#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> a(n + 1);
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;
}
vector<int> dp(n + 1, 0);
int best1 = a[1];
int best2 = - a[1];
for(int i = 1; i <= n; i++) {
dp[i] = max({dp[i - 1], best1 - a[i], best2 + a[i]});
best1 = max(best1, dp[i - 1] + a[i]);
best2 = max(best2, dp[i - 1] - a[i]);
}
cout << dp[n] << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |