제출 #1120433

#제출 시각아이디문제언어결과실행 시간메모리
1120433LuvidiGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
36 ms8664 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #define fs first #define sc second #define pb push_back void solve(){ int n; cin>>n; ll a[n+1],d[n+1]; for(int i=0;i<n;i++)cin>>a[i]; a[n]=0; d[0]=a[0]; for(int i=1;i<=n;i++)d[i]=a[i]-a[i-1]; ll pre[n],suf[n]; for(int i=0;i<=n;i++){ pre[i]=max(0LL,1-d[i]); if(i)pre[i]+=pre[i-1]; } for(int i=n;i>-1;i--){ suf[i]=max(0LL,d[i]+1); if(i<n)suf[i]+=suf[i+1]; } ll ans=1e18; for(int i=0;i<n;i++)ans=min(ans,max(pre[i],suf[i+1])); cout<<ans<<'\n'; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...