제출 #922603

#제출 시각아이디문제언어결과실행 시간메모리
922603Abdalaziz_AlshamiGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
0 ms348 KiB
#include<bits/stdc++.h> #define int long long using namespace std; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; vector<int>x,y; x.push_back(0); int a[n]; for(auto &i:a) cin>>i; for(int i=0;i<n-1;i++) x.push_back(max(0ll,a[i]-a[i+1]+1)); for(int i=0;i<n-1;i++) y.push_back(max(0ll,a[i+1]-a[i]+1)); y.push_back(0); for(int i=1;i<n;i++) x[i]+=x[i-1]; for(int i=n-2;i>=0;i--) y[i]+=y[i+1]; int ans=1e18; for(int i=0;i<n;i++) ans=min(ans,x[i]+y[i]); cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...