제출 #634784

#제출 시각아이디문제언어결과실행 시간메모리
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...