제출 #1095302

#제출 시각아이디문제언어결과실행 시간메모리
1095302Tesla89Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
19 ms6308 KiB
#include <bits/stdc++.h> #define endl '\n' using namespace std; int a[200010]; long pref[200010],suf[200010],res=LONG_MAX; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin>>n; for(int i=1;i<=n;i++)cin>>a[i]; for(int i=1;i<=n;i++){ if(a[i]>a[i-1])pref[i]=pref[i-1]; else pref[i]=pref[i-1]+a[i-1]-a[i]+1; } for(int i=n-1;i>0;i--){ if(a[i]>a[i+1])suf[i]=suf[i+1]; else suf[i]=suf[i+1]+a[i+1]-a[i]+1; } for(int i=1;i<=n;i++)res=min(res,max(pref[i],suf[i])); cout<<res<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...