#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n + 1);
vector<int> b(m + 1);
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
for(int i = 1; i <= m; i++) {
cin >> b[i];
}
sort(a.begin() + 1, a.end());
sort(b.begin() + 1, b.end());
if(n == m) {
int ans = 0;
for(int i = 1; i <= n; i++) {
ans = max(ans, abs(a[i] - b[i]));
}
cout << ans;
return 0;
}
if(n < m) {
swap(a, b);
swap(n, m);
}
int ans = 1e18;
int k = n - m;
for(int i = 1; i + k - 1 <= n; i++) {
int e1 = 1;
int e2 = 1;
int current = 0;
while(e1 <= n && e2 <= m) {
if(e1 >= i && e1 <= i + k - 1) {
e1 += 1;
continue;
}
current = max(current, abs(a[e1++] - b[e2++]));
}
ans = min(ans, current);
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |