#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 = 1e18;
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 |
1 |
Correct |
10 ms |
364 KB |
Output is correct |
2 |
Correct |
9 ms |
364 KB |
Output is correct |
3 |
Correct |
9 ms |
364 KB |
Output is correct |
4 |
Correct |
9 ms |
364 KB |
Output is correct |
5 |
Correct |
9 ms |
364 KB |
Output is correct |
6 |
Correct |
9 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
364 KB |
Output is correct |
2 |
Correct |
9 ms |
364 KB |
Output is correct |
3 |
Correct |
9 ms |
364 KB |
Output is correct |
4 |
Correct |
9 ms |
364 KB |
Output is correct |
5 |
Correct |
9 ms |
364 KB |
Output is correct |
6 |
Correct |
9 ms |
364 KB |
Output is correct |
7 |
Execution timed out |
2094 ms |
492 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
364 KB |
Output is correct |
2 |
Correct |
9 ms |
364 KB |
Output is correct |
3 |
Correct |
9 ms |
364 KB |
Output is correct |
4 |
Correct |
9 ms |
364 KB |
Output is correct |
5 |
Correct |
9 ms |
364 KB |
Output is correct |
6 |
Correct |
9 ms |
364 KB |
Output is correct |
7 |
Execution timed out |
2094 ms |
492 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |