#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 left shoes and 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 , representing the numbers of left shoes and right shoes.
The second line contains integers , representing the sizes of the left shoes.
The third line contains integers , 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 left shoes and right shoes, so at most 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 .
A better pairing method is: 39-39, 41-42, 45-46. The ugliness of this method is , which is the minimum among all pairing methods.
Constraints
For of the testdata, .
For another of the testdata, .
For of the testdata, , .
Notes
The score settings of this problem follow the original COCI problem, with a full score of .
Translated from T3 Cipele of COCI2018-2019 CONTEST #1.
Translated by ChatGPT 5
京公网安备 11011102002149号