제출 #1218300

#제출 시각아이디문제언어결과실행 시간메모리
1218300jellybeanGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
40 / 100
1093 ms1860 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define dd(x) cout<<#x<<" is "<<x<<endl;
typedef pair<int,int> pii;


signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n; cin>>n;
	int a[n+2]= {};
	for(int i=1; i<=n; i++) cin>>a[i];
	
	int ans = LLONG_MAX;
	for(int k=1; k<=n; k++){ //k is the tallest guy
		int x=0, y=0;
		for(int i=1; i<=k; i++){
			if(a[i] <= a[i-1]) x+= (a[i-1]-a[i]+1);
		}
		for(int i=k; i<=n; i++){
			if(a[i] <= a[i+1]) y+= (a[i+1]-a[i]+1);
		}
		ans = min(ans,max(x,y));
	}
	cout<<ans;
	
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...