Woburn Challenge 2017-18 Finals Round - Senior Division
Problem 1: An Interspecific Army
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 N cows and N monkeys (1 ≤ N ≤ 100,000). The i-th cow has a combat skill level of Ci (1 ≤ Ci ≤ 106), while the i-th monkey has a combat skill level of Mi (1 ≤ Mi ≤ 106). Each cow is to be paired up with a monkey to form a combat unit, such that there are N combat units total and each of the 2N 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 2N animals, let D denote the maximum combat skill differential across all N combat units. Bo Vine and the Head-Monkey would like to pair up the animals such that D ends up being as small as possible. Can you help them determine the minimum possible value of D which can be achieved?
In test cases worth 2/9 of the points, N ≤ 10 and 1 ≤ Ci, Mi ≤ 2 for each i.
In test cases worth another 2/9 of the points, N ≤ 1000 and 1 ≤ Ci, Mi ≤ 2 for each i.
In test cases worth another 4/9 of the points, N ≤ 1000.
The first line of input consists of a single integer, N.
The second line consists of N space-separated integers, C1, …, CN.
The third line consists of N space-separated integers, M1, …, MN.
Output a single integer, the minimum possible value of D which can be achieved.
4 5 1 9 1 2 7 4 6
One possible optimal arrangement is to pair:
- cow 1 with monkey 2 (a combat skill differential of |5 − 7| = 2)
- cow 2 with monkey 1 (a combat skill differential of |1 − 2| = 1)
- cow 3 with monkey 4 (a combat skill differential of |9 − 6| = 3)
- cow 4 with monkey 3 (a combat skill differential of |1 − 4| = 3)
The maximum of these differentials is 3, and it is not possible to go any lower.
Point Value: 10 (partial)
Time Limit: 3.00s
Memory Limit: 64M
Added: May 13, 2018
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3