#P7305. [COCI 2018/2019 #1] Cipele

[COCI 2018/2019 #1] Cipele

Description

After spending money on all kinds of projects, Nadan decided to provide software developers with high-quality shoes.

Nadan found NN left shoes and MM right shoes in the basement. Since their sources are unknown, the shoe sizes are not necessarily the same.

Nadan wants you to match as many pairs of shoes as possible (that is, after all pairings are done, no more pairs can be formed). Each pair must contain one left shoe and one right shoe. When wearing the shoes, the ugliness should be minimized. The ugliness of a set of pairs is defined as the maximum, over all paired shoes, of the absolute difference between the sizes of the left shoe and the right shoe.

Input Format

The first line contains positive integers N,MN, M, representing the numbers of left shoes and right shoes.

The second line contains NN integers LiL_i, representing the sizes of the left shoes.

The third line contains MM integers RiR_i, representing the sizes of the right shoes.

Output Format

Output the minimum possible ugliness among all possible pairing methods.

2 3
2 3
1 2 3
0
4 3
2 39 41 45
39 42 46
1
5 5
7 6 1 2 10
9 11 6 3 12
4

Hint

Explanation of Sample 2

Nadan has 44 left shoes and 33 right shoes, so at most 33 pairs can be formed. One pairing method is: 39-46, 41-42, 45-39. The first pair has the largest absolute size difference, so the ugliness is 77.

A better pairing method is: 39-39, 41-42, 45-46. The ugliness of this method is 11, which is the minimum among all pairing methods.

Constraints

For 20%20\% of the testdata, N=MN = M.

For another 50%50\% of the testdata, N,M5000N, M \le 5000.

For 100%100\% of the testdata, 1N,M1051 \le N, M \le 10^5, 1Li,Ri1091 \le L_i, R_i \le 10^9.

Notes

The score settings of this problem follow the original COCI problem, with a full score of 9090.

Translated from T3 Cipele of COCI2018-2019 CONTEST #1.

Translated by ChatGPT 5