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;
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |