//
// Created by liasa on 29/01/2026.
//
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define v vector
#define lp(i, s, e) for (int i = s; i < e; ++i)
ll n;
v<ll> solve(v<ll> tp1, v<ll> tp2, ll d) {
v<ll> res(n, 0);
v<ll> ev(n + 1, 0);
v<ll> LF(2 * n), RG(2 * n);
ll p_l = 0, p_r = 0;
for (ll i = 0; i < n; i++) {
while (p_l < n && tp2[p_l] < tp1[i] - d)
p_l++;
while (p_r < n && tp2[p_r] <= tp1[i] + d)
p_r++;
LF[i] = p_l;
RG[i] = p_r - 1;
}
p_l = n;
p_r = n;
for (ll i = n; i < 2 * n; i++) {
while (p_l > 0 && tp2[p_l - 1] >= tp1[i] - d)
p_l--;
while (p_r > 0 && tp2[p_r - 1] > tp1[i] + d)
p_r--;
LF[i] = p_l;
RG[i] = p_r - 1;
}
v<ll> LOW(2 * n);
ll s_r = 2 * n;
for (ll i = 0; i < n; i++) {
while (s_r > n && tp1[s_r - 1] < tp1[i])
s_r--;
LOW[i] = i - s_r + n;
}
s_r = n;
for (ll i = n; i < 2 * n; i++) {
while (s_r > 0 && tp1[s_r - 1] > tp1[i])
s_r--;
LOW[i] = s_r + n - i - 1;
}
for (ll i = 0; i < n; i++) {
if (RG[i] < LOW[i])
continue;
ll L = max(0LL, i - RG[i]);
ll R;
if (LF[i] <= LOW[i])
R = i + 1;
else
R = i - LF[i] + 1;
if (L < R) {
ev[L]++;
ev[R]--;
}
}
for (ll i = n; i < 2 * n; i++) {
if (RG[i] < LOW[i])
continue;
ll L;
if (LF[i] <= LOW[i])
L = i - n + 1;
else
L = i + LF[i] - n + 1;
ll R = min(n, i + RG[i] - n + 2);
if (L < R) {
ev[L]++;
ev[R]--;
}
}
ll cur = 0;
for (ll s = 0; s < n; s++) {
cur += ev[s];
if (cur == n)
res[s] = 1;
}
return res;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
v<ll> a(2 * n), b(n), c(n);
lp(i, 0, 2 * n) cin >> a[i];
lp(i, 0, n) cin >> b[i];
lp(i, 0, n) cin >> c[i];
sort(b.begin(), b.end());
sort(c.begin(), c.end());
v<ll> ra = a, rb = b, rc = c;
lp(i, 0, n) swap(ra[i], ra[i + n]);
lp(i, 0, 2 * n) ra[i] *= -1;
reverse(rb.begin(), rb.end());
for (auto &x : rb)
x = -x;
reverse(rc.begin(), rc.end());
for (auto &x : rc)
x = -x;
ll l = 0, r = 1e9, ans = 1e18;
while (l <= r) {
ll mid = (l + r) / 2;
v<ll> F1 = solve(a, b, mid);
v<ll> F2 = solve(ra, rb, mid);
v<ll> G1 = solve(a, c, mid);
v<ll> G2 = solve(ra, rc, mid);
bool ok = 0;
lp(s, 0, n) {
if ((F1[s] && G2[s]) || (F2[s] && G1[s])) {
ok = 1;
}
}
if (ok) {
ans = min(ans, mid);
r = mid - 1;
} else
l = mid + 1;
}
cout << ans << endl;
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... |