#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 |
1 |
Correct |
31 ms |
2688 KB |
Output is correct |
2 |
Correct |
48 ms |
2940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
2944 KB |
Output is correct |
2 |
Correct |
45 ms |
2936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
2432 KB |
Output is correct |
2 |
Correct |
30 ms |
1792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
2680 KB |
Output is correct |
2 |
Correct |
24 ms |
2176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
2432 KB |
Output is correct |
2 |
Correct |
38 ms |
2560 KB |
Output is correct |