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;
///Binary Search The Answer
int n,m;
int A[100005];
int B[100005];
bool possible(int maxDiff) ///Returns whether is possible to match shoes with at most maxDiff ugliness
{
int j=0;
for(int i=0;i<n;i++){
while(j<m && abs(A[i]-B[j]) > maxDiff)
j++;
if(j==m)
return false; //We have no more shoes to match
j++;
}
return true; //Shoes matched successfully
}
int binarySearch() ///Return the first moment when is possible
{
int k=-1;
for(int b=1000000007;b>=1;b/=2){
while(!possible(k+b)) k+=b;
}
return k+1;
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
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){
swap(n,m);
swap(A,B);
}
sort(A,A+n);
sort(B,B+m);
cout<<binarySearch()<<'\n';
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... |