제출 #477947

#제출 시각아이디문제언어결과실행 시간메모리
477947LouayFarahGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
40 / 100
25 ms8496 KiB
#include "bits/stdc++.h" using namespace std; #define endl "\n" #define ll long long #define pb push_back #define mp make_pair const long long MOD = 1e9+7; const long long INF = 1e18; void solve(vector<ll> arr, int n, vector<ll> &pre) { for(int i = 1; i<n; i++) { pre[i] = max(0LL, arr[i-1]-arr[i]+1) + pre[i-1]; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<ll> arr(n); for(int i = 0; i<n; i++) cin >> arr[i]; vector<ll> pre1(n, 0), pre2(n, 0); solve(arr, n, pre1); reverse(arr.begin(), arr.end()); solve(arr, n, pre2); ll res = 1e12; for(int i = 0; i<n; i++) { res = min(res, max(pre1[i], pre2[n-i-1])); } cout << res << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...