Lineage
Time limit1sMemory limit256 MB
Pick a father and a mother from the given gene values so the nearest of the three pups' gene values to R is as close as possible.
- Level
Medium5 of 10
- Topics
- Sorting, Binary search
- Solved
- No attempts yet
Problem
At a rabbit breeding institute the keeper decides which male and which female to mate so that a customer gets the young rabbit they want.
A rabbit carries gene A in amount and gene B in amount , and the two amounts always add up to (). More gene A makes a rabbit cuter, more gene B makes it smarter. A rabbit whose gene A is at least as large as its gene B () has pink fur.
A mating always produces three young rabbits. If the father carries gene A in amount and the mother carries gene A in amount , the three young rabbits carry gene A in these amounts:
- first:
- second:
- third:
These three amounts are not always integers.
The institute keeps breeding pairs. One pair is the cutest pair, with gene A equal to , and another pair is the smartest pair, with gene A equal to . Pair is one male and one female that both carry gene A in amount .
The customer names the amount of gene A they want, and the keeper picks one male as the father and one female as the mother. The two may come from different pairs or from the same pair. The customer takes the one young rabbit whose gene A is closest to , and the other two stay at the institute for later matings.
Pick the father and the mother so that the difference between and the gene A of the young rabbit the customer takes is as small as possible.
Input
The first line has the number of test cases ().
Each test case is three lines.
- The first line has the number of breeding pairs ().
- The second line has the amount of gene A the customer wants ().
- The third line has the amounts separated by spaces ().
At least one is and at least one is .
Output
For each test case print the gene A of the chosen father and the gene A of the chosen mother in that order, on one line, separated by a space.
If several combinations give the same smallest difference, print the one whose mother has the largest gene A. If several of those remain, print the one whose father has the largest gene A.