#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mxN = 1e6 + 5, mod = 1e9 + 7;
const ll inf = 1e18;
ll n, q, a[mxN];
ll d[mxN];
int main() {
ios :: sync_with_stdio(false), cin.tie(nullptr);
cin >> n >> q;
for (int i = 1; i <= n; ++i)
cin >> a[i];
while (q--) {
int l, r, x;
cin >> l >> r >> x;
for (int i = l; i <= r; ++i)
a[i] += x;
for (int i = 1; i <= n; ++i)
d[i] = -inf;
for (int i = 1; i <= n; ++i) {
ll mn = inf, mx = -inf;
for (int j = i; j > 0; j--) {
mn = min(mn, a[j]);
mx = max(mx, a[j]);
d[i] = max(d[i], d[j - 1] + mx - mn);
}
}
cout << d[n] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
364 KB |
Output is correct |
2 |
Correct |
9 ms |
364 KB |
Output is correct |
3 |
Correct |
9 ms |
364 KB |
Output is correct |
4 |
Correct |
9 ms |
364 KB |
Output is correct |
5 |
Correct |
11 ms |
364 KB |
Output is correct |
6 |
Correct |
9 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
364 KB |
Output is correct |
2 |
Correct |
9 ms |
364 KB |
Output is correct |
3 |
Correct |
9 ms |
364 KB |
Output is correct |
4 |
Correct |
9 ms |
364 KB |
Output is correct |
5 |
Correct |
11 ms |
364 KB |
Output is correct |
6 |
Correct |
9 ms |
364 KB |
Output is correct |
7 |
Execution timed out |
2078 ms |
548 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
364 KB |
Output is correct |
2 |
Correct |
9 ms |
364 KB |
Output is correct |
3 |
Correct |
9 ms |
364 KB |
Output is correct |
4 |
Correct |
9 ms |
364 KB |
Output is correct |
5 |
Correct |
11 ms |
364 KB |
Output is correct |
6 |
Correct |
9 ms |
364 KB |
Output is correct |
7 |
Execution timed out |
2078 ms |
548 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |