#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define crep(i,x,n) for(int i=x;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _31av4qi ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
using pii=pair<int,int>;
using vi=vector<int>;
int sgn(int x){
return x>=0?1:-1;
}
int main(){
_31av4qi;
int n,q;
cin>>n>>q;
vec(ll) a(n);
rep(i,n){
cin>>a[i];
}
vi _d(n);
rep(cs,q){
int l,r,x;
cin>>l>>r>>x;
l--,r--;
crep(i,l,r+1) a[i]+=x;
vec(ll) dp(n+1);
dp[0]=0;
rep(i,n){
ll _v0=a[i],_v1=a[i];
drep(j,i){
_v0=max(_v0,a[j]);
_v1=min(_v1,a[j]);
dp[i+1]=max(dp[i+1],dp[j]+_v0-_v1);
}
}
cout<<dp[n]<<"\n";
}
//
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
208 KB |
Output is correct |
2 |
Correct |
7 ms |
204 KB |
Output is correct |
3 |
Correct |
7 ms |
208 KB |
Output is correct |
4 |
Correct |
8 ms |
208 KB |
Output is correct |
5 |
Correct |
7 ms |
204 KB |
Output is correct |
6 |
Correct |
7 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
208 KB |
Output is correct |
2 |
Correct |
7 ms |
204 KB |
Output is correct |
3 |
Correct |
7 ms |
208 KB |
Output is correct |
4 |
Correct |
8 ms |
208 KB |
Output is correct |
5 |
Correct |
7 ms |
204 KB |
Output is correct |
6 |
Correct |
7 ms |
204 KB |
Output is correct |
7 |
Execution timed out |
2079 ms |
456 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
208 KB |
Output is correct |
2 |
Correct |
7 ms |
204 KB |
Output is correct |
3 |
Correct |
7 ms |
208 KB |
Output is correct |
4 |
Correct |
8 ms |
208 KB |
Output is correct |
5 |
Correct |
7 ms |
204 KB |
Output is correct |
6 |
Correct |
7 ms |
204 KB |
Output is correct |
7 |
Execution timed out |
2079 ms |
456 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |