제출 #923387

#제출 시각아이디문제언어결과실행 시간메모리
923387ting39Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
77 ms7200 KiB
#include<bits/stdc++.h> #define int long long using namespace std; signed main(){ int n; cin>>n; vector<int> v(n),pre(n),suf(n); for(int &i:v) cin>>i; for(int i=1;i<n;i++){ pre[i]=max(0LL,v[i-1]+1-v[i]); pre[i]+=pre[i-1]; } for(int i=n-2;i>=0;i--){ suf[i]=max(0LL,v[i+1]+1-v[i]); suf[i]+=suf[i+1]; } int ans=1e18; for(int i=0;i<n;i++){ ans=min(ans,max(pre[i],suf[i])); } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...