제출 #878987

#제출 시각아이디문제언어결과실행 시간메모리
878987frostray8653Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
21 ms8688 KiB
#include <bits/stdc++.h> #define int long long #define IO ios::sync_with_stdio(0), cin.tie(0); #define FOR(i, a, b) for (int i = a; i <= b; i++) using namespace std; using pii = pair<int, int>; void dbg() {;} template<class T, class ...U> void dbg(T a, U ...b) { cout << a << " "; dbg(b...); } void ent() { cout << "\n"; } const int INF = 1e16; const int N = 200005; int a[N], b[N]; int dx[2][N]; signed main() { IO; int n; cin >> n; FOR(i, 1, n) cin >> a[i]; FOR(i, 2, n) b[i] = a[i] - a[i - 1]; FOR(i, 2, n) { if (b[i] <= 0) dx[0][i] = 1 - b[i]; if (b[i] >= 0) dx[1][i] = b[i] - (- 1); dx[0][i] += dx[0][i - 1]; dx[1][i] += dx[1][i - 1]; } int ans = INF; FOR(i, 1, n) { int pre = dx[0][i]; int suf = dx[1][n] - dx[1][i]; ans = min(ans, max(pre, suf)); } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...