#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 |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
21 ms |
348 KB |
Output is correct |
8 |
Correct |
21 ms |
344 KB |
Output is correct |
9 |
Correct |
23 ms |
636 KB |
Output is correct |
10 |
Correct |
23 ms |
348 KB |
Output is correct |
11 |
Correct |
21 ms |
348 KB |
Output is correct |
12 |
Correct |
22 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
21 ms |
348 KB |
Output is correct |
8 |
Correct |
21 ms |
344 KB |
Output is correct |
9 |
Correct |
23 ms |
636 KB |
Output is correct |
10 |
Correct |
23 ms |
348 KB |
Output is correct |
11 |
Correct |
21 ms |
348 KB |
Output is correct |
12 |
Correct |
22 ms |
512 KB |
Output is correct |
13 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |