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;
using ll = long long int;
const int maxn = 2e5 + 5;
const int oo = 1e9 + 7;
const ll inf = 1e18;
int n, q;
ll a[maxn], st[4*maxn], dp[maxn];
void sub1() { // O(n^2 * q)
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;
dp[0] = 0;
for (int i = 1; i <= n; i++) {
dp[i] = 0;
ll mx = a[i];
ll mn = a[i];
for (int j = i; j >= 1; j--) {
mx = max(mx, a[j]);
mn = min(mn, a[j]);
dp[i] = max(dp[i], mx - mn + dp[j - 1]);
}
}
cout << dp[n] << '\n';
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
sub1();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |