Submission #706131

# Submission time Handle Problem Language Result Execution time Memory
706131 2023-03-06T00:38:26 Z Pring Growing Vegetables is Fun 4 (JOI21_ho_t1) C++14
100 / 100
24 ms 3440 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
typedef pair<int, int> pii;

const int MXN = 200005;
int n, a[MXN], d[MXN];

int getANS() {
    int l = 0, r = n - 2, ans = 0;
    while (l < n - 1 && d[l] > 0) l++;
    while (r >= 0 && d[r] < 0) r--;
    if (l == n - 1 || r == -1) return 0;
    while (l < r) {
        int small = min(1 - d[l], d[r] + 1);
        d[l] += small;
        d[r] -= small;
        ans += small;
        while (l < n - 1 && d[l] > 0) l++;
        while (r >= 0 && d[r] < 0) r--;
    }
    if (l == r && d[l] == 0) ans++;
    return ans;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 1; i < n; i++) d[i - 1] = a[i] - a[i - 1];
    cout << getANS() << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 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 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 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 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 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 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 21 ms 3344 KB Output is correct
27 Correct 21 ms 3408 KB Output is correct
28 Correct 21 ms 3364 KB Output is correct
29 Correct 20 ms 3404 KB Output is correct
30 Correct 17 ms 3372 KB Output is correct
31 Correct 24 ms 3344 KB Output is correct
32 Correct 22 ms 3412 KB Output is correct
33 Correct 24 ms 3408 KB Output is correct
34 Correct 20 ms 3388 KB Output is correct
35 Correct 16 ms 3420 KB Output is correct
36 Correct 17 ms 3332 KB Output is correct
37 Correct 18 ms 3412 KB Output is correct
38 Correct 21 ms 3372 KB Output is correct
39 Correct 22 ms 3412 KB Output is correct
40 Correct 19 ms 3332 KB Output is correct
41 Correct 20 ms 3380 KB Output is correct
42 Correct 19 ms 3376 KB Output is correct
43 Correct 21 ms 3440 KB Output is correct
44 Correct 20 ms 3344 KB Output is correct
45 Correct 19 ms 3404 KB Output is correct
46 Correct 19 ms 3412 KB Output is correct
47 Correct 20 ms 3348 KB Output is correct
48 Correct 22 ms 3328 KB Output is correct