#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mxN = 1e6+10;
const ll INF = 1e18;
ll dp[mxN];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<ll> v(n+1);
for(int i = 1; i <= n; i++) {
cin >> v[i];
}
for(int i = 1; i <= n; i++) {
ll mx = v[i], mn = v[i];
for(int j = i-1; j >= 1; j--) {
mx = max(mx, v[j]);
mn = min(mn, v[j]);
dp[i] = max(dp[i], dp[j-1]+mx-mn);
}
}
while(q--) {
int l, r; ll x;
cin >> l >> r >> x;
for(int i = l; i <= r; i++) {
v[i] += x;
}
for(int i = 1; i <= n; i++) {
dp[i] = 0;
ll mx = v[i], mn = v[i];
for(int j = i-1; j >= 1; j--) {
mx = max(mx, v[j]);
mn = min(mn, v[j]);
dp[i] = max(dp[i], dp[j-1]+mx-mn);
}
}
cout << dp[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... |