제출 #856805

#제출 시각아이디문제언어결과실행 시간메모리
856805StefanSebezGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
67 ms7068 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int inf=1e18; signed main() { int n;cin>>n; int a[n+50]={0};for(int i=1;i<=n;i++)cin>>a[i]; int pref[n+50]={0},suf[n+50]={0}; for(int i=1;i<=n;i++) { int x=a[i-1]-a[i]+1;if(x<0) x=0; pref[i]=pref[i-1]+x; int j=n-i+1; x=a[j+1]-a[j]+1;if(x<0) x=0; suf[j]=suf[j+1]+x; } /*for(int i=1;i<=n;i++)printf("%i ",pref[i]); printf("\n"); for(int i=1;i<=n;i++)printf("%i ",suf[i]); printf("\n");*/ int res=inf; for(int i=1;i<=n;i++) { int x=max(pref[i],suf[i]); res=min(res,x); } cout<<res<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...