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>
#define mid (l+r)/2
using namespace std;
const int N=1e5+55;
int a[N];
int b[N];
int n,m;
bool ok(int x)
{
int j=0,i=0;
if(n<m)
{
for(j=0,i=0;i<n;i++,j++)
{
while(abs(a[i]-b[j])>x&&j<m)
{
j++;
}
if(j==m)
return 0;
}
return (i==n);
}
else
{
for(j=0,i=0;j<m;i++,j++)
{
while(abs(a[i]-b[j])>x&&i<n)
{
i++;
}
if(i==n)
return 0;
}
return (j==m);
}
}
int main()
{
cin>>n>>m;
for(int i=0;i<n;i++)
cin>>a[i];
for(int j=0;j<m;j++)
cin>>b[j];
sort(a,a+n);
sort(b,b+m);
int l=0,r=1e9+55;
while(l<r)
{
if(ok(mid))
r=mid;
else
l=mid+1;
}
cout<<l<<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... |