제출 #960898

#제출 시각아이디문제언어결과실행 시간메모리
960898happy_nodeGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
21 ms9068 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MX=2e5+5; int N; ll A[MX], B[MX], C[MX], pf[MX], sf[MX]; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin>>N; for(int i=1;i<=N;i++) { cin>>A[i]; B[i]=A[i]-A[i-1]; } B[N+1]=A[N+1]-A[N]; for(int i=1;i<=N+1;i++) { pf[i]+=pf[i-1]; if(B[i]<=0) pf[i]+=1-B[i]; } for(int i=N;i>=1;i--) { sf[i]+=sf[i+1]; if(B[i+1]>=0) sf[i]+=B[i+1]+1; } ll ans=pf[N]; for(int i=1;i<=N;i++) { ans=min(ans,max(pf[i],sf[i])); } cout<<ans<<'\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...