#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n,q;
cin>>n>>q;
vector <int> a(n);
for(int i=0;i<n;i++){
cin>>a[i];
}
while(q--){
int l,r,v;
cin>>l>>r>>v;
l--;r--;
for(int i=l;i<=r;i++)a[i]+=v;
vector <int> ans(n);
int x=-a[0],y=a[0];
for(int i=1;i<n;i++){
x=max(x,ans[i-1]-a[i]);
y=max(y,ans[i-1]+a[i]);
//cout<<x<<" "<<y<<"\n";
ans[i]=max(x+a[i],y-a[i]);
//cout<<ans[i]<<"\n";
}
cout<<ans[n-1]<<"\n";
}
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
360 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
360 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
50 ms |
584 KB |
Output is correct |
8 |
Correct |
50 ms |
568 KB |
Output is correct |
9 |
Correct |
50 ms |
344 KB |
Output is correct |
10 |
Correct |
50 ms |
584 KB |
Output is correct |
11 |
Correct |
50 ms |
348 KB |
Output is correct |
12 |
Correct |
50 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
360 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
50 ms |
584 KB |
Output is correct |
8 |
Correct |
50 ms |
568 KB |
Output is correct |
9 |
Correct |
50 ms |
344 KB |
Output is correct |
10 |
Correct |
50 ms |
584 KB |
Output is correct |
11 |
Correct |
50 ms |
348 KB |
Output is correct |
12 |
Correct |
50 ms |
344 KB |
Output is correct |
13 |
Execution timed out |
2016 ms |
5172 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |