This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//author: Ahmet Alp Orakci
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define ONLINE_JUDGE
void solve() {
int n, m;
cin >> n >> m;
vector <int> a(n +1), b(m +1);
for(int i = 1; i <= n; i++)
cin >> a[i];
for(int j = 1; j <= m; j++)
cin >> b[j];
if(n > m) {
swap(a, b);
swap(n, m);
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
auto check = [&](int c) -> bool {
int ind = 1;
//cerr << c << ": \n";
for(int i = 1; i <= n; i++) {
while(ind <= m && abs(a[i] - b[ind]) > c)
ind++;
if(ind == m +1) {
return false;
}
//cerr << a[i] << " " << b[ind] << "\n";
ind++;
}
return true;
};
int l = 0, r = 1E9, ans = 0;
while(l <= r) {
int mid = (l + r) / 2;
if(check(mid)) {
ans = mid;
r = mid -1;
} else {
l = mid +1;
}
cerr << "\n";
}
cout << ans << "\n";
return;
}
signed main() {
#ifndef ONLINE_JUDGE
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t = 1; //cin >> t;
for(int i = 1; i <= t; i++) {
solve();
}
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... |