Submission #145287

# Submission time Handle Problem Language Result Execution time Memory
145287 2019-08-19T13:42:31 Z Fasho Cipele (COCI18_cipele) C++14
63 / 90
140 ms 3120 KB
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("kmp.in","r",stdin);freopen ("kmp.out","w",stdout);
#define mod 1000000009
#define fs(x,y) for(int i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(int i=x;i<=y;i++)
#define INF 1000000000005
using namespace std;

ll n,m,ar[N],sum,b[N];

ll get(ll l,ll x)
{
	ll r=m;
	while(l<r)
	{
		if(l==r-1)
		{
			if(b[l]>=x)
				r=l;
			break;
		}

		ll mid=(l+r)/2;
		if(b[mid]>=x)
			r=mid;
		else
			l=mid+1;
	}

	return r;
}

bool check(ll x)
{
	ll l=1;
	for(int i=1;i<=n;i++)
	{
		ll y=get(l,ar[i]-x);
		if(y>m || fabs(b[y]-ar[i])>x)
			return 0;
		l=y+1;
	}
	return 1;
}

int main()
{
	fast;
	cin>>n>>m;
	fs(ar,n);
	fs(b,m);
	sort(ar+1,ar+n+1);
	sort(b+1,b+m+1);
	if(m<n)
	{
		fo(i,1,n)
			swap(ar[i],b[i]);
		swap(n,m);
	}
	if(n==m)
	{
		fo(i,1,n)
			sum=max(sum,abs(ar[i]-b[i]));
		return cout<<sum,0;
	}


	ll l=0,r=max(ar[n],b[m])-min(ar[1],b[1]);

	while(l<r)
	{
		if(l==r-1)
		{
			if(check(l))
				r=l;
			break;
		}
		ll mid=(l+r)/2;
		if(check(mid))
			r=mid;
		else
			l=mid+1;
		
	}

	// cout<<endl;
	cout<<r<<endl;

	// cout<<endl;
	// cout<<endl;

	// fo(i,1,n)
	// 	cout<<ar[i]<<sp;
	// cout<<endl;
	// fo(i,1,m)
	// 	cout<<b[i]<<sp;

	// cout<<endl;

	// cout<<endl<<check(1)<<endl;



}



/*     cd onedrive\desktop\kod
cls


*/
# Verdict Execution time Memory Grader output
1 Correct 31 ms 3064 KB Output is correct
2 Correct 48 ms 3064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 3116 KB Output is correct
2 Correct 51 ms 3120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 8 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 8 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 8 ms 608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 8 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 118 ms 2956 KB Output is correct
2 Correct 91 ms 2456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 140 ms 3060 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 117 ms 2936 KB Output is correct
2 Incorrect 136 ms 3012 KB Output isn't correct