Submission #370943

# Submission time Handle Problem Language Result Execution time Memory
370943 2021-02-25T06:27:15 Z kshitij_sodani Growing Vegetables is Fun 4 (JOI21_ho_t1) C++14
100 / 100
41 ms 5120 KB
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
#define endl '\n'
llo n;
llo it[200001];
llo pre[200001];
llo pre2[200001];
llo cur[200001];

llo cur2[200001];

/*llo ans=0;
void solve(llo l,llo r){
	if(l==r){
		return ;
	}
	if(it[l]<=it[r]){
		llo mi=it[l+1];
		for(llo i=l+1;i<=r;i++){
			mi=min(mi,it[i]);
		}
		if(mi<=it[l]){
			for(llo i=l+1;i<=r;i++){
				it[i]+=it[l]-mi+1;
			}
			ans+=it[l]-mi+1;
		}
		solve(l+1,r);
	}
	else{
		llo mi=it[l];
		for(llo i=l;i<r;i++){
			mi=min(mi,it[i]);
		}
		if(mi<=it[r]){
			for(llo i=l;i<r;i++){
				it[i]+=it[r]-mi+1;
			}
			ans+=it[r]-mi+1;
		}
		solve(l,r-1);

	}
}*/
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	for(llo i=0;i<n;i++){
		cin>>it[i];
	}
	//solve(0,n-1);
	//llo ma=it[0];
	//cur[0]=it[0];
	for(int i=1;i<n;i++){
		pre[i]=pre[i-1];
		if(it[i]<=it[i-1]){
			pre[i]+=(it[i-1]-it[i]+1);
			//cur[i]=cur[i-1]+it[i];
		}
		else{
			//cur[i]=it[i];
		}
	}
	cur2[n-1]=it[0];
	for(int i=n-2;i>=0;i--){
		pre2[i]=pre2[i+1];
		if(it[i]<=it[i+1]){
			pre2[i]+=(it[i+1]-it[i]+1);
		//	cur2[i]=cur2[i+1]+1;
		}
		else{
			//cur2[i]=it[i];
		}
	}
	llo ans=1e18;
	for(int i=0;i<n;i++){
	//	cout<<pre[i]<<":"<<pre2[i]<<endl;
		ans=min(ans,max(pre[i],pre2[i]));
	}
	cout<<ans<<endl;


/*	llo ma=0;
	for(llo i=1;i<n;i++){
		ma=max(ma,it[i-1]);
		pre[i]=pre[i-1];
		if(it[i]<=ma){
			pre[i]+=ma-it[i]+1;
		}
	}
	ma=0;
	for(llo i=n-2;i>=0;i--){
		ma=max(ma,it[i+1]);
		pre2[i]=pre2[i+1];
		if(it[i]<=ma){
			pre2[i]+=ma-it[i]+1;

		}
	}
	llo ans=pre[0]+pre2[0];
	for(llo i=0;i<n;i++){
		ans=min(ans,pre[i]+pre2[i]);

	}*/


	//cout<<ans<<endl;





 
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 41 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 41 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 34 ms 5100 KB Output is correct
27 Correct 27 ms 5100 KB Output is correct
28 Correct 26 ms 5100 KB Output is correct
29 Correct 27 ms 5100 KB Output is correct
30 Correct 24 ms 5100 KB Output is correct
31 Correct 26 ms 5100 KB Output is correct
32 Correct 26 ms 5120 KB Output is correct
33 Correct 26 ms 5100 KB Output is correct
34 Correct 25 ms 5100 KB Output is correct
35 Correct 21 ms 5100 KB Output is correct
36 Correct 23 ms 5100 KB Output is correct
37 Correct 21 ms 5100 KB Output is correct
38 Correct 26 ms 5100 KB Output is correct
39 Correct 26 ms 5100 KB Output is correct
40 Correct 26 ms 5100 KB Output is correct
41 Correct 26 ms 5100 KB Output is correct
42 Correct 25 ms 5100 KB Output is correct
43 Correct 26 ms 5100 KB Output is correct
44 Correct 26 ms 5100 KB Output is correct
45 Correct 26 ms 5100 KB Output is correct
46 Correct 26 ms 5100 KB Output is correct
47 Correct 26 ms 5100 KB Output is correct
48 Correct 26 ms 5100 KB Output is correct