Submission #511161

# Submission time Handle Problem Language Result Execution time Memory
511161 2022-01-15T09:53:51 Z danikoynov Sjeckanje (COCI21_sjeckanje) C++14
0 / 110
2 ms 204 KB
/**
 ____ ____ ____ ____ ____ ____
||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];

void solve_dp()
{
    dp[2][1] = abs(a[2] - a[1]);
    for (int i = 3; i <= n; i ++)
    {
        if ((a[i] >= a[i - 1] && a[i - 1] >= a[i - 2]) ||
            (a[i] <= a[i - 1] && a[i - 1] <= a[i - 2]))
        {
            dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + abs(a[i] - a[i - 1]);
            dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
        }
        else
        {
            dp[i][1] = dp[i - 1][0] + abs(a[i] - a[i - 1]);
            dp[i][0] = max(dp[i - 1][1], dp[i - 1][0]);
        }
    }
}
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 << dp[n][1] << endl;
    }

}

int main()
{
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 2 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 2 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 2 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -