# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
388167 | BartolM | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++17 | 33 ms | 8492 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define DEBUG 1
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;
const int INF=0x3f3f3f3f;
const int N=2e5+5;
int n;
ll p[N], pref[N], suff[N];
ll br[N];
void solve() {
br[0]=p[0]; pref[0]=0;
for (int i=1; i<n; ++i) {
br[i]=max(p[i]+pref[i-1], br[i-1]+1);
pref[i]=max(pref[i-1], br[i]-p[i]);
}
br[n-1]=p[n-1]; suff[n-1]=0;
for (int i=n-2; i>=0; --i) {
br[i]=max(p[i]+suff[i+1], br[i+1]+1);
suff[i]=max(suff[i+1], br[i]-p[i]);
}
ll sol=(ll)INF*INF;
for (int i=0; i<n; ++i) sol=min(sol, max(pref[i], suff[i]));
printf("%lld\n", sol);
}
void load() {
scanf("%d", &n);
for (int i=0; i<n; ++i) scanf("%lld", p+i);
}
int main() {
load();
solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |