제출 #931927

#제출 시각아이디문제언어결과실행 시간메모리
931927AiperiiiGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
30 ms756 KiB
#include <bits/stdc++.h> #define int long long #define ff first #define ss second #define all(x) x.begin(),x.end() #define pb push_back using namespace std; signed main(){ ios_base::sync_with_stdio(); cin.tie(0);cout.tie(0); int n;cin>>n; vector <int> a(n+1); for(int i=1;i<=n;i++)cin>>a[i]; a.pb(0); int mn=1e18; vector <int> cnt(n+1); for(int i=1;i<=n;i++){ vector <int> v=a; for(int j=1;j<=i;j++){ v[j]=max(v[j-1]+1,v[j]); cnt[j]=v[j]-a[j]; } for(int j=n;j>=i;j--){ v[j]=max(v[j+1]+1,v[j]); cnt[j]=v[j]-a[j]; } int ans=0; int l=1,r=n; while(l<=r){ int x=min(cnt[l],cnt[r]); ans+=x; cnt[l]-=x; if(r!=l)cnt[r]-=x; if(!cnt[l])l++; if(!cnt[r])r--; } mn=min(mn,ans); } cout<<mn<<"\n"; } /* 5 3 2 2 3 1 5 9 7 5 3 1 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...