// Only GOD
// believe in yourself
// Nemidam Del Be In Darde Donya!
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define bit(x, y) ((x >> y)&1)
#define sz(x) (int)x.size()
#define kill(x) return cout << x << '\n', void()
#define KILL(x) return cout << x << '\n', 0
#define int ll
const int N = 2e5+100;
const int INF = 1e18;
int a[N];
int n;
int dp[N];
int32_t main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int q;
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;
for(int i =0; i<=n; i++)
dp[i] = 0;
dp[1] = 0;
for(int i = 2; i <= n; i++){
int mx = -INF, mn = INF;
for(int j = i; j >= 1; j--){
mx = max(mx, a[j]);
mn = min(mn, a[j]);
dp[i] = max(dp[j-1]+mx-mn, dp[i]);
}
}
cout << dp[n] << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
212 KB |
Output is correct |
2 |
Correct |
8 ms |
336 KB |
Output is correct |
3 |
Correct |
7 ms |
212 KB |
Output is correct |
4 |
Correct |
7 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
212 KB |
Output is correct |
2 |
Correct |
8 ms |
336 KB |
Output is correct |
3 |
Correct |
7 ms |
212 KB |
Output is correct |
4 |
Correct |
7 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
212 KB |
Output is correct |
7 |
Execution timed out |
2073 ms |
360 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
212 KB |
Output is correct |
2 |
Correct |
8 ms |
336 KB |
Output is correct |
3 |
Correct |
7 ms |
212 KB |
Output is correct |
4 |
Correct |
7 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
212 KB |
Output is correct |
7 |
Execution timed out |
2073 ms |
360 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |