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 Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
int main()
{
cin.tie(0) -> sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<ll> a(n), b(m);
Loop (i,0,n)
cin >> a[i];
Loop (i,0,m)
cin >> b[i];
sort(a.begin(), a.end());
sort(b.begin(), b.end());
if (n > m) {
swap(a, b);
swap(n, m);
}
ll l = 0, r = 2e9;
while (l < r) {
ll mid = (l+r)/2;
int p = 0;
bool ok = 1;
Loop (i,0,n) {
while (p < m && abs(a[i] - b[p]) > mid)
++p;
if (p == m) {
ok = 0;
break;
}
++p;
}
if (ok)
r = mid;
else
l = mid+1;
}
cout << l << '\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... |