Tribute
Time limit15sMemory limit512 MB
Given all 2^n - 1 non-empty subset sums, recover the n positive values they came from, or report that the answer is missing or not unique.
- Level
Medium7 of 10
- Topics
- Sorting, Greedy, Implementation, Math
- Solved
- No attempts yet
Problem
The Son of Heaven, our beloved emperor, has commanded you, his First Minister, to extort tribute from neighbouring kingdoms. Each tributary has been assigned a number of silver coins to pay: for the -th kingdom, the number is . To show His infinite grace, the emperor decided to take money from only some of the countries and spare the rest. Your overzealous finance minister, after writing down all , has already produced all possible income values, the sums of the non-empty subsets of tributaries. Unfortunately, in the process the minister lost the paper sheet with the original tribute values. For this infraction, as well as improper calligraphy, he was promptly executed.
Now you have only sums, written rather badly. Can you recover the tribute values from them?
Input
The first line of input contains the number of test cases . The descriptions of the test cases follow.
Every test case consists of two lines: the first contains a number , the second contains integers not exceeding , denoting all the possible sums of tributes. Assume that the tribute values were all positive integers. The total number of sums in all test cases does not exceed .
Output
For each test case output the recovered values of for , in increasing order. If there are no values that fit the input, or if there are multiple possibilities, simply write ``\texttt{NO}'' instead: you cannot execute anyone twice.