제출 #644916

#제출 시각아이디문제언어결과실행 시간메모리
644916kdn5549Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
25 ms6944 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pi; typedef pair<ll,ll> pl; #define eb emplace_back #define all(v) v.begin(),v.end() #define ff first #define ss second const ll mxn=2e5+5; ll a[mxn],l[mxn],r[mxn]; int main() { ios::sync_with_stdio(0); cin.tie(0); ll n; cin>>n; for (int i=1;i<=n;i++) cin>>a[i]; for (int i=1;i<=n;i++) l[i]=l[i-1]+max(a[i-1]-a[i]+1,0ll); for (int i=n;i>=1;i--) r[i]=r[i+1]+max(a[i+1]-a[i]+1,0ll); ll rt=LLONG_MAX; for (int i=1;i<=n;i++) rt=min(rt,max(l[i],r[i])); cout<<rt; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...