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>
#if defined(LOCAL)
#include "debug.cpp"
#else
#define debug(x...) 0
#endif // LOCAL
using namespace std;
using ll = long long;
#define all(a) (a).begin(), (a).end()
void solve(){
int n, q; cin >> n >> q;
vector<ll> a(n);
for(int i=0; i<n; i++) cin >> a[i];
auto get = [&](vector<ll> a){
vector<ll> dp(n+1);
for(int i=0; i<n; i++){
ll mn=a[i], mx = a[i];
for(int j=i; j<n; j++){
mn = min(mn, a[j]);
mx = max(mx, a[j]);
dp[j+1]=max(dp[j+1], dp[i]+mx - mn);
}
}
return dp[n];
};
while(q--){
ll l, r, add;
cin>>l>>r>>add;
l--, r--;
for(int i=l; i<=r;i++) a[i]+=add;
ll ans = get(a);
cout<<ans<<endl;
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int t=1; //cin >> t;
while(t--) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |