제출 #533861

#제출 시각아이디문제언어결과실행 시간메모리
533861someoneGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
24 ms6940 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 2e5 + 42, INF = 1e18; int n, a[N], val[N][2]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 1; i < n; i++) val[i][0] = val[i-1][0] + max(a[i-1] + 1 - a[i], 0ll); for(int i = n-2; i > -1; i--) val[i][1] = val[i+1][1] + max(a[i+1] + 1 - a[i], 0ll); int ans = INF; for(int i = 0; i < n; i++) ans = min(ans, max(val[i][0], val[i][1])); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...