/* In the name of God */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
#define PB push_back
#define MP make_pair
#define all(a) (a).begin(), (a).end()
#define endl '\n'
#define dbg(x) cerr << '[' << #x << ": " << x << "]\n"
#define dbg2(x, y) cerr << '[' << #x << ": " << x << ", " << #y << ": " << y << "]\n"
#define YES cout << "YES\n"
#define NO cout << "NO\n"
const ll INF = (ll)2e18 + 1386;
const ld EPS = 0.000000000000001;
const int MOD = 1e9 + 7;
inline int _add(int a, int b){ int res = a + b; return (res >= MOD ? res - MOD : res); }
inline int _neg(int a, int b){ int res = (abs(a - b) < MOD ? a - b : (a - b) % MOD); return (res < 0 ? res + MOD : res); }
inline int _mlt(ll a, ll b){ return (a * b % MOD); }
inline void fileIO(string i, string o){ freopen(i.c_str(), "r", stdin); freopen(o.c_str(), "w", stdout); }
const int MAXN = 3e3 + 23;
ll dp[MAXN][2], a[MAXN], dif[MAXN];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int n, 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 = 2; i <= n; i++){
dif[i] = a[i] - a[i - 1];
if (i == 2){
dp[i][0] = 0, dp[i][1] = abs(dif[i]);
continue;
}
dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
if ((dif[i] > 0 && dif[i - 1] < 0) || (dif[i] < 0 && dif[i - 1] > 0)) dp[i][1] = dp[i - 1][0] + abs(dif[i]);
else dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + abs(dif[i]);
}
cout << max(dp[n][0], dp[n][1]) << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
33 ms |
604 KB |
Output is correct |
8 |
Correct |
33 ms |
648 KB |
Output is correct |
9 |
Correct |
33 ms |
600 KB |
Output is correct |
10 |
Correct |
32 ms |
604 KB |
Output is correct |
11 |
Correct |
33 ms |
604 KB |
Output is correct |
12 |
Correct |
31 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
33 ms |
604 KB |
Output is correct |
8 |
Correct |
33 ms |
648 KB |
Output is correct |
9 |
Correct |
33 ms |
600 KB |
Output is correct |
10 |
Correct |
32 ms |
604 KB |
Output is correct |
11 |
Correct |
33 ms |
604 KB |
Output is correct |
12 |
Correct |
31 ms |
600 KB |
Output is correct |
13 |
Runtime error |
1 ms |
856 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |