제출 #706130

#제출 시각아이디문제언어결과실행 시간메모리
706130pccGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
28 ms6588 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int mxn = 2e5+10; ll arr[mxn],diff[mxn],pref[mxn],suf[mxn]; int main(){ int n; ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>n; for(int i = 1;i<=n;i++){ cin>>arr[i]; if(i>1)diff[i] = arr[i]-arr[i-1]; } for(int i = 2;i<=n;i++){ pref[i] = pref[i-1]+(diff[i]<=0?1-diff[i]:0); } for(int i = n;i>=1;i--){ suf[i] = suf[i+1]+(diff[i]>=0?diff[i]+1:0); } ll ans = 1e18; for(int i = 1;i<=n+1;i++){ ans = min(ans,max(pref[i-1],suf[i])); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...