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...