#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define mp make_pair
#define ll long long
const ll INF=1e18,N=2e5+5;
void solve(){
int n,q;cin>>n>>q;
vector<int> a(n+1);
for(int i=1;i<=n;i++){
cin>>a[i];
}
vector<int> dp(n),prv(n);
while(q--){
int l,r,x;cin>>l>>r>>x;
for(int i=l;i<=r;i++) a[i]+=x;
dp[1]=0;
dp[2]=abs(a[2]-a[1]);
prv[2]=1;
for(int i=3;i<=n;i++){
dp[i]=dp[i-1];
if((a[i]>=a[i-1]) == (a[i-1]>=a[i-2])) prv[i]=prv[i-1];
else prv[i]=i-1;
dp[i]=max(dp[i],abs(a[i]-a[prv[i]])+dp[prv[i]-1]);
dp[i]=max(dp[i],abs(a[i]-a[prv[i]+1])+dp[prv[i]]);
}
cout<<dp[n]<<endl;
}
}
int main(){
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |