Simpest Solution of Codeforces Round 672 Div 2 Problem C

Revision en2, by DumbCarlsen69, 2020-09-25 12:56:28

Anyone know how to come up with these kind of solutions, because intuitively its not easy and took me a while? Thanks!


#include<bits/stdc++.h> using namespace std; #define int long long int32_t main(){ int t; cin>>t; while(t--){ int n,q; cin>>n>>q; int a[n]; for(int i =0; i<n; i++){ cin>>a[i]; } int ans =a[0]; for(int i=1; i<n; i++){ int x = a[i]-a[i-1]; if(x>0){ ans+=x; } else continue; } cout<<ans<<endl; } }
Your code here...
Tags div2 672, #problem c

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English DumbCarlsen69 2020-09-25 12:57:53 17 Tiny change: 'n\n~~~~~\nYour code here...\n~~~~~\n\' -> 'n\n~~~~~\n\n~~~~~\n\'
en3 English DumbCarlsen69 2020-09-25 12:57:23 11
en2 English DumbCarlsen69 2020-09-25 12:56:28 57
en1 English DumbCarlsen69 2020-09-25 12:55:27 599 Initial revision (published)