제출 #994490

#제출 시각아이디문제언어결과실행 시간메모리
994490mnieplowiczGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms2396 KiB
#include <bits/stdc++.h> using namespace std; int tab[200005]; int R[200005]; int pref[200005]; int suf[200005]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for(int i = 0; i < n; i++){ cin >> tab[i]; if(i == 0) continue; R[i] = tab[i] - tab[i-1]; } for(int i = 1; i <= n-1; i++){ pref[i] = pref[i-1]; if(R[i] <= 0) pref[i] += (-R[i])+1; } pref[n] = pref[n-1]; for(int i = n-1; i > 0; i--){ suf[i] = suf[i+1]; if(R[i] >= 0) suf[i] += R[i]+1; } suf[0] = suf[1]; int res = 1e9; for(int i = 0; i <= n; i++){ res = min(res, max(suf[i], pref[i])); } cout << res << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...