Submission #383718

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

#define fi first
#define se second

typedef long long ll;
typedef pair<int,int> ii;

const int N = 2e5;
const ll INF = 1e18;
int n;
int a[N+2], b[N+2];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    ll ans = INF;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= i-1; j++) b[j] = max(b[j-1]+1,a[j]);
        for (int j = n; j >= i+1; j--) b[j] = max(b[j+1]+1,a[j]);
        b[i] = max(max(b[i-1],b[i+1])+1,a[i]);
        ll cost = 0;
        for (int j = 1; j <= n; j++) {
            b[j] -= a[j];
            cost += max(0,b[j]-b[j-1]);
        }
        ans = min(ans,cost);
    }
    cout << ans << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...