#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 |
1 |
Correct |
92 ms |
2680 KB |
Output is correct |
2 |
Correct |
112 ms |
4464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
6408 KB |
Output is correct |
2 |
Correct |
113 ms |
7952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7952 KB |
Output is correct |
2 |
Correct |
8 ms |
7952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7952 KB |
Output is correct |
2 |
Correct |
9 ms |
7952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7952 KB |
Output is correct |
2 |
Correct |
8 ms |
7952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
7952 KB |
Output is correct |
2 |
Correct |
8 ms |
7952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7952 KB |
Output is correct |
2 |
Correct |
9 ms |
7952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
7952 KB |
Output is correct |
2 |
Correct |
65 ms |
7952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
8428 KB |
Output is correct |
2 |
Correct |
66 ms |
9404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
10784 KB |
Output is correct |
2 |
Correct |
96 ms |
12296 KB |
Output is correct |