#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
ifstream fin("input.txt");
ofstream fout("output.txt");
#else
#define fin cin
#define fout cout
#endif
const int INF = 0x3f3f3f3f;
const int LIM = 1e9;
int tc, testCases = 1;
int N, M;
vector<int> L, R;
bool check(int diff) {
int i = 0, j = 0;
while(i < N && j < M) {
if(abs(L[i] - R[j]) <= diff) {
i++;
}
j++;
}
return i == N;
}
void solve() {
fin >> N >> M;
L = vector<int> (N);
R = vector<int> (M);
for(int &it: L) {
fin >> it;
}
for(int &it: R) {
fin >> it;
}
if(N > M) {
swap(N, M);
L.swap(R);
}
sort(L.begin(), L.end());
sort(R.begin(), R.end());
int st = 0, dr = LIM, mid, ans = -1;
while(st <= dr) {
mid = (st + dr) >> 1;
if(check(mid)) {
ans = mid;
dr = mid - 1;
} else {
st = mid + 1;
}
}
fout << ans << '\n';
}
signed main() {
ios_base :: sync_with_stdio(false); fin.tie(0); fout.tie(0);
// fin >> testCases;
for(tc = 0; tc < testCases; tc++) {
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
1108 KB |
Output is correct |
2 |
Correct |
46 ms |
1564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
1108 KB |
Output is correct |
2 |
Correct |
45 ms |
1576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
3 ms |
436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
948 KB |
Output is correct |
2 |
Correct |
28 ms |
1796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
980 KB |
Output is correct |
2 |
Correct |
23 ms |
1912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
936 KB |
Output is correct |
2 |
Correct |
42 ms |
2384 KB |
Output is correct |