Submission #412974

#TimeUsernameProblemLanguageResultExecution timeMemory
412974wiritos16Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
35 ms6952 KiB
#include<bits/stdc++.h> #define ll long long using namespace std; ll arr[200000]; ll izq[200000]; ll der[200000]; int main() { std::ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n; cin>>n; for(ll i=0;i<n;i++) { cin>>arr[i]; } izq[0]=0; for(ll i=1;i<n;i++) { izq[i]=izq[i-1]+max((long long)0,arr[i-1]-arr[i]+1); } der[n-1]=0; for(ll i=n-2;i>=0;i--) { der[i]=der[i+1]+max((long long)0,arr[i+1]-arr[i]+1); } ll cont=max(der[0],izq[0]); for(ll i=1;i<n;i++) { cont=min(cont,max(der[i],izq[i])); } cout<<cont; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...