#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[200005], dp[200005];
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1904 KB |
Output is correct |
2 |
Correct |
20 ms |
1868 KB |
Output is correct |
3 |
Correct |
21 ms |
1896 KB |
Output is correct |
4 |
Correct |
22 ms |
1896 KB |
Output is correct |
5 |
Correct |
21 ms |
1868 KB |
Output is correct |
6 |
Correct |
21 ms |
1900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1904 KB |
Output is correct |
2 |
Correct |
20 ms |
1868 KB |
Output is correct |
3 |
Correct |
21 ms |
1896 KB |
Output is correct |
4 |
Correct |
22 ms |
1896 KB |
Output is correct |
5 |
Correct |
21 ms |
1868 KB |
Output is correct |
6 |
Correct |
21 ms |
1900 KB |
Output is correct |
7 |
Execution timed out |
2086 ms |
2124 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1904 KB |
Output is correct |
2 |
Correct |
20 ms |
1868 KB |
Output is correct |
3 |
Correct |
21 ms |
1896 KB |
Output is correct |
4 |
Correct |
22 ms |
1896 KB |
Output is correct |
5 |
Correct |
21 ms |
1868 KB |
Output is correct |
6 |
Correct |
21 ms |
1900 KB |
Output is correct |
7 |
Execution timed out |
2086 ms |
2124 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |