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 blue 0
#define red 1
#define purple 2
#define pb push_back
#define F first
#define S second
#define sz(x) (int)x.size()
#define el "\n"
using namespace std;
typedef long long ll;
const int N = 1e5 + 500;
ll a[N], f[N][2], b[N];
int n, q;
int main() {
cin >> n >> q;
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;
b[l - 1] += x;
b[r] -= x;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 2; j++) {
f[i][j] = -1e18;
}
}
f[1][0] = 0;
f[1][1] = abs(b[1]);
for (int i = 2; i < n; i++) {
if ((b[i - 1] < 0 && b[i] < 0) || (b[i - 1] > 0 && b[i] > 0)) {
f[i][1] = max(f[i][1], f[i - 1][1] + abs(b[i]));
}
f[i][1] = max(f[i - 1][0] + abs(b[i]), f[i][1]);
f[i][0] = max(f[i - 1][0], f[i - 1][1]);
}
cout << max(f[n - 1][0], f[n - 1][1]) << el;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |