제출 #677010

#제출 시각아이디문제언어결과실행 시간메모리
677010rittin1Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
28 ms6952 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int arr[n+1]; for(int i=1;i<=n;i++){ cin >> arr[i]; } int dp1[n+1]; int dp2[n+1]; dp1[1]=0; for(int i=2;i<=n;i++){ dp1[i]=dp1[i-1]; if(arr[i]<=arr[i-1]){ dp1[i]+=arr[i-1]-arr[i]+1; } } dp2[n]=0; for(int i=n-1;i>=1;i--){ dp2[i]=dp2[i+1]; if(arr[i]<=arr[i+1]){ dp2[i]+=arr[i+1]-arr[i]+1; } } int ans=max(dp1[1],dp2[1]); for(int i=2;i<=n;i++){ ans=min(ans,max(dp1[i],dp2[i])); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...