//TrungNotChung
#include <bits/stdc++.h>
#define pii pair<int , int>
#define fi first
#define se second
#define BIT(x,i) (1&((x)>>(i)))
#define MASK(x) (1LL<<(x))
#define CNT(x) __builtin_popcountll(x)
#define task "tnc"
using namespace std;
const int N = 3030;
const long long INF = (long long)1e18;
void maximize(long long &x, const long long &y)
{
x = max(x, y);
}
int n, q;
long long a[N], dp[N][2][2];
void solve()
{
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;
memset(dp, -0x3f, sizeof(dp));
dp[0][0][0] = 0;
for(int i=0; i<n; ++i)
{
for(int j=0; j<=1; ++j)
{
for(int k=0; k<=1; ++k)
{
maximize(dp[i+1][j][k], dp[i][j][k]);
if(k == 0 || j == 0)
maximize(dp[i+1][1][1^k], dp[i][j][k] + a[i+1]);
if(k == 0 || j == 1)
maximize(dp[i+1][0][1^k], dp[i][j][k] - a[i+1]);
}
}
}
long long res = -INF;
for(int i=0; i<=1; ++i)
maximize(res, dp[n][i][0]);
cout << res << '\n';
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
//cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
87 ms |
528 KB |
Output is correct |
8 |
Correct |
89 ms |
524 KB |
Output is correct |
9 |
Correct |
86 ms |
524 KB |
Output is correct |
10 |
Correct |
91 ms |
528 KB |
Output is correct |
11 |
Correct |
86 ms |
524 KB |
Output is correct |
12 |
Correct |
91 ms |
540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
87 ms |
528 KB |
Output is correct |
8 |
Correct |
89 ms |
524 KB |
Output is correct |
9 |
Correct |
86 ms |
524 KB |
Output is correct |
10 |
Correct |
91 ms |
528 KB |
Output is correct |
11 |
Correct |
86 ms |
524 KB |
Output is correct |
12 |
Correct |
91 ms |
540 KB |
Output is correct |
13 |
Runtime error |
2 ms |
724 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |