# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
756761 | Nika533 | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++14 | 23 ms | 5076 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.
#pragma GCC diagnostic warning "-std=c++11"
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define flush fflush(stdout)
#define all(x) (x).begin(),(x).end()
using namespace std;
int n,m,T,k;
string s;
void test_case() {
cin>>n;
int arr[n+2];
arr[0]=0;
arr[n+1]=0;
int pref[n+2];
pref[0]=0;
pref[n+1]=0;
int suf[n+2];
suf[0]=0;
suf[n+1]=0;
for (int i=1; i<=n; i++) {
cin>>arr[i];
}
for (int i=1; i<=n; i++) {
if (arr[i]>arr[i-1]) {
pref[i]=pref[i-1];
continue;
}
int val=arr[i-1]-arr[i]+1;
pref[i]=pref[i-1];
pref[i]+=val;
}
for (int i=n; i>=1; i--) {
if (arr[i]>arr[i+1]) {
suf[i]=suf[i+1];
continue;
}
int val=arr[i+1]-arr[i]+1;
suf[i]=suf[i+1];
suf[i]+=val;
}
int ans=1e18;
for (int i=1; i<=n; i++) {
//cout<<i<<" "<<pref[i]<<" "<<suf[i]<<endl;
ans=min(ans,max(pref[i],suf[i]));
}
cout<<ans<<endl;
}
main () {
ios :: sync_with_stdio(0);
cin.tie(0); cout.tie(0);
T=1;
while (T--) {
test_case();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |