Submission #145292

# Submission time Handle Problem Language Result Execution time Memory
145292 2019-08-19T14:10:05 Z Fasho Cipele (COCI18_cipele) C++14
90 / 90
54 ms 3256 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];

bool check(ll x)
{
	ll l=1;
	for(int i=1;i<=n;i++)
	{
		while(fabs(ar[i]-b[l])>x && l<=m)
			l++;

		if(l>m || fabs(b[l]-ar[i])>x)
			return 0;
		l++;
	}
	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<<r<<endl;
}



/*     cd onedrive\desktop\kod
cls


*/
# Verdict Execution time Memory Grader output
1 Correct 31 ms 2296 KB Output is correct
2 Correct 47 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 2308 KB Output is correct
2 Correct 49 ms 2268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 1784 KB Output is correct
2 Correct 34 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 1968 KB Output is correct
2 Correct 27 ms 2848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 1752 KB Output is correct
2 Correct 48 ms 3256 KB Output is correct