// This code is written by _L__
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update>;
#define endl '\n'
#define F_word ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
typedef long long ll;
typedef long double ld;
const ll mod = 1e9+7, N = 1e5+300, inf = 1e18;
const ld E = 1e-6;
#define ff first
#define ss second
ll a[N], b[N], n, m;
bool check(ll mid){
ll cur = -1;
ll cnt = 0;
for(int i = 0; i < n; ++i){
ll l = lower_bound(b, b+m, a[i]-mid)-b;
ll r = upper_bound(b, b+m, a[i]+mid)-b-1;
if(l > r) return 0;
if(cur+1 <= r){cnt++; cur = max(cur+1, l);}
}
return (cnt >= m);
}
ll lower(){
ll l = 0, r = 1e11;
ll ans = 0;
while(l <= r){
ll mid = (l+r)/2;
if(check(mid)){
r = mid-1;
ans = mid;
} else l = mid+1;
}
return ans;
}
int main(void){
F_word;
cin >> n >> m;
for(int i = 0; i < n; ++i) cin >> a[i];
for(int i = 0; i < m; ++i) cin >> b[i];
if(n > m){
for(int i = 0; i < n; ++i) swap(a[i], b[i]);
swap(n,m);
}
sort(a, a+n); sort(b, b+m);
cout << lower() << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
312 ms |
1924 KB |
Output is correct |
2 |
Correct |
333 ms |
1864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
373 ms |
1864 KB |
Output is correct |
2 |
Correct |
333 ms |
1868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
332 KB |
Output is correct |
2 |
Incorrect |
8 ms |
332 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
133 ms |
1576 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
159 ms |
1692 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
139 ms |
1564 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |