제출 #870024

#제출 시각아이디문제언어결과실행 시간메모리
870024PanndaGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
20 ms4520 KiB
#include <bits/stdc++.h> using namespace std; const long long INF = (long long)3e18; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<long long> pre(n); pre[0] = 0; for (int i = 1; i < n; i++) { pre[i] = pre[i - 1] + max(0, a[i - 1] + 1 - a[i]); } vector<long long> suf(n); suf[n - 1] = 0; for (int i = n - 2; i >= 0; i--) { suf[i] = suf[i + 1] + max(0, a[i + 1] + 1 - a[i]); } long long ans = INF; for (int i = 0; i < n; i++) { ans = min(ans, max(pre[i], suf[i])); } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...