제출 #1006971

#제출 시각아이디문제언어결과실행 시간메모리
1006971faqinyeagerGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> #define ff first #define ss second using namespace std; using ll = long long; int n; vector<ll> a, pref, suff; int main(){ cin >> n; a.resize(n); pref.resize(n, 0); suff.resize(n, 0); for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 1; i < n; i++) if(a[i - 1] >= a[i]) pref[i] = a[i - 1] - a[i] + 1; for(int i = n - 2; i >= 0; i--) if(a[i] <= a[i + 1]) suff[i] = a[i + 1] - a[i] + 1; for(int i = 1; i < n; i++) pref[i] += pref[i - 1]; for(int i = n - 2; i >= 0; i--) suff[i] += suff[i + 1]; if(pref[n - 1] == 0 || suff[0] == 0){ cout << 0; return 0; } ll ans = 1e14; for(int i = 1; i < n; i++){ ans = min(ans, max(pref[i - 1], suff[i])); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...