Simpest Solution of Codeforces Round 672 Div 2 Problem C

Правка en1, от DumbCarlsen69, 2020-09-25 12:55:27

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

}

Теги div2 672, #problem c

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en4 Английский DumbCarlsen69 2020-09-25 12:57:53 17 Tiny change: 'n\n~~~~~\nYour code here...\n~~~~~\n\' -> 'n\n~~~~~\n\n~~~~~\n\'
en3 Английский DumbCarlsen69 2020-09-25 12:57:23 11
en2 Английский DumbCarlsen69 2020-09-25 12:56:28 57
en1 Английский DumbCarlsen69 2020-09-25 12:55:27 599 Initial revision (published)