Submission #1055253

# Submission time Handle Problem Language Result Execution time Memory
1055253 2024-08-12T15:59:55 Z fryingduc Growing Vegetables is Fun 4 (JOI21_ho_t1) C++17
100 / 100
20 ms 12508 KB
#include "bits/stdc++.h"
using namespace std;

const int maxn = 2e5 + 5;
int n, a[maxn];
long long f[maxn], g[maxn];
long long pref[maxn], suf[maxn];
long long b[maxn], c[maxn];

void solve() {
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for(int i = 1; i <= n; ++i) {
        pref[i] = max(pref[i - 1] + 1, 1ll * a[i]);
        b[i] = max(0ll, pref[i] - a[i]);
        f[i] = f[i - 1] + max(0ll, b[i] - b[i - 1]);
    }
    for(int i = n; i; --i) {
        suf[i] = max(suf[i + 1] + 1, 1ll * a[i]);
        c[i] = max(0ll, suf[i] - a[i]);
        g[i] = g[i + 1] + max(0ll, c[i] - c[i + 1]);
    }
    
    long long ans = min(f[n], g[1]);
    for(int i = 1; i < n; ++i) {
        ans = min(ans, max(f[i], g[i]));
    }
    
    cout << ans;
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 0 ms 2520 KB Output is correct
7 Correct 0 ms 2652 KB Output is correct
8 Correct 0 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 0 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2652 KB Output is correct
16 Correct 1 ms 2556 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 0 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 0 ms 2652 KB Output is correct
24 Correct 0 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 0 ms 2520 KB Output is correct
7 Correct 0 ms 2652 KB Output is correct
8 Correct 0 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 0 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2652 KB Output is correct
16 Correct 1 ms 2556 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 0 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 0 ms 2652 KB Output is correct
24 Correct 0 ms 2652 KB Output is correct
25 Correct 1 ms 2904 KB Output is correct
26 Correct 15 ms 12380 KB Output is correct
27 Correct 14 ms 12500 KB Output is correct
28 Correct 20 ms 12492 KB Output is correct
29 Correct 14 ms 12380 KB Output is correct
30 Correct 18 ms 11736 KB Output is correct
31 Correct 14 ms 12380 KB Output is correct
32 Correct 14 ms 12380 KB Output is correct
33 Correct 14 ms 12316 KB Output is correct
34 Correct 14 ms 12368 KB Output is correct
35 Correct 12 ms 11612 KB Output is correct
36 Correct 15 ms 11868 KB Output is correct
37 Correct 12 ms 11648 KB Output is correct
38 Correct 18 ms 12468 KB Output is correct
39 Correct 19 ms 12508 KB Output is correct
40 Correct 17 ms 12380 KB Output is correct
41 Correct 15 ms 12336 KB Output is correct
42 Correct 14 ms 12380 KB Output is correct
43 Correct 17 ms 12440 KB Output is correct
44 Correct 16 ms 12380 KB Output is correct
45 Correct 16 ms 12380 KB Output is correct
46 Correct 18 ms 12376 KB Output is correct
47 Correct 14 ms 12376 KB Output is correct
48 Correct 15 ms 12376 KB Output is correct