제출 #375743

#제출 시각아이디문제언어결과실행 시간메모리
375743rama_pangGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
33 ms6656 KiB
#include <bits/stdc++.h> using namespace std; using lint = long long; int main() { ios::sync_with_stdio(0); cin.tie(0); int N; cin >> N; vector<lint> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } vector<lint> B(N - 1); for (int i = 0; i < N - 1; i++) { B[i] = A[i + 1] - A[i]; } // [l, r] += v -> B[l - 1] += v, B[r] -= v // exist k, B[0...k-1] >= 1, B[k...N-2] <= -1 vector<lint> pref(N - 1); vector<lint> suff(N - 1); for (int i = 0; i < N - 1; i++) { pref[i] = (i > 0 ? pref[i - 1] : 0) + (B[i] <= 0 ? (-B[i] + 1) : 0); } for (int i = N - 2; i >= 0; i--) { suff[i] = (i < N - 2 ? suff[i + 1] : 0) + (B[i] >= 0 ? (B[i] + 1) : 0); } lint ans = LLONG_MAX; for (int i = 0; i < N; i++) { ans = min(ans, max(i > 0 ? pref[i - 1] : 0, i < N - 1 ? suff[i] : 0)); } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...