Mendelian Genetics
Time limit1sMemory limit128 MB
For each data set, find the n largest values among the ceil((x+y)/2) hybrid sizes formed by all pairs of n given sizes, sorted descending.
- Level
Medium7 of 10
- Topics
- Sorting, Greedy, Binary search
- Solved
- No attempts yet
Problem
The Austrian monk Gregor Mendel (1822–1884) is regarded as the founding father of genetics for his pioneering theory of genotypic inheritance. In this problem you help Mendel speed up his pea-hybridization experiments.
Consider only one feature of the peas: their size. Starting from initial types, each with a size, hybridizing them pairwise yields hybrid types after one generation. Mendel wants larger peas, but he can afford to grow only of the candidates, so he must pick the most promising ones.
Without knowing the hidden genotypes, he estimates the size of the hybrid of two parents of sizes and with the formula
For example, if the two parents have sizes and , the hybrid is estimated to have size .
Find the largest values in this matrix of pairwise combinations. A type may also be combined with itself, i.e. the diagonal entries are included.
Input
The first line contains the number of data sets. Then follow data sets, each of the following form:
- The first line contains an integer (), the number of initial types.
- The second line contains positive integers, the sizes of the initial types.
Output
For each data set, output Data Set x: on a line by itself, where is its number (starting from ). On the next line output the largest numbers from the matrix of combinations, sorted in descending order and separated by single spaces. Separate consecutive data sets with a single blank line.