Submission #513860

# Submission time Handle Problem Language Result Execution time Memory
513860 2022-01-17T19:04:38 Z blue Sjeckanje (COCI21_sjeckanje) C++17
15 / 110
2000 ms 420 KB
#include <iostream>
using namespace std;

using ll = long long;

ll* a;

bool cmp(int i, int j)
{
    if(a[i] != a[j]) return a[i] < a[j];
    else return i < j;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, q;
    cin >> n >> q;

    a = new ll[1+n+1];
    for(int i = 1; i <= n; i++) cin >> a[i];
    a[0] = a[n+1] = 0;

    for(int j = 1; j <= q; j++)
    {
        ll l, r, x;
        cin >> l >> r >> x;

        for(int i = l; i <= r; i++)
            a[i] += x;

        ll dp[1+n];
        dp[0] = 0;
        for(int i = 1; i <= n; i++)
        {
            dp[i] = 0;
            for(int j = 1; j <= i; j++)
                dp[i] = max(dp[i], dp[j-1] + abs(a[i] - a[j]));
        }

        cout << dp[n] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 204 KB Output is correct
2 Correct 6 ms 312 KB Output is correct
3 Correct 5 ms 204 KB Output is correct
4 Correct 6 ms 320 KB Output is correct
5 Correct 8 ms 320 KB Output is correct
6 Correct 6 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 204 KB Output is correct
2 Correct 6 ms 312 KB Output is correct
3 Correct 5 ms 204 KB Output is correct
4 Correct 6 ms 320 KB Output is correct
5 Correct 8 ms 320 KB Output is correct
6 Correct 6 ms 204 KB Output is correct
7 Execution timed out 2082 ms 420 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 204 KB Output is correct
2 Correct 6 ms 312 KB Output is correct
3 Correct 5 ms 204 KB Output is correct
4 Correct 6 ms 320 KB Output is correct
5 Correct 8 ms 320 KB Output is correct
6 Correct 6 ms 204 KB Output is correct
7 Execution timed out 2082 ms 420 KB Time limit exceeded
8 Halted 0 ms 0 KB -