#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];
}
sort(A,A+n);
sort(B,B+m);
cout<<binarySearch()<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
2688 KB |
Output is correct |
2 |
Correct |
52 ms |
2936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
2936 KB |
Output is correct |
2 |
Correct |
52 ms |
2936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
7 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
7 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
384 KB |
Output is correct |
2 |
Correct |
7 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
8 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
7 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
2552 KB |
Output is correct |
2 |
Execution timed out |
1086 ms |
1792 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
2688 KB |
Output is correct |
2 |
Execution timed out |
1087 ms |
2048 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
2432 KB |
Output is correct |
2 |
Execution timed out |
1093 ms |
2560 KB |
Time limit exceeded |