#include <bits/stdc++.h>
using namespace std;
long long n,m,s=0;
vector<long long> a,b;
long long f(long long x)
{
long long now=0;
for(int i=0;i<n;i++)
{
long long g=lower_bound(b.begin()+now,b.end(),a[i]-x)-b.begin();
if(g==m)return 0;
if(b[g]>a[i])
{
if(b[g]-a[i]>x)
{
return 0;
}
}
now=g+1;
}
return 1;
}
int main()
{
cin>>n>>m;
a.resize(n);
b.resize(m);
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<m;i++)
{
cin>>b[i];
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
if(n>m)
{
swap(n,m);
swap(a,b);
}
long long l=0,r=1e18;
for(int i=0;i<100;i++)
{
long long mid=(l+r)/2;
if(f(mid))
{
r=mid;
}
else
{l=mid;
}
}
cout<<r<<endl;
/*for(auto i:b)
{
cout<<i<<endl;
}*/
// cout<<s<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
212 ms |
3400 KB |
Output is correct |
2 |
Correct |
315 ms |
3652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
291 ms |
3648 KB |
Output is correct |
2 |
Correct |
302 ms |
3644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
332 KB |
Output is correct |
2 |
Correct |
12 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
332 KB |
Output is correct |
2 |
Correct |
12 ms |
428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
404 KB |
Output is correct |
2 |
Correct |
12 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
332 KB |
Output is correct |
2 |
Correct |
14 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
332 KB |
Output is correct |
2 |
Correct |
16 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
217 ms |
3012 KB |
Output is correct |
2 |
Correct |
162 ms |
2212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
252 ms |
3268 KB |
Output is correct |
2 |
Correct |
146 ms |
2500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
219 ms |
3064 KB |
Output is correct |
2 |
Correct |
246 ms |
3136 KB |
Output is correct |