# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
386074 | CaroLinda | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++14 | 46 ms | 10220 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.
#include <bits/stdc++.h>
#define lp(i,a,b) for(int i = a ; i < b; i++)
#define ll long long
#define all(x) x.begin(),x.end()
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define sz(x) (int)(x.size())
#define ff first
#define ss second
const int MAXN = 2e5+10 ;
using namespace std ;
int N ;
ll A[MAXN] , suf[MAXN] , pref[MAXN] ;
ll valSuf[MAXN] , valPref[MAXN] ;
int main()
{
scanf("%d", &N ) ;
for(int i = 1 ; i <= N ; i++ ) scanf("%lld", &A[i]) ;
lp(i,1,N+1)
{
valPref[i] = valPref[i-1]+(A[i]-A[i-1]) ;
pref[i] = pref[i-1] ;
if( A[i] <= A[i-1] )
{
pref[i] += A[i-1]-A[i]+1 ;
valPref[i] = valPref[i-1]+(A[i-1]-A[i]+1) ;
}
}
for(int i = N ; i > 0 ; i-- )
{
valSuf[i] = valSuf[i+1]+(A[i]-A[i+1]) ;
suf[i] = suf[i+1] ;
if( A[i] <= A[i+1] )
{
suf[i] += A[i+1]-A[i]+1 ;
valSuf[i] = valSuf[i+1]+(A[i+1]-A[i]+1) ;
}
}
ll ans = pref[N] ;
lp(i,1,N+1) ans = min(ans, max(pref[i],suf[i]) ) ;
printf("%lld\n" , ans ) ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |