제출 #957633

#제출 시각아이디문제언어결과실행 시간메모리
957633peterandvoiGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
22 ms7112 KiB
#include <bits/stdc++.h>

using namespace std;

#ifdef ngu
#include "debug.h"
#else
#define debug(...) 42
#endif

#define int long long

const int N = (int) 2e5 + 5;

int n;
int a[N];
int L[N], R[N];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifdef ngu
    freopen("test.inp", "r", stdin);
    freopen("test.out", "w", stdout);
    #endif
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        if (i > 1) {
            L[i] = L[i - 1] + max(0LL, a[i - 1] - a[i] + 1);
        }
    }
    for (int i = n - 1; i >= 1; --i) {
        R[i] = R[i + 1] + max(0LL, a[i + 1] - a[i] + 1);
    }
    const int INF = (int) 1e18;
    int res = INF;
    for (int i = 1; i <= n; ++i) {
        res = min(res, max(L[i], R[i]));
    }
    cout << res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...