제출 #387495

#제출 시각아이디문제언어결과실행 시간메모리
387495wildturtleGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
93 ms8684 KiB
#include<bits/stdc++.h> #define ll long long using namespace std; ll a,b,c,d,i,e,f,g,n,m,k,l,A[500005],B[500005],pre[500005],suf[500005],ans,minn; int main() { cin>>n; for(ll i=1;i<=n;i++) { cin>>A[i]; } for(ll i=1;i<=n;i++) { if(i!=n) B[i]=A[i+1]-A[i]; } for(ll i=1;i<n;i++) { pre[i]=pre[i-1]; if(B[i]<=0) pre[i]+=abs(B[i])+1; } for(ll i=n-1;i>=1;i--) { suf[i]=suf[i+1]; if(B[i]>=0) suf[i]+=B[i]+1; //cout<<B[i]<<"_"<<suf[i]<<" "; } //cout<<endl; minn=1e18; for(ll i=1;i<=n;i++) { ans=max(pre[i-1],suf[i]); //cout<<pre[i-2]<<"_"<<suf[i+1]<<"_"<<ans<<" "; minn=min(minn,ans); } cout<<minn; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...