제출 #1028799

#제출 시각아이디문제언어결과실행 시간메모리
1028799vjudge1Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
24 ms6304 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int maxn = 2e5 + 7; int n , a[maxn] ; ll precnt[maxn] , sufcnt[maxn]; void solve() { cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++) { precnt[i] = precnt[i-1]; if(a[i] <= a[i-1]) { precnt[i] += a[i-1] - a[i] + 1; } } for(int i = n; i >= 1; i--) { sufcnt[i] = sufcnt[i+1]; if(a[i] <= a[i+1]) { sufcnt[i] += a[i+1] - a[i] + 1; } } ll ans = 1e18; for(int i = 1; i <= n; i++) { ans = min(ans , max(precnt[i] , sufcnt[i])); } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...