#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin() , (x).end()
const ll MOD = 998244353;
const long double EPS = 0.000000001;
ll n, q, arr[220], dp[220];
ll solve(ll i) {
if(dp[i]!=-1) return dp[i];
ll mn=arr[i], mx=arr[i], best=0;
for(ll l=i;l<=n;l++) {
mx=max(mx, arr[l]); mn=min(mn, arr[l]);
best=max(best, mx-mn+solve(l+1));
}
return dp[i]=best;
}
int32_t main()
{
ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
cin>>n>>q;
for(ll l=1;l<=n;l++) cin>>arr[l];
while(q--) {
ll a, b, val; cin>>a>>b>>val;
for(int l=a;l<=b;l++) arr[l]+=val;
memset(dp, -1, sizeof dp);
cout<<solve(1)<<'\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
332 KB |
Output is correct |
2 |
Correct |
9 ms |
332 KB |
Output is correct |
3 |
Correct |
9 ms |
328 KB |
Output is correct |
4 |
Correct |
9 ms |
324 KB |
Output is correct |
5 |
Correct |
9 ms |
332 KB |
Output is correct |
6 |
Correct |
13 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
332 KB |
Output is correct |
2 |
Correct |
9 ms |
332 KB |
Output is correct |
3 |
Correct |
9 ms |
328 KB |
Output is correct |
4 |
Correct |
9 ms |
324 KB |
Output is correct |
5 |
Correct |
9 ms |
332 KB |
Output is correct |
6 |
Correct |
13 ms |
204 KB |
Output is correct |
7 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
332 KB |
Output is correct |
2 |
Correct |
9 ms |
332 KB |
Output is correct |
3 |
Correct |
9 ms |
328 KB |
Output is correct |
4 |
Correct |
9 ms |
324 KB |
Output is correct |
5 |
Correct |
9 ms |
332 KB |
Output is correct |
6 |
Correct |
13 ms |
204 KB |
Output is correct |
7 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
8 |
Halted |
0 ms |
0 KB |
- |