Submission #1311486

#TimeUsernameProblemLanguageResultExecution timeMemory
1311486madamadam3Growing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
18 ms5220 KiB
#include <bits/stdc++.h>

using namespace std;
#define int long long int

signed main() {
    cin.tie(0)->sync_with_stdio(0);

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

    vector<int> f(n), r(n);
    f[0] = r[n-1] = 0;

    for (int i = 1; i < n; i++) {
        int dx = (a[i-1] + 1) - (a[i]);
        f[i] = max(0LL, dx) + f[i-1];

        int dy = (a[n-i] + 1) - (a[n-i-1]);
        r[n-i-1] = max(0LL, dy) + r[n-i];
    }

    int t = 4e18; for (int i = 0; i < n; i++) t = min(t, max(f[i], r[i]));
    cout << t << "\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...