This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |