Submission #690936

#TimeUsernameProblemLanguageResultExecution timeMemory
690936stevancvGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms340 KiB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 2e5 + 2;
const ll linf = 1e18;
int a[N], b[N];
ll p[N], s[N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n; cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i < n; i++) b[i] = a[i + 1] - a[i];
    for (int i = 1; i < n; i++) p[i] = p[i - 1] + max(0, 1 - b[i]);
    for (int i = n - 1; i >= 1; i--) s[i] = s[i + 1] + max(0, b[i] + 1);
    ll ans = s[1];
    for (int i = 1; i < n; i++) smin(ans, max(p[i], s[i]));
    cout << ans << en;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...