제출 #912266

#제출 시각아이디문제언어결과실행 시간메모리
912266andrei_iorgulescuGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
24 ms8608 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int n,a[200005],d[200005]; int pref[200005],suf[200005]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i < n; i++) d[i] = a[i + 1] - a[i]; for (int i = 1; i < n; i++) pref[i] = pref[i - 1] + max(-d[i] + 1,0ll); for (int i = n - 1; i >= 1; i--) suf[i] = suf[i + 1] + max(d[i] + 1,0ll); int ans = 1e18; for (int k = 1; k <= n; k++) ans = min(ans,max(pref[k - 1],suf[k])); cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...