Submission #814054

#TimeUsernameProblemLanguageResultExecution timeMemory
814054MohamedAhmed04Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
25 ms6136 KiB
#include <bits/stdc++.h> using namespace std ; const int MAX = 2e5 + 10 ; int arr[MAX] ; int n ; long long pref[MAX] , suff[MAX] ; int main() { ios_base::sync_with_stdio(0) ; cin.tie(0) ; cin>>n ; for(int i = 1 ; i <= n ; ++i) cin>>arr[i] ; for(int i = 2 ; i <= n ; ++i) pref[i] = pref[i-1] + max(0 , arr[i-1] + 1 - arr[i]) ; for(int i = n-1 ; i >= 1 ; --i) suff[i] = suff[i+1] + max(0 , arr[i+1] + 1 - arr[i]) ; long long ans = 4e18 ; for(int i = 1 ; i <= n ; ++i) ans = min(ans , max(pref[i] , suff[i])) ; return cout<<ans<<"\n" , 0 ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...