This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int mod=1e9+7;
int a[100001],b[100001];
int n,m;
bool ok(int x)
{
int cur=-1;
int cnt=0;
for(int i=0;i<n;i++)
{
int l=lower_bound(b,b+m,a[i]-x)-b;
int r=upper_bound(b,b+m,a[i]+x)-b-1;
if(max(cur+1,l)<=r)
{
cur=max(cur+1,l);
cnt++;
}
}
return (cnt>=m);
}
int bs()
{
int s=0,e=1e10;
while(s<e)
{
int mid=s+(e-s)/2;
if(ok(mid))
{
e=mid;
}
else
{
s=mid+1;
}
}
return s;
}
signed main()
{
cin>>n>>m;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<m;i++)
{
cin>>b[i];
}
if(n<m)
{
for(int i=0;i<m;i++)
{
swap(a[i],b[i]);
}
swap(n,m);
}
sort(a,a+n);
sort(b,b+m);
cout<<bs()<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |