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>
#define PB push_back
#define ST first
#define ND second
#define _ ios_base::sync_with_stdio(0); cin.tie(0);
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
using namespace std;
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
const int nax = 100 * 1000 + 10, INF = 1e9 + 10;
int n, m;
vi a, b;
bool check(int x) {
int ptr = 0;
for(int i = 0; i < n; ++i) {
while(ptr < m && a[i] - b[ptr] > x) {
ptr++;
}
if(ptr < m && abs(a[i] - b[ptr]) <= x) {
ptr++;
} else {
return false;
}
}
return true;
}
int main() {_
cin >> n >> m;
a.resize(n); b.resize(m);
for(int i = 0; i < n; ++i) cin >> a[i];
for(int i = 0; i < m; ++i) cin >> b[i];
if(n > m) {
swap(n, m);
a.swap(b);
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int low = 0, high = INF, mid;
while(low <= high) {
mid = (low + high) / 2;
if(check(mid)) high = mid - 1;
else low = mid + 1;
}
cout << high + 1;
}
# | 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... |