제출 #373110

#제출 시각아이디문제언어결과실행 시간메모리
373110sam571128Sjeckanje (COCI21_sjeckanje)C++14
55 / 110
2065 ms7404 KiB
#include <bits/stdc++.h> #define int long long #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; const int N = 2e5+5; int dp[N][2]; //The maximum sum when we get to the ith element and is ascend/descending signed main(){ fastio int n,q; cin >> n >> q; int arr[n+1]; for(int i = 1;i <= n;i++){ cin >> arr[i]; } while(q--){ int l,r,x; cin >> l >> r >> x; for(int i = l;i <= r;i++) arr[i] += x; dp[1][0] = dp[1][1] = 0; for(int i = 2;i <= n;i++){ if(arr[i]>=arr[i-1]){ dp[i][0] = max(dp[i-1][0]+arr[i]-arr[i-1],dp[i-1][1]); dp[i][1] = max(dp[i-1][0],dp[i-1][1]); }else if(arr[i] < arr[i-1]){ dp[i][0] = max(dp[i-1][0],dp[i-1][1]); dp[i][1] = max(dp[i-1][0],dp[i-1][1]+arr[i-1]-arr[i]); } } cout << max(dp[n][0],dp[n][1]) << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...