/**
____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|
**/
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const ll inf = 1e18;
const int maxn = 3010;
int n, q;
ll a[maxn], dp[maxn][2], d[maxn];
bool diff(ll x, ll y)
{
if (x > 0 && y < 0)
return true;
if (x < 0 && y > 0)
return true;
return false;
}
void solve_dp()
{
for (int i = 1; i < n; i ++)
d[i] = a[i + 1] - a[i];
dp[1][1] = abs(d[1]);
for (int i = 2; i < n; i ++)
{
dp[i][0] = max(dp[i - 1][1], dp[i - 1][0]);
if (!diff(d[i], d[i - 1]))
{
dp[i][1] = max(dp[i - 1][1], dp[i - 1][0]) + abs(d[i]);
}
else
{
dp[i][1] = dp[i - 1][0] + abs(d[i]);
}
}
}
void solve()
{
cin >> n >> q;
for (int i = 1; i <= n; i ++)
cin >> a[i];
for (int i = 1; i <= q; i ++)
{
int l, r, x;
cin >> l >> r >> x;
for (int j = l; j <= r; j ++)
a[j] += x;
solve_dp();
cout << max(dp[n - 1][1], dp[n - 1][0]) << endl;
}
}
int main()
{
solve();
return 0;
}
/**
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
47 ms |
436 KB |
Output is correct |
8 |
Correct |
47 ms |
484 KB |
Output is correct |
9 |
Correct |
47 ms |
472 KB |
Output is correct |
10 |
Correct |
49 ms |
428 KB |
Output is correct |
11 |
Correct |
49 ms |
484 KB |
Output is correct |
12 |
Correct |
47 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
47 ms |
436 KB |
Output is correct |
8 |
Correct |
47 ms |
484 KB |
Output is correct |
9 |
Correct |
47 ms |
472 KB |
Output is correct |
10 |
Correct |
49 ms |
428 KB |
Output is correct |
11 |
Correct |
49 ms |
484 KB |
Output is correct |
12 |
Correct |
47 ms |
492 KB |
Output is correct |
13 |
Incorrect |
2 ms |
424 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |