제출 #1172913

#제출 시각아이디문제언어결과실행 시간메모리
1172913nguyenkhangninh99Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
13 ms4936 KiB

#include <bits/stdc++.h>
using namespace std;

#define int long long

void solve(){
    int n; cin >> n;

    vector<int> pre(n + 2), suf(n + 2), a(n + 2);

    int ans = 1e18;

    for (int i = 1; i <= n; i++){
        cin >> a[i];
        pre[i] = (i == 1 ? 0 : pre[i - 1] + max(0ll, a[i - 1] - a[i] + 1));
    }
    for (int i = n; i >= 1; i--){
        suf[i] = (i == n ? 0 : suf[i + 1] + max(0ll, a[i + 1] - a[i] + 1));
        ans = min(ans, max(pre[i], suf[i]));
    }
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
 
    solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...