#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 |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
356 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
356 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
34 ms |
432 KB |
Output is correct |
8 |
Correct |
34 ms |
424 KB |
Output is correct |
9 |
Correct |
34 ms |
340 KB |
Output is correct |
10 |
Correct |
34 ms |
424 KB |
Output is correct |
11 |
Correct |
35 ms |
428 KB |
Output is correct |
12 |
Correct |
29 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
356 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
34 ms |
432 KB |
Output is correct |
8 |
Correct |
34 ms |
424 KB |
Output is correct |
9 |
Correct |
34 ms |
340 KB |
Output is correct |
10 |
Correct |
34 ms |
424 KB |
Output is correct |
11 |
Correct |
35 ms |
428 KB |
Output is correct |
12 |
Correct |
29 ms |
340 KB |
Output is correct |
13 |
Execution timed out |
2086 ms |
5012 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |