This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |