제출 #703177

#제출 시각아이디문제언어결과실행 시간메모리
703177ld_minh4354Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
27 ms6948 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define pb push_back #define debug(x) cout<<#x<<": "<<x<<"\n" signed main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); // freopen("input.000","r",stdin); // freopen("output.000","w",stdout); // srand((unsigned)time(NULL)); // rand() int n,i,a[200005],l[200005],r[200005],ans; cin>>n; for (i=1;i<n+1;i++) cin>>a[i]; l[1]=0; for (i=2;i<n+1;i++) l[i]=max(0ll, a[i-1]-a[i]+1); for (i=3;i<n+1;i++) l[i] += l[i-1]; r[n]=0; for (i=n-1;i>0;i--) r[i]=max(0ll, a[i+1]-a[i]+1); for (i=n-2;i>0;i--) r[i] += r[i+1]; ans=1e18; for (i=1;i<n+1;i++) ans=min(ans,max(l[i],r[i])); cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...