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;
int n, m;
vector <int> a, b;
int check(int mid) {
int j=0;
for(int i=0; i<n; i++){
while(abs(b[j]-a[i])>mid){
j++;
if (j == m) return false;
}
j++;
}
return true;
}
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);
}
int l=0, r=1e9, ans = -1;
while (l<=r) {
int mid=(l+r)/2;
if (check(mid)) {
ans = mid;
r = mid - 1;
} else l = mid + 1;
}
cout << ans;
}
# | 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... |