Submission #706129

#TimeUsernameProblemLanguageResultExecution timeMemory
706129pccGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms340 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; 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 = 1e9+10; for(int i = 2;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...