Submission #532476

#TimeUsernameProblemLanguageResultExecution timeMemory
532476scottchouGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
40 / 100
2 ms588 KiB
#include<iostream>
#include<queue>
using namespace std;
int const N = 2005;
typedef long long LL;
LL const inf = 1e18;
LL a[N], dif[N];
LL suf[N];
int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        dif[i] = a[i] - a[i - 1];
    }
    for(int i = n; i > 0; i--){
        suf[i] = suf[i + 1];
        if(dif[i] >= 0){
            suf[i] += dif[i] + 1;
        }
    }
    LL ans = inf, pre = 0;
    for(int i = 1; i <= n; i++){
        if(dif[i] <= 0){
            pre += (-dif[i]) + 1;
        }
        ans = min(ans, max(pre, suf[i + 1]));
    }
    cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...