제출 #1092255

#제출 시각아이디문제언어결과실행 시간메모리
1092255ortsacGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
62 ms7004 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { int n; cin >> n; vector<int> v(n + 2); for (int i = 1; i <= n; i++) { cin >> v[i]; } vector<int> pf(n + 1), sf(n + 2); for (int i = 1; i <= n; i++) { int k = max(0LL, (v[i - 1] - v[i] + 1)); pf[i] = (pf[i - 1] + k); } for (int i = n; i >= 1; i--) { int k = max(0LL, (v[i + 1] - v[i] + 1)); sf[i] = (sf[i + 1] + k); } int ans = 0x3f3f3f3f3f3f3f3f; for (int i = 1; i <= n; i++) { // i is k int x = max(pf[i - 1], sf[i + 1]); int y = max(v[i - 1], v[i + 1]); int z = max(0LL, y - v[i] + 1); //cout << x << " " << y << " " << z << " " << x+z << "\n"; ans = min(ans, x + z); } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...