#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3007;
int n, q, a[N];
ll b[N], dp[N][2];
int getSign(ll x){
if (x < 0)
return -1;
else if (x == 0)
return 0;
else
return 1;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> q;
if (max(n, q) > 3000)
return 0;
for(int i = 1; i <= n; i++)
cin >> a[i];
for(int i = 1; i < n; i++)
b[i] = a[i + 1] - a[i];
while (q--){
int l, r, x;
cin >> l >> r >> x;
if (l > 1)
b[l - 1] += x;
if (r < n)
b[r] -= x;
// cerr << "b: ";
// for(int i = 1; i < n; i++)
// cerr << b[i] << ' ';
// cerr << endl;
dp[0][0] = dp[0][1] = 0;
for(int i = 1; i < n; i++){
dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
dp[i][1] = dp[i - 1][0] + abs(b[i]);
if (getSign(b[i - 1]) * getSign(b[i]) != -1)
dp[i][1] = max(dp[i][1], dp[i - 1][1] + abs(b[i]));
}
cout << max(dp[n - 1][0], dp[n - 1][1]) << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
48 ms |
620 KB |
Output is correct |
8 |
Correct |
42 ms |
620 KB |
Output is correct |
9 |
Correct |
42 ms |
748 KB |
Output is correct |
10 |
Correct |
45 ms |
620 KB |
Output is correct |
11 |
Correct |
43 ms |
620 KB |
Output is correct |
12 |
Correct |
37 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
48 ms |
620 KB |
Output is correct |
8 |
Correct |
42 ms |
620 KB |
Output is correct |
9 |
Correct |
42 ms |
748 KB |
Output is correct |
10 |
Correct |
45 ms |
620 KB |
Output is correct |
11 |
Correct |
43 ms |
620 KB |
Output is correct |
12 |
Correct |
37 ms |
620 KB |
Output is correct |
13 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |