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 <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
using namespace std;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
typedef long long ll;
typedef long double ld;
ll n, m;
vector<ll> vec1, vec2;
const ll INF = 1'000'000'100;
bool check(int val) {
multiset<ll> st;
for (auto c : vec2) st.insert(c);
sort(vec1.begin(), vec1.end());
for (auto c : vec1) {
while (true) {
if (st.empty()) return 0;
ll v = (*st.begin());
st.erase(st.begin());
if (abs(c - v) > val) continue;
break;
}
}
return 1;
}
int main() {
fastInp;
cin >> n >> m;
vec1.resize(n);
vec2.resize(m);
for (auto &c : vec1) cin >> c;
for (auto &c : vec2) cin >> c;
if (n > m) {
swap(n, m);
swap(vec1, vec2);
}
int l = -1, r = INF;
while (r - l > 1) {
ll mid = (ll(l) + r) / 2;
if (check(mid)) {
r = mid;
} else {
l = mid;
}
}
cout << r;
return 0;
}
# | 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... |