Submission #1112652

#TimeUsernameProblemLanguageResultExecution timeMemory
1112652sunboiGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
76 ms7092 KiB
#include <bits/stdc++.h>
 
using namespace std;
#define int long long
 

 
signed main(){
    int n; cin >> n;
    vector<int> a(n), pref(n), suf(n);
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    for (int i = 1; i < n; i++){
        pref[i] = pref[i - 1];
        if (a[i] <= a[i - 1]){
            pref[i] += (a[i - 1] - a[i] + 1);
        }
    }
    for (int i = n - 2; i >= 0; i--){
        suf[i] = suf[i + 1];
        if (a[i] <= a[i + 1]){
            suf[i] += (a[i + 1] - a[i] + 1);
        }
    }
    int ans = 1e18 + 7;
    for (int i = 0; i < n; i++){
        ans = min(ans, max(suf[i], pref[i]));
    }
    cout << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...