求助WA on #3
查看原帖
求助WA on #3
794701
wo_hen_la楼主2024/1/13 14:36
#include <iostream>
#include <algorithm>
#include <cmath>
#define int long long
using namespace std;
int a[100005],b[100005];
int n,m;
bool check(int x)
{
	int ta=1,city=1;
	while(1){
		if(abs(b[ta]-a[city])<=x){
			if(++city>n) return 1;
		}
		else if(++ta>m) return 0;
	}
}
main()
{
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=m;i++) cin>>b[i];
	sort(a+1,a+1+n);
	sort(b+1,b+1+m);
	int ans,l=0,r=2e9;
	while(l<r){
		int mid=l+r>>1;
		//cout<<l<<" "<<r<<" "<<mid<<"\n";
		if(check(mid)) ans=mid,r=mid;
		else l=mid+1;
	}
	cout<<ans;
	return 0;
}
2024/1/13 14:36
加载中...