Submission #956292

#TimeUsernameProblemLanguageResultExecution timeMemory
956292_callmelucianGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
26 ms10324 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tt;

#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())

const int mn = 2e5 + 5;
ll a[mn], ap[mn], as[mn], prf[mn], sfx[mn];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n; cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];

    for (int i = 1; i <= n; i++)
        ap[i] = max(ap[i - 1] + 1, a[i] + prf[i - 1]), prf[i] = max(prf[i - 1], ap[i] - a[i]);
    for (int i = n; i >= 1; i--)
        as[i] = max(as[i + 1] + 1, a[i] + sfx[i + 1]), sfx[i] = max(sfx[i + 1], as[i] - a[i]);

    ll ans = LLONG_MAX;
    for (int i = 1; i <= n; i++)
        ans = min(ans, max(prf[i], sfx[i]));
    cout << ans;

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...