Submission #756792

#TimeUsernameProblemLanguageResultExecution timeMemory
756792gvancakGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++11
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> #define ll long long #define f first #define s second #define pb push_back using namespace std; ll mn,mx,x,n,m,k,a[100005],b[100005],l,d,ans,pref[100005],suf[1000005],y; bool ok,okk; pair <ll,ll> dp[100005]; int main(){ cin>>n; for (int i=1; i<=n; i++){ cin>>a[i]; b[i]=a[i]; } pref[0]=0; for (int i=2; i<=n; i++){ if (a[i-1]<a[i]) { pref[i]=pref[i-1]; continue; } pref[i]=pref[i-1]+a[i-1]+1-a[i]; } suf[n]=0; for (int i=n-1; i>=1; i--){ if (a[i+1]<a[i]) { suf[i]=suf[i+1]; continue; } suf[i]=suf[i+1]+a[i+1]+1-a[i]; } ans=1e9; for (int i=1; i<=n; i++){ ans=min(ans,max(pref[i],suf[i])); } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...