Submission #686276

#TimeUsernameProblemLanguageResultExecution timeMemory
686276PacybwoahGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms212 KiB
#include<iostream> #include<vector> #include<algorithm> #define ll long long using namespace std; int main(){ int n; cin>>n; vector<ll> old(n+2); for(int i=0;i<n;i++) cin>>old[i+1]; vector<ll> vec(n+1); for(int i=0;i<=n;i++) vec[i]=old[i+1]-old[i]; ll pos=0,neg=0; for(int i=0;i<=n;i++){ if(vec[i]>=0) pos+=vec[i]+1; } ll ans=1e18; for(int i=0;i<n;i++){ if(vec[i]<=0){ neg-=vec[i]; neg++; } else{ pos-=vec[i]; pos--; } ans=min(ans,max(pos,neg)); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...