Woburn Challenge 2017-18 Finals Round - Senior Division
The Great Cow-Monkey War of 2017 has left Scarberia in a fragile and unstable state. Interspecies tension is at an all-time high, and both sides are working relentlessly to rebuild their economies, social systems, and militias. Little do the cows and monkeys know that amidst the turmoil, the world is at risk of being taken over by an even more dangerous foe — a group of aliens known as the Party of Extraterrestrial Gangsters (or PEG for short)! PEG has decided that it's the perfect time to divide and conquer Scarberia by exploiting its current internal hostilities. Fortunately, Bo Vine and the Head-Monkey have learned of the impending invasion in time, and an important realization has dawned on them: now is not the time to engage in petty quarrels with one another. All of Scarberia must unite, at least temporarily, to face an even greater evil. The animals have thus formed a truce, and started to plan for the upcoming war!
With an overall battle formation decided, the cows and monkeys are now ready to fight against the incoming alien invaders! …Well, almost. You see, the commanders realized that it is not too effective to simply line up large platoons of uniformly cows or uniformly monkeys. They must work together at a more local scale, with each cow and monkey taking immediate advantage of each others' strengths and weaknesses. As such, the commanders have decided to pair up cows and monkeys to form individual combat units on the battlefield.
Between the united armies, there are cows and monkeys . The -th cow has a combat skill level of , while the -th monkey has a combat skill level of . Each cow is to be paired up with a monkey to form a combat unit, such that there are combat units total and each of the animals is a part of exactly one unit.
A combat unit is most effective when the skill levels of its two members don't differ too greatly. More formally, we can define the combat skill differential of a given unit to be the absolute difference between the combat skill levels of the two animals making up that unit. For a given pairing of the animals, let denote the maximum combat skill differential across all combat units. Bo Vine and the Head-Monkey would like to pair up the animals such that ends up being as small as possible. Can you help them determine the minimum possible value of which can be achieved?
Subtasks
In test cases worth of the points, and
for each .
In test cases worth another of the points, and
for each .
In test cases worth another of the points, .
Input Specification
The first line of input consists of a single integer, .
The second line consists of space-separated integers, .
The third line consists of space-separated integers, .
Output Specification
Output a single integer, the minimum possible value of which can be achieved.
Sample Input
4
5 1 9 1
2 7 4 6
Sample Output
3
Sample Explanation
One possible optimal arrangement is to pair:
- cow with monkey (a combat skill differential of )
- cow with monkey (a combat skill differential of )
- cow with monkey (a combat skill differential of )
- cow with monkey (a combat skill differential of )
The maximum of these differentials is , and it is not possible to go any lower.
Comments