#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
#define fi first
#define se second
#define int long long
const int MAXN = 200;
int memo[MAXN][MAXN], a[MAXN];
int n, q;
int dp(int p, int c){
if(memo[p][c] != -1) return memo[p][c];
if(p == 0){
return 0;
}
int minx = LLONG_MAX, maxx = LLONG_MIN;
if(c == 0){
for(int i=0; i<=p; i++){
minx = min(minx, a[i]);
maxx = max(maxx, a[i]);
}
return (memo[p][c] = maxx - minx);
}
memo[p][c] = 0;
for(int i=p; i>=c; i--){
minx = min(minx, a[i]);
maxx = max(maxx, a[i]);
memo[p][c] = max(memo[p][c], dp(i-1, c-1) + maxx - minx);
}
return memo[p][c];
}
signed main(){
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> n >> q;
for(int i=0; i<n; i++){
cin >> a[i];
}
while(q--){
memset(memo, -1, sizeof(memo));
int l, r, x;
cin >> l >> r >> x;
l--; r--;
for(int i=l; i<=r; i++){
a[i] += x;
}
int ans=0;
for(int i=0; i<n; i++){
ans = max(ans, dp(n-1, i));
}
cout << ans << '\n';
/*for(int i=0; i<n; i++){
cerr << a[i] << ' ';
}
cerr << '\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... |