제출 #372638

#제출 시각아이디문제언어결과실행 시간메모리
372638SeDunionGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms364 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e6 + 66; int A[N]; ll p[N], s[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int n; cin >> n; for (int i = 1 ; i <= n ; ++ i) cin >> A[i]; for (int i = 2 ; i <= n ; ++ i) { ll add = max(0, A[i] + 1 - A[i - 1]); p[i] = p[i - 1] + add; } for (int i = n - 1 ; i >= 1 ; -- i) { ll add = max(0, A[i] + 1 - A[i + 1]); s[i] = s[i + 1] + add; } ll ans = ll(1e18); for (int i = 1 ; i <= n ; ++ i) { ans = min(ans, max(p[i], s[i])); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...