제출 #460735

#제출 시각아이디문제언어결과실행 시간메모리
460735BarayGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
102 ms5060 KiB
#include <iostream> #include <vector> #include <set> #include <queue> #include <stack> #include <algorithm> #include <climits> using namespace std; long long n, ans = 1000000000000000; int main() { cin >> n; vector<long long> arr(n), pre(n), suf(n); suf[n - 1] = 0; pre[0] = 0; for (long long i = 0; i < n; i++) { cin >> arr[i]; } for (long long i = 1; i < n; i++) { pre[i] = pre[i - 1] + max(0ll, arr[i - 1] + 1 - arr[i]); } for (long long i = n - 2; i >= 0; i--) { suf[i] = suf[i + 1] + max(0ll, arr[i + 1] + 1 - arr[i]); } //ans = min(suf[0], pre[n - 1]); pre[0] = 0; suf[n - 1] = 0; for (long long i = 0; i < n; i++) { ans = min(ans, max(suf[i], pre[i])); } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...