#P7305. Minimizing Shoe Pair Ugliness
Minimizing Shoe Pair Ugliness
Minimizing Shoe Pair Ugliness
Nadan has discovered a collection of shoes in his basement: N left shoes and M right shoes. The sizes of these shoes vary as they come from unknown sources. Nadan wants to create as many pairs as possible (a pair consists of one left shoe and one right shoe, and after pairing, no additional valid pair exists) and minimize the ugliness of the pairings.
The ugliness of a complete set of pairings is defined as the maximum absolute difference between the sizes of the left and right shoes in any pair. Formally, if the pairs are (l1, r1), (l2, r2), …, (lk, rk) (with k = min(N, M)), then the ugliness U is given by:
\( U = \max_{1 \le i \le k} \; |l_i - r_i| \)
Your task is to determine the minimum possible ugliness achievable by optimally pairing the shoes. Note that you must form exactly min(N, M) pairs.
inputFormat
The first line contains two integers N and M (1 ≤ N, M ≤ 105) indicating the number of left and right shoes, respectively.
The second line contains N integers representing the sizes of the left shoes.
The third line contains M integers representing the sizes of the right shoes.
outputFormat
Output a single integer — the minimum possible ugliness, i.e., the minimized maximum absolute difference among all pairs.
sample
3 3
1 4 9
2 5 10
1
</p>