Submission #553559

#TimeUsernameProblemLanguageResultExecution timeMemory
553559andrei_boacaGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
28 ms8652 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n,v[200005],ans=1e18,a[200005],toneg[200005],topos[200005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; n++; for(int i=1;i<=n;i++) v[i]=a[i]-a[i-1]; for(int i=n;i>=1;i--) { toneg[i]=toneg[i+1]; if(v[i]>=0) toneg[i]+=v[i]+1; } for(int i=1;i<=n;i++) { topos[i]=topos[i-1]; if(v[i]<=0) topos[i]+=abs(v[i])+1; } for(int i=1;i<n;i++) { ll val=max(topos[i],toneg[i+1]); ans=min(ans,val); } cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...