제출 #949624

#제출 시각아이디문제언어결과실행 시간메모리
949624amirhoseinfar1385Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
23 ms8076 KiB
#include<bits/stdc++.h> using namespace std; const long long maxn=200000+10; long long n,all[maxn]; long long ps[maxn],suf[maxn],dpps[maxn],dpsuf[maxn]; void vorod(){ cin>>n; for(long long i=1;i<=n;i++){ cin>>all[i]; } } void pre(){ for(long long i=1;i<=n;i++){ ps[i]=ps[i-1]; ps[i]+=max(0ll,all[i-1]-all[i]+1); } for(long long i=n;i>=1;i--){ suf[i]=suf[i+1]; suf[i]+=max(0ll,all[i+1]-all[i]+1); } } void solve(){ long long res=1e15; for(long long i=1;i<=n;i++){ //cout<<i<<" "<<ps[i]<<" "<<suf[i]<<endl; long long fres=max(ps[i],suf[i]); res=min(res,fres); } cout<<res<<"\n"; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("inp.txt","r",stdin); vorod(); pre(); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...