Submission #1011687

#TimeUsernameProblemLanguageResultExecution timeMemory
1011687pccSjeckanje (COCI21_sjeckanje)C++17
55 / 110
23 ms636 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll,ll> #define fs first #define sc second #define pii pair<int,int> const int mxn = 3030; const ll inf = 1e18; ll arr[mxn]; ll dp[mxn]; int N,Q; ll getans(){ pll mx = pll(-inf,-inf); dp[1] = 0; mx.fs = -arr[1]; mx.sc = arr[1]; for(int i = 1;i<=N;i++){ dp[i] = max(arr[i]+mx.fs,-arr[i]+mx.sc); mx.fs = max(mx.fs,dp[i]-arr[i+1]); mx.sc = max(mx.sc,dp[i]+arr[i+1]); } return dp[N]; } int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>N>>Q; for(int i = 1;i<=N;i++)cin>>arr[i]; while(Q--){ int l,r,v; cin>>l>>r>>v; for(int i = l;i<=r;i++)arr[i] += v; cout<<getans()<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...