제출 #523311

#제출 시각아이디문제언어결과실행 시간메모리
523311lucriGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
82 ms6980 KiB
#include <iostream> using namespace std; long long n,a[200010],st[200010],dr[200010],ans=100000000000000000; int main() { cin>>n; for(int i=1;i<=n;++i) { cin>>a[i]; st[i]=st[i-1]; if(a[i-1]>=a[i]) st[i]+=a[i-1]-a[i]+1; } for(int i=n;i>=1;--i) { dr[i]=dr[i+1]; if(a[i+1]>=a[i]) dr[i]+=a[i+1]-a[i]+1; } for(int i=1;i<=n;++i) ans=min(ans,max(st[i],dr[i])); cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...