#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define debug if(0)
const int mod = 1e9 + 7;
const ll infL = 1e18 + 7;
const int inf = 1e9 + 7;
void add(int &a, int b) { a = (a+b)%mod; }
int add(int a, int b, int c) { int res = (((a+b)%mod) + c)%mod; return res; }
ll solve(vector<ll> &a, int n) {
vector<ll> dp(n, 0);
for(int i=1; i<n; i++) {
array<ll, 2> m = {a[i], a[i]};
dp[i] = dp[i-1];
for(int j=i-1; j>=0; j--) {
m[0] = max(m[0], a[j]);
m[1] = min(m[1], a[j]);
dp[i] = max(dp[i], (j == 0 ? 0 : dp[j-1]) + (m[0]-m[1]));
}
}
return dp[n-1];
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, q; cin>>n>>q;
vector<ll> a(n);
for(ll &x : a) cin>>x;
while(q--) {
int l, r; ll x; cin>>l>>r>>x;
for(int i=l-1; i<r; i++) a[i] += x;
cout<<solve(a, n)<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
204 KB |
Output is correct |
2 |
Correct |
7 ms |
204 KB |
Output is correct |
3 |
Correct |
7 ms |
316 KB |
Output is correct |
4 |
Correct |
9 ms |
324 KB |
Output is correct |
5 |
Correct |
6 ms |
312 KB |
Output is correct |
6 |
Correct |
9 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
204 KB |
Output is correct |
2 |
Correct |
7 ms |
204 KB |
Output is correct |
3 |
Correct |
7 ms |
316 KB |
Output is correct |
4 |
Correct |
9 ms |
324 KB |
Output is correct |
5 |
Correct |
6 ms |
312 KB |
Output is correct |
6 |
Correct |
9 ms |
204 KB |
Output is correct |
7 |
Execution timed out |
2074 ms |
432 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
204 KB |
Output is correct |
2 |
Correct |
7 ms |
204 KB |
Output is correct |
3 |
Correct |
7 ms |
316 KB |
Output is correct |
4 |
Correct |
9 ms |
324 KB |
Output is correct |
5 |
Correct |
6 ms |
312 KB |
Output is correct |
6 |
Correct |
9 ms |
204 KB |
Output is correct |
7 |
Execution timed out |
2074 ms |
432 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |