제출 #756791

#제출 시각아이디문제언어결과실행 시간메모리
756791gvancakGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++11
0 / 100
0 ms212 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-a[i+1]; } 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...