제출 #1027115

#제출 시각아이디문제언어결과실행 시간메모리
1027115aykhnGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
40 / 100
8 ms6088 KiB
#include <bits/stdc++.h> using namespace std; #define inf 0x3F3F3F3F3F3F3F3F #define int long long const int MXN = 1e5 + 5; int n; int a[MXN]; int p[MXN], s[MXN]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; a[0] = -inf, a[n + 1] = -inf; for (int i = 1; i <= n; i++) p[i] = p[i - 1] + max(0LL, a[i - 1] + 1 - a[i]); for (int i = n; i >= 1; i--) s[i] = s[i + 1] + max(0LL, a[i + 1] + 1 - a[i]); int res = inf; for (int i = 1; i <= n; i++) res = min(res, max(p[i - 1], s[i + 1]) + max(0LL, max(a[i - 1], a[i + 1]) + 1 - a[i])); cout << res << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...