제출 #896633

#제출 시각아이디문제언어결과실행 시간메모리
896633arbuzickGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
40 / 100
1063 ms3176 KiB
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } long long ans = 1e18 + 7; for (int md = 0; md < n; ++md) { long long start = 0, finish = 0; for (int i = 0; i < md; ++i) { if (a[i] >= a[i + 1]) { start += a[i] - a[i + 1] + 1; } } for (int i = md; i < n - 1; ++i) { if (a[i] <= a[i + 1]) { finish += a[i + 1] - a[i] + 1; } } ans = min(ans, max(start, finish)); } cout << ans << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...