Submission #795033

#TimeUsernameProblemLanguageResultExecution timeMemory
795033ttamxSjeckanje (COCI21_sjeckanje)C++14
55 / 110
2086 ms5012 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=2e5+5; const int K=1<<19; int n,q; ll a[N],d[N],dp[N]; int main(){ cin.tie(nullptr)->sync_with_stdio(false); cin >> n >> q; for(int i=1;i<=n;i++)cin >> a[i]; for(int i=1;i<=n;i++)d[i]=a[i]-a[i-1]; while(q--){ int l,r,x; cin >> l >> r >> x; d[l]+=x; d[r+1]-=x; for(int i=2;i<=n;i++){ dp[i]=max(dp[i-2]+abs(d[i]),dp[i-1]); if((d[i]^d[i-1])>=0)dp[i]=max(dp[i],dp[i-1]+abs(d[i])); } cout << dp[n] << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...