#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define all(x) begin(x), end(x)
#define x first
#define y second
typedef long long ll;
typedef long double ld;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using normal_queue = priority_queue<T, vector<T>, greater<T>>;
const int MAX_N = 1e5 + 10;
int a[MAX_N], b[MAX_N];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
int *ca = a, *cb = b;
if (n > m)
swap(ca, cb);
for (int i = 0; i < n; ++i)
cin >> ca[i];
for (int i = 0; i < m; ++i)
cin >> cb[i];
if (n > m)
swap(n, m);
sort(a, a + n);
sort(b, b + m);
int l = -1, r = 1e9 + 1;
while (r - l > 1) {
int mid = (l + r) / 2;
int ptr = 0;
bool flag = 0;
for (int i = 0; i < n; ++i) {
while (ptr < m && abs(a[i] - b[ptr]) > mid)
++ptr;
if (ptr >= m) {
flag = 1;
break;
}
++ptr;
}
if (flag)
l = mid;
else
r = mid;
}
cout << r << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
1144 KB |
Output is correct |
2 |
Correct |
50 ms |
1016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
1152 KB |
Output is correct |
2 |
Correct |
50 ms |
1256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 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 |
6 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 |
512 KB |
Output is correct |
2 |
Correct |
7 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
1144 KB |
Output is correct |
2 |
Correct |
37 ms |
1792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
1024 KB |
Output is correct |
2 |
Correct |
27 ms |
2048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
1016 KB |
Output is correct |
2 |
Correct |
44 ms |
2552 KB |
Output is correct |