#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
int n, m, a[100000], b[100000];
bool ok(int x) {
int c = 0;
for (int i = 0, j = 0; i < n; ++i) {
while(j < m && b[j] + x < a[i])
++j;
if (j == m)
break;
if (a[i] + x >= b[j])
++c, ++j;
}
return c == min(n, m);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; ++i)
cin >> a[i];
for (int i = 0; i < m; ++i)
cin >> b[i];
sort(a, a + n);
sort(b, b + m);
int l = 0, r = 1e9;
while(l < r) {
int mid = (l + r) / 2;
if (ok(mid))
r = mid;
else
l = mid + 1;
}
cout << l;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
2668 KB |
Output is correct |
2 |
Correct |
47 ms |
2924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
3072 KB |
Output is correct |
2 |
Correct |
46 ms |
2924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
5 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
4 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
364 KB |
Output is correct |
2 |
Correct |
4 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
492 KB |
Output is correct |
2 |
Correct |
4 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
2412 KB |
Output is correct |
2 |
Correct |
28 ms |
1772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
2668 KB |
Output is correct |
2 |
Correct |
22 ms |
2028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
2540 KB |
Output is correct |
2 |
Correct |
39 ms |
2540 KB |
Output is correct |