Submission #634784

#TimeUsernameProblemLanguageResultExecution timeMemory
634784mdn2002Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
94 ms6988 KiB
#include<bits/stdc++.h> using namespace std; long long n , a [200005] , suma , sumb , ans = 1e18 , dif [200005] , rdif [200005]; int main () { cin >> n; for ( int i = 1 ; i <= n ; i ++ ) { cin >> a [i]; if ( i != 1 ) dif [i] = max ( 0ll , a [ i - 1 ] - a [i] + 1 ); dif [i] += dif [ i - 1 ]; } for ( int i = n ; i >= 1 ; i -- ) { if ( i != n ) rdif [i] = max ( 0ll , a [ i + 1 ] - a [i] + 1 ); rdif [i] += rdif [ i + 1 ]; } for ( int i = 1 ; i <= n ; i ++ ) ans = min ( ans , max ( dif [i] , rdif [i] ) ); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...