#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define F first
#define S second
#define f(i,a,b) for(int i = a; i < b; i++)
#define endl '\n'
using ll = long long;
using db = long double;
using ii = pair<int, int>;
const int N = 1e5 + 5, LG = 19, MOD = 1e9 + 7;
const int SQ =320;
const long double EPS = 1e-7;
int n, m;
vector<int> a, b;
bool check(int limit){
for(int i = 0, j = 0; i < n; i++){
while(j < m && a[i] - b[j] > limit)j++;
if(j == m || b[j] - a[i] > limit)
return false;
j++;
}
return true;
}
int32_t main(){
#ifdef ONLINE_JUDGE
ios_base::sync_with_stdio(0);
cin.tie(0);
#endif
cin >> n >> m;
a.resize(n); b.resize(m);
f(i,0,n)
cin >> a[i];
f(i,0,m)
cin >> b[i];
sort(a.begin(),a.end());
sort(b.begin(),b.end());
if(n > m){
swap(n, m);
swap(a, b);
}
int lo = 0, hi = 1000 * 1000 * 1000;
while(lo < hi){
int md = lo + (hi - lo) / 2;
if(check(md))
hi = md;
else
lo = md + 1;
}
cout << lo << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
2680 KB |
Output is correct |
2 |
Correct |
153 ms |
2968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
162 ms |
2936 KB |
Output is correct |
2 |
Correct |
162 ms |
3032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
476 KB |
Output is correct |
2 |
Correct |
11 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
11 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Output is correct |
2 |
Correct |
10 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
376 KB |
Output is correct |
2 |
Correct |
11 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
376 KB |
Output is correct |
2 |
Correct |
11 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
143 ms |
2396 KB |
Output is correct |
2 |
Correct |
97 ms |
1996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
149 ms |
2660 KB |
Output is correct |
2 |
Correct |
101 ms |
2168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
2396 KB |
Output is correct |
2 |
Correct |
139 ms |
2572 KB |
Output is correct |