제출 #807198

#제출 시각아이디문제언어결과실행 시간메모리
807198annabeth9680Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
75 ms6908 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { int N; cin >> N; vector<ll> arr(N); for(int i = 0;i<N;++i) cin >> arr[i]; vector<ll> f(N,0),g(N,0); //f : for increasing numbers before i; g : for decreasing numbers after i (that are bigger than arr[i]) for(int i = 1;i<N;++i){ f[i] = f[i-1]+max(arr[i-1]-arr[i]+1,0ll); } for(int i = N-2;i>=0;--i){ g[i] = g[i+1]+max(arr[i+1]-arr[i]+1,0ll); } ll ans = 1e18; for(int i = 0;i<N;++i){ //cout << f[i] << " " << g[i] << "\n"; ans = min(ans,max(f[i],g[i])); } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...