#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5;
int n, m;
vector<ll> L, R;
bool works(ll x){
int cnt = 0;
for(int i = 0; i < m; i ++){
if(cnt >= n){
return true;
}
if(llabs(R[i] - L[cnt]) > x){
continue;
}
cnt ++;
}
return (cnt >= n);
}
int main() {
cin >> n >> m;
ll num;
for(int i = 0; i < n; i ++){
cin >> num;
L.push_back(num);
}
for(int i = 0; i < m; i ++){
cin >> num;
R.push_back(num);
}
if(n > m){
swap(L, R);
}
n = (int)L.size();
m = (int)R.size();
sort(L.begin(), L.end());
sort(R.begin(), R.end());
ll lo = 0, hi = (1LL << 40LL);
ll ans = -1;
while(lo <= hi){
ll mid = lo + ((hi - lo) / 2LL);
if(works(mid)){
hi = mid -1;
ans = mid;
}
else{
lo = mid +1;
}
}
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
4032 KB |
Output is correct |
2 |
Correct |
101 ms |
4216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
4232 KB |
Output is correct |
2 |
Correct |
100 ms |
4212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
6 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
468 KB |
Output is correct |
2 |
Correct |
7 ms |
676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
400 KB |
Output is correct |
2 |
Correct |
6 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
408 KB |
Output is correct |
2 |
Correct |
6 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
3700 KB |
Output is correct |
2 |
Correct |
58 ms |
2544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
3888 KB |
Output is correct |
2 |
Correct |
63 ms |
3020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
3748 KB |
Output is correct |
2 |
Correct |
86 ms |
4020 KB |
Output is correct |