Submission #703177

# Submission time Handle Problem Language Result Execution time Memory
703177 2023-02-26T12:44:26 Z ld_minh4354 Growing Vegetables is Fun 4 (JOI21_ho_t1) C++17
100 / 100
27 ms 6948 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define pb push_back
#define debug(x) cout<<#x<<": "<<x<<"\n"



signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//	freopen("input.000","r",stdin);
//	freopen("output.000","w",stdout);
//	srand((unsigned)time(NULL));
//	rand()
	
	int n,i,a[200005],l[200005],r[200005],ans;
	
	cin>>n;
	for (i=1;i<n+1;i++) cin>>a[i];
	
	l[1]=0;
	for (i=2;i<n+1;i++) l[i]=max(0ll, a[i-1]-a[i]+1);
	for (i=3;i<n+1;i++) l[i] += l[i-1];
	
	r[n]=0;
	for (i=n-1;i>0;i--) r[i]=max(0ll, a[i+1]-a[i]+1);
	for (i=n-2;i>0;i--) r[i] += r[i+1];
	
	ans=1e18;
	for (i=1;i<n+1;i++) ans=min(ans,max(l[i],r[i]));
	
	cout<<ans;
}

# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 5012 KB Output is correct
3 Correct 2 ms 5012 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 5024 KB Output is correct
6 Correct 2 ms 5024 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 5020 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 4 ms 5028 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5020 KB Output is correct
16 Correct 3 ms 5020 KB Output is correct
17 Correct 3 ms 5020 KB Output is correct
18 Correct 4 ms 5024 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 5020 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 5012 KB Output is correct
3 Correct 2 ms 5012 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 5024 KB Output is correct
6 Correct 2 ms 5024 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 5020 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 4 ms 5028 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5020 KB Output is correct
16 Correct 3 ms 5020 KB Output is correct
17 Correct 3 ms 5020 KB Output is correct
18 Correct 4 ms 5024 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 5020 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 23 ms 6896 KB Output is correct
27 Correct 24 ms 6896 KB Output is correct
28 Correct 25 ms 6896 KB Output is correct
29 Correct 25 ms 6912 KB Output is correct
30 Correct 23 ms 6348 KB Output is correct
31 Correct 23 ms 6908 KB Output is correct
32 Correct 22 ms 6908 KB Output is correct
33 Correct 22 ms 6896 KB Output is correct
34 Correct 22 ms 6908 KB Output is correct
35 Correct 19 ms 6044 KB Output is correct
36 Correct 19 ms 6264 KB Output is correct
37 Correct 18 ms 6272 KB Output is correct
38 Correct 22 ms 6916 KB Output is correct
39 Correct 21 ms 6904 KB Output is correct
40 Correct 23 ms 6900 KB Output is correct
41 Correct 23 ms 6900 KB Output is correct
42 Correct 21 ms 6644 KB Output is correct
43 Correct 27 ms 6908 KB Output is correct
44 Correct 24 ms 6776 KB Output is correct
45 Correct 21 ms 6896 KB Output is correct
46 Correct 21 ms 6948 KB Output is correct
47 Correct 23 ms 6896 KB Output is correct
48 Correct 24 ms 6860 KB Output is correct