#include <bits/stdc++.h>
#define ar array
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
ll dp[maxn][2];
signed main() {
ios_base::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
int n, q; cin >> n >> q;
vector<ll> a(n+1);
for(int i=1; i<=n; i++) cin >> a[i];
while(q--) {
ll l, r, x; cin >> l >> r >> x;
for(int i=l; i<=r; i++) a[i] += x;
for(int i=0; i<=n; i++) dp[i][0] = dp[i][1] = -1e18;
dp[1][0] = dp[1][1] = 0;
for(int i=2; i<=n; i++) {
dp[i][0] = max(dp[i-1][0], dp[i-1][1]);
dp[i][1] = max(dp[i-1][0], dp[i-1][1]);
if(a[i-1] <= a[i]) dp[i][0] = max(dp[i][0], dp[i-1][0] + a[i] - a[i-1]);
if(a[i-1] >= a[i]) dp[i][1] = max(dp[i][1], dp[i-1][1] + a[i-1] - a[i]);
}
cout << max(dp[n][0], 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... |