Submission #827259

# Submission time Handle Problem Language Result Execution time Memory
827259 2023-08-16T10:19:05 Z borisAngelov Sjeckanje (COCI21_sjeckanje) C++17
0 / 110
1 ms 340 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 200005;

int n, q;
int a[maxn];

long long dp[maxn];
long long pref[maxn];
long long delta[maxn];

bool is_diff(long long x, long long y)
{
    if (x > 0 && y < 0)
    {
        return true;
    }

    if (x < 0 && y > 0)
    {
        return true;
    }

    return false;
}

void solve()
{
    for (int i = 1; i <= n - 1; ++i)
    {
        delta[i] = a[i + 1] - a[i];
    }

    dp[1] = abs(delta[1]);

    for (int i = 2; i <= n - 1; ++i)
    {
        pref[i] = max(dp[i - 1], pref[i - 1]);

        if (is_diff(delta[i], delta[i - 1]) == false)
        {
            dp[i] = pref[i - 1] + abs(delta[i]);
        }
        else
        {
            dp[i] = pref[i - 1] + abs(delta[i]);
        }
    }

    cout << dp[n - 1] << "\n";
}

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    fastIO();

    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();
    }

    return 0;
}

/*
4 3
1 2 3 4
1 2 1
1 1 2
2 3 1

4 1
1 2 3 4
1 2 1
*/
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -