This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |