제출 #505170

#제출 시각아이디문제언어결과실행 시간메모리
505170DanerZeinGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
40 / 100
1090 ms4020 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ int n; cin>>n; vector<ll> x; for(int i=0;i<n;i++){ ll a; cin>>a; x.push_back(a); } ll res=1e14+1; for(int i=0;i<n;i++){ ll ac=0; vector<ll> y=x; ll c=0; for(int j=1;j<=i;j++){ if(y[j]<=y[j-1]){ ac+=(y[j-1]-y[j])+1; c+=(y[j-1]-y[j])+1; } } y[i]+=ac; for(int j=i+1;j<n;j++){ if(y[j-1]<=y[j]){ c+=(y[j]-y[j-1])+1; ac=0; y[j-1]=y[j]+1; } if(y[j]+ac>=y[j-1]){ ac=abs(y[j]-y[j-1])-1; } y[j]+=ac; } res=min(res,c); } cout<<res<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...