Submission #1110242

# Submission time Handle Problem Language Result Execution time Memory
1110242 2024-11-09T03:11:41 Z vjudge1 Growing Vegetables is Fun 5 (JOI24_vegetables5) C++17
30 / 100
311 ms 41616 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define pb push_back
using namespace std;
int n,a[10005],b[5005],c[5005];
int dp[5005][5005];

int get(int l,int r)
{
	vector<int> vb,vc;
	for(int i=1;i<l;i++) vc.pb(a[i]);
	for(int i=l;i<=r;i++) vb.pb(a[i]);
	for(int i=r+1;i<=2*n;i++) vc.pb(a[i]);
	sort(vc.begin(),vc.end());
	sort(vb.begin(),vb.end());
	
	int mx1=0,mx2=0;
	for(int i=1;i<=n;i++)
	{
		mx1=max(mx1,abs(b[i]-vb[i-1]));
	}
	
	for(int i=1;i<=n;i++)
	{
		mx1=max(mx1,abs(c[i]-vc[i-1]));
	}
	
	for(int i=1;i<=n;i++)
	{
		mx2=max(mx2,abs(c[i]-vb[i-1]));
	}
	
	for(int i=1;i<=n;i++)
	{
		mx2=max(mx2,abs(b[i]-vc[i-1]));
	}
	
	return min(mx2,mx1);
}



bool check(int mid)
{
	for(int i=1;i<=n+1;i++)
	{
		int mx=0;
		mx=dp[i][i+n-1];
		if(mx<=mid) return true;
	}
	return false;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
//	freopen(".INP","r",stdin);
//	freopen(".OUT","w",stdout);
	cin>>n;
	for(int i=1;i<=n*2;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=n;i++)
	{
		cin>>b[i];
	}
	for(int i=1;i<=n;i++)
	{
		cin>>c[i];
	}
	sort(b+1,b+1+n);
	sort(c+1,c+1+n);
	
	for(int i=1;i<=n+1;i++)
	{
		int j=i+n-1;
		dp[i][j]=get(i,j);
	}
	
	int l=0,r=1e9,res=0;
	while(l<=r)
	{
		int mid=(l+r)/2;
		if(check(mid))
		{
			res=mid;
			r=mid-1;
		}
		else l=mid+1;
	}
	cout<<res;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2564 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2384 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 1 ms 2384 KB Output is correct
25 Correct 1 ms 2556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2564 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2384 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 1 ms 2384 KB Output is correct
25 Correct 1 ms 2556 KB Output is correct
26 Correct 183 ms 41548 KB Output is correct
27 Correct 179 ms 41536 KB Output is correct
28 Correct 95 ms 41548 KB Output is correct
29 Correct 1 ms 2384 KB Output is correct
30 Correct 200 ms 41548 KB Output is correct
31 Correct 176 ms 41556 KB Output is correct
32 Correct 37 ms 20808 KB Output is correct
33 Correct 10 ms 10576 KB Output is correct
34 Correct 227 ms 41548 KB Output is correct
35 Correct 191 ms 41552 KB Output is correct
36 Correct 183 ms 41544 KB Output is correct
37 Correct 71 ms 41544 KB Output is correct
38 Correct 91 ms 41552 KB Output is correct
39 Correct 103 ms 41616 KB Output is correct
40 Correct 192 ms 41616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 311 ms 588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2564 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2384 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 1 ms 2384 KB Output is correct
25 Correct 1 ms 2556 KB Output is correct
26 Correct 183 ms 41548 KB Output is correct
27 Correct 179 ms 41536 KB Output is correct
28 Correct 95 ms 41548 KB Output is correct
29 Correct 1 ms 2384 KB Output is correct
30 Correct 200 ms 41548 KB Output is correct
31 Correct 176 ms 41556 KB Output is correct
32 Correct 37 ms 20808 KB Output is correct
33 Correct 10 ms 10576 KB Output is correct
34 Correct 227 ms 41548 KB Output is correct
35 Correct 191 ms 41552 KB Output is correct
36 Correct 183 ms 41544 KB Output is correct
37 Correct 71 ms 41544 KB Output is correct
38 Correct 91 ms 41552 KB Output is correct
39 Correct 103 ms 41616 KB Output is correct
40 Correct 192 ms 41616 KB Output is correct
41 Runtime error 311 ms 588 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -