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>
using namespace std;
long long n, a[1000005], d[1000005], q, dp[1000005];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> q;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i < n; i++) d[i] = a[i] - a[i + 1];
dp[0] = 0;
while (q--) {
long long l, r, x;
cin >> l >> r >> x;
d[l - 1] -= x;
d[r] += x;
d[0] = d[1];
for (int i = 1; i < n; i++) {
if (d[i] * d[i - 1] > 0) dp[i] = max(dp[i - 1], dp[i - 1] + abs(d[i]));
else dp[i] = max(dp[i - 1], dp[i - 2] + abs(d[i]));
}
cout << dp[n - 1] << "\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... |