제출 #460559

#제출 시각아이디문제언어결과실행 시간메모리
460559MKutayBozkurtGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms332 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> a(n + 1); for (int i = 1; i <= n; i++) cin >> a[i]; vector<int> left(n + 1), right(n + 1); for (int i = 2; i <= n; i++) { left[i] = left[i - 1] + max(0, a[i - 1] - a[i] + 1); } for (int i = n - 1; i > 0; i--) { right[i] = right[i + 1] + max(0, a[i + 1] - a[i] + 1); } int ans = min(right[1], left[n]); for (int i = 2; i <= n; i++) { ans = min(ans, max(left[i], right[i])); } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...