Woburn Challenge 2016-17 Round 2 - Senior Division
During its travels, the Starship Enterprise has come across a rather curious planet which appears to contain vast deposits of kironide, a rare and valuable mineral. Captain Kerk has ordered of his crewmembers to go on an away mission to the planet's surface in order to confirm the sensors' readings. If all goes well, they'll be able to locate the kironide and collect some samples… before anything on the planet collects them as samples.
Each of the crewmembers will need to be outfitted with a shirt, of course. It's standard Starfleet procedure for shirts to be manufactured on demand, with the use of a shirt replicator. The replicator is fed three Colour Component Chips (CCCs) - a red, green, and blue one - which determine the colour of the resulting shirt. Each CCC, in addition to corresponding to a particular colour component (either red, green, or blue), is encoded with an integral value between and , inclusive. Kerk has red CCCs with values at his disposal. He similarly has green CCCs with values , and blue CCCs with values .
Kerk may feed the CCCs into the shirt replicator in any combinations he'd like to in order to create shirts, as long as the replicator is always given CCCs corresponding to all three different colour components at a time, and each of the CCCs is only used once.
A shirt is considered "red" if its red CCC's value is strictly larger than its other two CCCs' values. In other words, if a shirt was produced using red, green, and blue CCCs with values , , and , then it's red if both and .
Unfortunate accidents have a way of happening to crewmembers wearing red shirts, so producing as few red shirts as possible would be beneficial. However, a strange anomaly has recently struck the Enterprise, which may be having unusual psychological effects on its crew, based on the value of . If , then Kerk has remained resilient and is determined to arrange his CCCs such that as few as possible of the shirts are red. Otherwise, if , then Kerk's psychological state has been compromised, and he'll instead maximize the number of red shirts produced!
In either case, please help estimate the number of "accidents" which might occur on the away mission by determining how many of the crewmembers will end up wearing red shirts.
In test cases worth of the points, and for
(and in exactly of these, ).
In test cases worth another of the points, (and in
exactly of these, ).
In exactly of the remaining test cases, .
Input Specification
The first line of input consists of two space-separated integers and .
The next line consists of space-separated integers .
The next line consists of space-separated integers .
The next line consists of space-separated integers .
Output Specification
Output a single integer - either the minimum possible number of red shirts that must be made if , or the maximum possible number that can be made if .
Sample Input 1
3 1
200 0 123
0 42 122
5 200 99
Sample Output 1
1
Sample Explanation 1
One optimal set of shirts is as follows (with each one notated as ):
(200, 0, 200)
(0, 42, 99)
(123, 122, 5)
Of these, only the last one is red. Unfortunately, it's impossible for none of the shirts to be red.
Sample Input 2
3 2
200 0 123
0 42 122
5 200 99
Sample Output 2
2
Sample Explanation 2
One optimal set of shirts is as follows:
(200, 0, 99)
(0, 42, 200)
(123, 122, 5)
Comments