제출 #1132087

#제출 시각아이디문제언어결과실행 시간메모리
1132087lopkusGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
16 ms5092 KiB
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n + 1); for(int i = 1; i <= n; i++) { cin >> a[i]; } vector<int> pref(n + 1, 0); vector<int> suf(n + 1, 0); for(int i = 1; i <= n; i++) { pref[i] = pref[i - 1] + max(a[i - 1] - a[i] + 1, 0LL); } for(int i = n - 1; i >= 0; i--) { suf[i] = suf[i + 1] + max(a[i + 1] - a[i] + 1, 0LL); } int ans = 1e18; for(int i = 1; i <= n; i++) { ans = min(ans, max(pref[i], suf[i])); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...