/* -*- coding: utf-8 -*- * * 3325.cc: No.3325 髯ー髯ス蟶ォ - yukicoder */ #include #include #include #include using namespace std; /* constant */ const int MAX_N = 200000; const int MAX_M = 200000; /* typedef */ using msi = multiset; using pii = pair; /* global variables */ int ss[MAX_N], ts[MAX_M]; /* subroutines */ pii calcmax(int n, int m) { msi as(ss, ss + n); int maxd = 0; for (int i = 0; i < m; i++) { auto sit = as.lower_bound(ts[i]); if (sit != as.end()) { maxd = max(maxd, *sit - ts[i]); as.erase(sit); } else return {maxd, i}; } return {maxd, m}; } int calc(int n, int m, int d) { msi as(ss, ss + n); for (int i = 0; i < m; i++) { auto sit = as.upper_bound(ts[i] + d); if (sit == as.begin()) return i; sit--; if (*sit < ts[i]) return i; as.erase(sit); } return m; } /* main */ int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", ss + i); for (int i = 0; i < m; i++) scanf("%d", ts + i); auto [maxd, maxx] = calcmax(n, m); //printf(" maxd=%d,maxx=%d\n", maxd, maxx); int d0 = -1, d1 = maxd; while (d0 + 1 < d1) { int d = (d0 + d1) / 2; if (calc(n, m, d) >= maxx) d1 = d; else d0 = d; } printf("%d\n", d1); return 0; }