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>
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
const int N = 100000 + 3;
int n, m, l[N], r[N];
bool can(int mid){
int j = 0;
for (int i = 0; i < n; i++){
while (abs(l[i] - r[j]) > mid && j < m) j++;
if (j == m) return false;
++j;
}
return true;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif // LOCAL
cin >> n >> m;
for (int i = 0; i < n; i++){
cin >> l[i];
}
for (int i = 0; i < m; i++){
cin >> r[i];
}
if (n > m){
for(int i = 0; i < n; i++) swap(l[i], r[i]);
swap(n, m);
}
sort(l, l + n);
sort(r, r + m);
if (can(0)){
cout << 0;
return 0;
}
// cout << (bool)can(4) << "!\n";
int L = 0, R = inf;
while (L < R){
int mid = (L + R) / 2;
if (can(mid)) R = mid;
else L = mid + 1;
}
cout << R;
}
# | 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... |