제출 #922472

#제출 시각아이디문제언어결과실행 시간메모리
922472Abdalaziz_AlshamiGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 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; int a[n],x[n],y[n]; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<n-1;i++) { if(a[i]>=a[i+1]) x[i]=a[i]-a[i+1]+1; else x[i]=0; if(i) x[i]+=x[i-1]; } y[n-1]=0; for(int i=n-2;i>=0;i--) { if(a[i]<=a[i+1]) y[i]=a[i+1]-a[i]+1; else y[i]=0; y[i]+=y[i+1]; } int ans=min(x[n-2],y[0]); for(int i=1;i<n-2;i++) ans=min(ans,x[i-1]+y[i+1]); cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...