#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> A1, A2;
int N, M;
bool ok(ll mid) {
int j = 0;
for (int i = 0; i < M; i++) {
if (abs(A2[i] - A1[j]) <= mid)
j++;
if (j == N)
return 1;
}
return 0;
}
void solve() {
cin >> N >> M;
A1.resize(N); A2.resize(M);
for (auto& a : A1) cin >> a;
for (auto& a : A2) cin >> a;
sort(A1.begin(), A1.end());
sort(A2.begin(), A2.end());
if (N > M) {
swap(N, M);
swap(A1, A2);
}
ll l = 0, r = 1e10, mid;
while(l < r) {
mid = (l+r)>>1;
if (ok(mid)) r = mid;
else l = mid+1;
}
cout << r << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
1100 KB |
Output is correct |
2 |
Correct |
60 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
1100 KB |
Output is correct |
2 |
Correct |
61 ms |
2888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
844 KB |
Output is correct |
2 |
Correct |
36 ms |
1792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
972 KB |
Output is correct |
2 |
Correct |
31 ms |
2012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
844 KB |
Output is correct |
2 |
Correct |
51 ms |
2508 KB |
Output is correct |