#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
vector<int> a, b;
int n, m;
int ans = 0;
bool ok(int t) {
int j = 0;
ans = 0;
for (int i = 0; i < n; i++)
{
while (j < m && abs(a[i] - b[j]) > t)
j++;
if (j == m)
return false;
ans += abs(a[i] - b[j]);
j++;
}
return true;
}
int main() {
// int n, m;
cin >> n >> m;
a.resize(n);
b.resize(m);
//vector<int> a(n), b(m);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < m; ++i) {
cin >> b[i];
}
if (n > m) {
swap(n, m);
swap(a, b);
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int tl = -1, tr = 1e9;
while (tl < tr - 1) {
int tm = (tl + tr) >> 1;
if (!ok(tm)) {
tl = tm;
}
else tr = tm;
}
ok(tr);
cout << tr;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
2924 KB |
Output is correct |
2 |
Correct |
100 ms |
2924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
2924 KB |
Output is correct |
2 |
Correct |
105 ms |
3052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
364 KB |
Output is correct |
2 |
Correct |
6 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
364 KB |
Output is correct |
2 |
Correct |
6 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
492 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
364 KB |
Output is correct |
2 |
Correct |
6 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
364 KB |
Output is correct |
2 |
Correct |
6 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
2412 KB |
Output is correct |
2 |
Correct |
59 ms |
1772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
93 ms |
2668 KB |
Output is correct |
2 |
Correct |
65 ms |
2100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
2424 KB |
Output is correct |
2 |
Correct |
89 ms |
2540 KB |
Output is correct |