use proconio::{fastout, input}; #[fastout] fn main() { input! { n: usize, m: usize, mut s: [u32; n], t: [u32; m], } s.sort_unstable(); let mut sorted_t = t.into_iter().zip(0..m as u32).collect::>(); sorted_t.sort_unstable(); println!("{}", output(solve(n, s, sorted_t))); } fn check(n: usize, s: &Vec, t: &Vec<(u32, u32)>, c: usize) -> bool { let mut i = 0; for (t, index) in t.iter() { if (*index as usize) < c { while i < n && s[i] < *t { i += 1; } match i < n { true => i += 1, false => return false, }; } } true } fn solve(n: usize, s: Vec, t: Vec<(u32, u32)>) -> u32 { let mut l = 0; let mut r = t.len() + 1; while l + 1 < r { let c = (l + r) / 2; match check(n, &s, &t, c) { true => l = c, false => r = c, }; } let mut ans = 0; let mut i = 0; for (t, index) in t.into_iter() { if (index as usize) < l { while i < n && s[i] < t { i += 1; } match i < n { true => ans = ans.max(s[i] - t), false => return ans, }; i += 1; } } ans } fn output(ans: u32) -> u32 { ans }