제출 #690937

#제출 시각아이디문제언어결과실행 시간메모리
690937stevancvGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
25 ms7012 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define sp ' ' #define en '\n' #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) using namespace std; const int N = 2e5 + 2; const ll linf = 1e18; int a[N], b[N]; ll p[N], s[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i < n; i++) b[i] = a[i + 1] - a[i]; for (int i = 1; i < n; i++) p[i] = p[i - 1] + max(0, 1 - b[i]); for (int i = n - 1; i >= 1; i--) s[i] = s[i + 1] + max(0, b[i] + 1); ll ans = s[1]; for (int i = 1; i < n; i++) smin(ans, max(p[i], s[i + 1])); cout << ans << en; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...