CF1857C.Assembly via Minimums

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Sasha has an array aa of nn integers. He got bored and for all ii, jj (i<ji \lt j), he wrote down the minimum value of aia_i and aja_j. He obtained a new array bb of size n⋅(n−1)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].

萨沙有一个包含 nn 个整数的数组 aa。他感到无聊,于是对所有满足 i<ji \lt j 的下标对 (i,j)(i, j),计算并记录下 aia_i 与 aja_j 的最小值。由此得到了一个大小为 n⋅(n−1)2\frac{n\cdot (n-1)}{2} 的新数组 bb。

例如,若 a=[2,3,5,1]a = [2,3,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, 1]$$。 接着,他将数组 $b$ 中的所有元素随机打乱。 不幸的是,他忘记了原始数组 $a$。你的任务是根据给定的数组 $b$,还原出任意一个可能的数组 $a$,使得该 $a$ 经上述过程确实能生成(打乱前的)$b$。 数组 $a$ 中的元素必须在区间 $[-10^9,10^9]$ 内。

输入格式

The first line contains a single integer tt (1≤t≤2001\le t\le 200) — the number of test cases.

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

The second line of each test case contains n⋅(n−1)2\frac{n\cdot (n-1)}{2} integers b1,b2,…,bn⋅(n−1)2b_1,b_2,\dots,b_{\frac{n\cdot (n-1)}{2}} (−109≤bi≤109−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.

第一行包含一个整数 tt(1≤t≤2001\le t\le 200)——测试用例的数量。

每个测试用例的第一行包含一个整数 nn(2≤n≤1032\le n\le 10^3)——数组 aa 的长度。

每个测试用例的第二行包含 n⋅(n−1)2\frac{n\cdot (n-1)}{2} 个整数 b1,b2,…,bn⋅(n−1)2b_1,b_2,\dots,b_{\frac{n\cdot (n-1)}{2}}(−109≤bi≤109−10^9\le b_i\le 10^9)——数组 bb 的元素。

保证所有测试用例中 nn 的总和不超过 10310^3,且对每个测试用例中的数组 bb,均存在对应的原始数组 aa。

输出格式

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

对于每个测试用例,输出任意一个长度为 nn 的数组 aa。

输入输出样例

  • 输入#1

    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

    输出#1

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

说明/提示

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].

在第一个样例中,萨沙选择了数组 [1,3,3][1,3,3],则数组 bb 将为 [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];对其元素进行重排后,该数组可能变为 [1,3,1][1,3,1]。

在第二个样例中,仅存在一对元素,因此数组 [10,10][10,10] 是可行的。另一个可行的数组可以是 [15,10][15,10]。

输入解题思路,AI测评打分。不知道怎么写?

首页