Submission #745286

# Submission time Handle Problem Language Result Execution time Memory
745286 2023-05-19T18:47:28 Z IDorando Growing Vegetables is Fun 4 (JOI21_ho_t1) C++17
100 / 100
82 ms 6252 KB
#include <bits/stdc++.h>

using namespace std;

int n, a[200005];
long long pref[200005], suff[200005], sol;

int main()
{
    int i;
    cin >> n;
    for (i = 1; i <= n; i++)
        cin >> a[i];

    pref[1] = 0;
    for (i = 2; i <= n; i++)
        if (a[i] <= a[i - 1])
            pref[i] = pref[i - 1] + a[i - 1] - a[i] + 1;
        else 
            pref[i] = pref[i - 1];

    suff[n] = 0;
    for (i = n - 1; i >= 1; i--)
        if (a[i] <= a[i + 1])
            suff[i] = suff[i + 1] + a[i + 1] - a[i] + 1;
        else
            suff[i] = suff[i + 1];

    sol = max(suff[1], pref[1]);
    for (i = 2; i <= n; i++)
        sol = min(sol, max(pref[i] , suff[i]));
    cout << sol;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 296 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 304 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 316 KB Output is correct
8 Correct 2 ms 320 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 320 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 336 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 296 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 304 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 316 KB Output is correct
8 Correct 2 ms 320 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 320 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 336 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 79 ms 6176 KB Output is correct
27 Correct 81 ms 6068 KB Output is correct
28 Correct 81 ms 6080 KB Output is correct
29 Correct 80 ms 6156 KB Output is correct
30 Correct 56 ms 5388 KB Output is correct
31 Correct 78 ms 6076 KB Output is correct
32 Correct 80 ms 6252 KB Output is correct
33 Correct 80 ms 6160 KB Output is correct
34 Correct 82 ms 6092 KB Output is correct
35 Correct 52 ms 5284 KB Output is correct
36 Correct 55 ms 5408 KB Output is correct
37 Correct 56 ms 5412 KB Output is correct
38 Correct 76 ms 6132 KB Output is correct
39 Correct 78 ms 6056 KB Output is correct
40 Correct 82 ms 6068 KB Output is correct
41 Correct 77 ms 6092 KB Output is correct
42 Correct 73 ms 5936 KB Output is correct
43 Correct 78 ms 6100 KB Output is correct
44 Correct 79 ms 6012 KB Output is correct
45 Correct 78 ms 6024 KB Output is correct
46 Correct 80 ms 6148 KB Output is correct
47 Correct 76 ms 6052 KB Output is correct
48 Correct 80 ms 6096 KB Output is correct