Submission #1251677

#TimeUsernameProblemLanguageResultExecution timeMemory
1251677inkvizytorGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
0 / 100
0 ms324 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> a (n, 0);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<ll> sp (n, 0), ss (n, 0);
    for (int i = 1; i < n; i++) {
        sp[i] = sp[i-1]+max(0ll, a[i-1]-a[i]+1);
    }
    for (int i = n-2; i >= 0; i--) {
        ss[i] = ss[i+1]+max(0ll, a[i+1]-a[i]+1);
    }
    ll w = 1e18;
    for (int i = 0; i < n; i++) {
        w = min(w, sp[i]+ss[i]);
    }
    cout << w << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...