제출 #960896

#제출 시각아이디문제언어결과실행 시간메모리
960896happy_nodeGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h>
using namespace std;

const int MX=2e5+5;
int N;
int 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;
	}
	int 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...