#include <bits/stdc++.h>
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
signed main() {
ios_base::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
int n, q;
cin >> n >> q;
vector<ll> v(n+1), dp(n+1);
for(int i=1; i<=n; i++) cin >> v[i];
while(q--) {
int l, r, x;
cin >> l >> r >> x;
for(int i=l; i<=r; i++) v[i] += x;
for(int i=1; i<=n; i++) {
dp[i] = 0;
ll mn=1e18, mx=-1e18;
for(int j=i; j>=1; j--) {
mn = min(mn, v[j]);
mx = max(mx, v[j]);
dp[i] = max(dp[i], dp[j-1] + mx - mn);
}
}
cout << dp[n] << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
348 KB |
Output is correct |
2 |
Correct |
5 ms |
348 KB |
Output is correct |
3 |
Correct |
5 ms |
468 KB |
Output is correct |
4 |
Correct |
5 ms |
456 KB |
Output is correct |
5 |
Correct |
5 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
348 KB |
Output is correct |
2 |
Correct |
5 ms |
348 KB |
Output is correct |
3 |
Correct |
5 ms |
468 KB |
Output is correct |
4 |
Correct |
5 ms |
456 KB |
Output is correct |
5 |
Correct |
5 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
348 KB |
Output is correct |
7 |
Execution timed out |
2015 ms |
472 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
348 KB |
Output is correct |
2 |
Correct |
5 ms |
348 KB |
Output is correct |
3 |
Correct |
5 ms |
468 KB |
Output is correct |
4 |
Correct |
5 ms |
456 KB |
Output is correct |
5 |
Correct |
5 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
348 KB |
Output is correct |
7 |
Execution timed out |
2015 ms |
472 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |