제출 #932000

#제출 시각아이디문제언어결과실행 시간메모리
932000AiperiiiGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
85 ms7344 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); for(int i=0;i<n;i++){ cin>>a[i]; } vector <int> pr(n),sf(n); for(int i=1;i<n;i++){ pr[i]=pr[i-1]; if(a[i-1]>=a[i])pr[i]+=a[i-1]-a[i]+1; } for(int i=n-2;i>=0;i--){ sf[i]=sf[i+1]; if(a[i+1]>=a[i])sf[i]+=a[i+1]-a[i]+1; } int ans=1e18; for(int i=0;i<n;i++){ ans=min(ans,max(sf[i],pr[i])); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...