Submission #511172

#TimeUsernameProblemLanguageResultExecution timeMemory
511172danikoynovSjeckanje (COCI21_sjeckanje)C++14
55 / 110
49 ms492 KiB
/**
 ____ ____ ____ ____ ____ ____
||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;
}
/**


*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...