#include "bits/stdc++.h"
#include <cstring>
#include <fstream>
using namespace std;
#define ll long long
#define forR(i, x) for(int i = 0; i < x; ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define open(s) freopen(((string) s + ".in").c_str(), "r", stdin); freopen(((string) s + ".out").c_str(), "w", stdout)
#define all(i) i.begin(), i.end()
#define boost() cin.sync_with_stdio(0); cin.tie()
#define int ll
const int MN = 210;
int arr[MN], dp[MN];
signed main() {
int n, q; cin >> n >> q;
REP(i, 1, n + 1) cin >> arr[i];
forR(g, q){
int l, r, x; cin >> l >> r >> x;
REP(i, l, r + 1) arr[i] += x;
REP(i, 1, n + 1){
dp[i] = 0;
int ma=arr[i], mi=arr[i];
for(int j = i; j >= 1; --j){
ma=max(ma, arr[j]);
mi = min(mi, arr[j]);
dp[i] = max(dp[i], ma - mi + dp[j - 1]);
}
}
cout << dp[n] << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
212 KB |
Output is correct |
2 |
Correct |
8 ms |
212 KB |
Output is correct |
3 |
Correct |
8 ms |
308 KB |
Output is correct |
4 |
Correct |
8 ms |
212 KB |
Output is correct |
5 |
Correct |
10 ms |
212 KB |
Output is correct |
6 |
Correct |
8 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 |
212 KB |
Output is correct |
3 |
Correct |
8 ms |
308 KB |
Output is correct |
4 |
Correct |
8 ms |
212 KB |
Output is correct |
5 |
Correct |
10 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
212 KB |
Output is correct |
7 |
Runtime error |
1 ms |
444 KB |
Execution killed with signal 11 |
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 |
212 KB |
Output is correct |
3 |
Correct |
8 ms |
308 KB |
Output is correct |
4 |
Correct |
8 ms |
212 KB |
Output is correct |
5 |
Correct |
10 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
212 KB |
Output is correct |
7 |
Runtime error |
1 ms |
444 KB |
Execution killed with signal 11 |
8 |
Halted |
0 ms |
0 KB |
- |