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>
using namespace std;
#define eb emplace_back
#define pb push_back
#define ppb pop_back
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define cln(a,s) memset((a),0,sizeof((a)[0])*(s))
#define all(x) (x).begin() , (x).end()
#define fi first
#define se second
#define int long long
using pii = pair<int,int>;
using ll = long long;
const int maxn = 2e5 + 5;
const int inf = 1e9;
const int mod = 1e9+7;
int n,q,a[maxn],dp[maxn];
int32_t main () {
//freopen("in","r",stdin); freopen("out","w",stdout);
ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
cin >> n >> q;
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;
dp[1] = 0;
for(int i=2;i<=n;i++) {
dp[i] = 0;
int mn = inf , mx = -inf;
for(int j=i;j>=1;j--) {
mn = min(mn,a[j]);
mx = max(mx,a[j]);
dp[i] = max(dp[i],dp[j-1]+mx-mn);
}
}
cout << dp[n] << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |