제출 #964595

#제출 시각아이디문제언어결과실행 시간메모리
964595Alihan_8Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
25 ms7188 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define ar array #define pb push_back #define ln '\n' #define int long long using i64 = long long; template <class F, class _S> bool chmin(F &u, const _S &v){ bool flag = false; if ( u > v ){ u = v; flag |= true; } return flag; } template <class F, class _S> bool chmax(F &u, const _S &v){ bool flag = false; if ( u < v ){ u = v; flag |= true; } return flag; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector <int> d(n - 1); int lst = -1; for ( int i = 0; i < n; i++ ){ int x; cin >> x; if ( lst != -1 ){ d[i - 1] = x - lst; } lst = x; } vector <int> pf(n), sf(n); for ( int i = 0; i + 1 < n; i++ ){ pf[i + 1] = pf[i] + min(0LL, d[i] - 1); } for ( int i = n - 2; i >= 0; i-- ){ sf[i] = sf[i + 1] + max(0LL, d[i] + 1); } int opt = 1e18; for ( int i = 0; i < n; i++ ){ chmin(opt, max(sf[i], -pf[i])); } cout << opt; cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...