제출 #458616

#제출 시각아이디문제언어결과실행 시간메모리
458616tempusGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
37 ms3828 KiB
#include <bits/stdc++.h> #define ll long long #define endl '\n' #define ios ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); using namespace std; int main() { ios int n; cin >> n; ll a[n + 2]; for (int i = 0; i < n; ++ i) { cin >> a[i]; } ll f = 0, s = 0; for (int i = 0; i < n - 1; ++ i) { s += max(0ll, a[i + 1] - a[i] + 1); } ll ans = s; for (int i = 1; i < n; ++ i) { s -= max(0ll, a[i] - a[i - 1] + 1); f += max(0ll, a[i - 1] - a[i] + 1); ans = min(ans, max(f, s)); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...