Submission #937802

#TimeUsernameProblemLanguageResultExecution timeMemory
937802AndreyGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
22 ms7248 KiB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n,sb = 0,br = 0,ans = LLONG_MAX;
    cin >> n;
    vector<long long> haha(n);
    vector<long long> wow(n-1);
    vector<long long> wut(n-1);
    for(long long i = 0; i < n; i++) {
        cin >> haha[i];
    }
    for(long long i = 0; i < n-1; i++) {
        wow[i] = max(haha[i]-haha[i+1]+1,0LL);
        sb+=wow[i];
        wut[i] = max(haha[n-i-1]-haha[n-i-2]+1,0LL);
    }
    ans = min(ans,sb);
    for(long long i = n-2; i >= 0; i--) {
        sb-=wow[i];
        br+=wut[n-i-2];
        ans = min(ans,max(sb,br));
    }
    cout << ans;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...