제출 #396911

#제출 시각아이디문제언어결과실행 시간메모리
396911AQTGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
30 ms6148 KiB
#include <bits/stdc++.h> using namespace std; int N; int arr[200005]; /* int mnpre[200005]; long long sumpre[200005]; int mnsuf[200005]; long long sumsuf[200005]; */ long long mxpre[200005]; long long mxsuf[200005]; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N; for(int i = 1; i <= N; i++){ cin >> arr[i]; } /* for(int i = 1; i <= N; i++){ mnpre[i] = max(arr[i], mnpre[i-1] + 1); sumpre[i] = sumpre[i-1] + mnpre[i] - arr[i]; } for(int i = N; i; i--){ mnsuf[i] = max(arr[i], mnsuf[i+1] + 1); sumsuf[i] = sumsuf[i+1] + mnsuf[i] - arr[i]; } long long ans = LLONG_MAX/2; for(int i = 1; i <= N; i++){ int lft = mnpre[i-1]; int rht = mnsuf[i+1]; long long tot = sumpre[i-1] + sumsuf[i+1]; tot += max({lft, rht, arr[i]}) - arr[i]; ans = min(ans, tot); } cout << ans; */ for(int i = 1; i <= N; i++){ mxpre[i] = max(0, arr[i-1] + 1 - arr[i]); mxpre[i] += mxpre[i-1]; } for(int i = N; i; i--){ mxsuf[i] = max(0, arr[i+1] + 1 - arr[i]); mxsuf[i] += mxsuf[i+1]; } long long ans = LLONG_MAX; for(int i = 1; i <= N; i++){ ans = min(ans, max(mxsuf[i], mxpre[i])); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...