itsanmolgera's blog

By itsanmolgera, history, 4 weeks ago, In English

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; } }

~~~~~

~~~~~

 
 
 
 
  • Vote: I like it
  • -11
  • Vote: I do not like it

»
4 weeks ago, # |
  Vote: I like it +10 Vote: I do not like it

practice