This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 998244353;
const ll LOGN = 18;
const ll INF = 1e15;
const ll MAXN = 3e5 + 5;
int N, M;
vector<int> A, B;
bool check(int x) {
int ptr = 0;
for (int i = 0; i < N; i++) {
while (abs(A[i] - B[ptr]) > x) {
ptr++;
if (ptr == M)
return false;
}
ptr++;
}
return true;
}
int main() {
fast
cin >> N >> M;
A = vector<int>(N);
B = vector<int>(M);
for (int i = 0; i < N; i++)
cin >> A[i];
for (int i = 0; i < M; i++)
cin >> B[i];
sort(A.begin(), A.end());
sort(B.begin(), B.end());
if (N > M) {
swap(N, M);
swap(A, B);
}
int L = 0;
int R = 1e9;
int ans = -1;
while (R >= L) {
int mid = L + (R-L)/2;
if (check(mid)) {
ans = mid;
R = mid - 1;
} else
L = mid + 1;
}
cout << ans << "\n";
}
# | 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... |