제출 #906270

#제출 시각아이디문제언어결과실행 시간메모리
906270AlphaMale06Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
25 ms8784 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define yes cout << "YES\n" #define no cout << "NO\n" #define F first #define S second #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define int long long void solve(){ int n; cin >> n; int a[n]; for(int i=0; i< n; i++){ cin >> a[i]; } if(n==1){ cout << 0 << '\n'; return; } vector<int> rz; for(int i=1; i< n; i++)rz.pb(a[i]-a[i-1]); int pref[n]; int suf[n]; pref[0]=0; for(int i=0; i< n-1; i++){ pref[i+1]=pref[i]; if(rz[i]<=0)pref[i+1]+=abs(rz[i])+1; } suf[n-1]=0; for(int i=n-2; i>=0; i--){ suf[i]=suf[i+1]; if(rz[i]>=0)suf[i]+=rz[i]+1; } int ans=1e18; for(int i=0; i< n; i++){ ans=min(ans, max(suf[i], pref[i])); } cout << ans << '\n'; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...