CF BUDDY
← Problems·

1857C · Assembly via Minimums

1200 · greedy, sortings

Problem: Sasha has an array aa of nn integers. He got bored and for all ii, jj (i<ji < j), he wrote down the minimum value of aia_i and aja_j. He obtained a new array bb of size n(n1)2\frac{n\cdot (n-1)}{2}.

For example, if a=a= [2,3,5,12,3,5,1], he would write [min(2,3),min(2,5),min(2,1),min(3,5),min(3,1),min(5,1)\min(2, 3), \min(2, 5), \min(2, 1), \min(3, 5), \min(3, 1), min(5, 1)] == [2,2,1,3,1,12, 2, 1, 3, 1, 1].

Then, he randomly shuffled all the elements of the array bb.

Unfortunately, he forgot the array aa, and your task is to restore any possible array aa from which the array bb could have been obtained.

The elements of array aa should be in the range [109,109][-10^9,10^9].

Input Format: The first line contains a single integer tt (1t2001\le t\le 200) — the number of test cases.

The first line of each test case contains a single integer nn (2n1032\le n\le 10^3) — the length of array aa.

The second line of each test case contains n(n1)2\frac{n\cdot (n-1)}{2} integers b1,b2,,bn(n1)2b_1,b_2,\dots,b_{\frac{n\cdot (n-1)}{2}} (109bi109−10^9\le b_i\le 10^9) — the elements of array bb.

It is guaranteed that the sum of nn over all tests does not exceed 10310^3 and for each array bb in the test, there exists an original array.

Output Format: For each test case, output any possible array aa of length nn.

Note: In the first sample, Sasha chose the array [1,3,3][1,3,3], then the array bb will look like [min(a1,a2)=1,min(a1,a3)=1,min(a2,a3)=3][\min(a_1,a_2)=1, \min(a_1,a_3)=1, \min(a_2,a_3)=3], after shuffling its elements, the array can look like [1,3,1][1,3,1].

In the second sample, there is only one pair, so the array [10,10][10,10] is suitable. Another suitable array could be [15,10][15,10].

Sample Cases

Case 1

Input

5
3
1 3 1
2
10
4
7 5 3 5 3 3
5
2 2 2 2 2 2 2 2 2 2
5
3 0 0 -2 0 -2 0 0 -2 -2

Output

1 3 3
10 10
7 5 3 12
2 2 2 2 2
0 -2 0 3 5

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback