CF1857C.Assembly via Minimums
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Sasha has an array a of n integers. He got bored and for all i, j (i<j), he wrote down the minimum value of ai and aj. He obtained a new array b of size 2n⋅(n−1).
For example, if a= [2,3,5,1], he would write [min(2,3),min(2,5),min(2,1),min(3,5),min(3,1),min(5,1)] = [2,2,1,3,1,1].
Then, he randomly shuffled all the elements of the array b.
Unfortunately, he forgot the array a, and your task is to restore any possible array a from which the array b could have been obtained.
The elements of array a should be in the range [−109,109].
萨沙有一个包含 n 个整数的数组 a。他感到无聊,于是对所有满足 i<j 的下标对 (i,j),计算并记录下 ai 与 aj 的最小值。由此得到了一个大小为 2n⋅(n−1) 的新数组 b。
例如,若 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 t (1≤t≤200) — the number of test cases.
The first line of each test case contains a single integer n (2≤n≤103) — the length of array a.
The second line of each test case contains 2n⋅(n−1) integers b1,b2,…,b2n⋅(n−1) (−109≤bi≤109) — the elements of array b.
It is guaranteed that the sum of n over all tests does not exceed 103 and for each array b in the test, there exists an original array.
第一行包含一个整数 t(1≤t≤200)——测试用例的数量。
每个测试用例的第一行包含一个整数 n(2≤n≤103)——数组 a 的长度。
每个测试用例的第二行包含 2n⋅(n−1) 个整数 b1,b2,…,b2n⋅(n−1)(−109≤bi≤109)——数组 b 的元素。
保证所有测试用例中 n 的总和不超过 103,且对每个测试用例中的数组 b,均存在对应的原始数组 a。
输出格式
For each test case, output any possible array a of length n.
对于每个测试用例,输出任意一个长度为 n 的数组 a。
输入输出样例
输入#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], then the array b will look like [min(a1,a2)=1,min(a1,a3)=1,min(a2,a3)=3], after shuffling its elements, the array can look like [1,3,1].
In the second sample, there is only one pair, so the array [10,10] is suitable. Another suitable array could be [15,10].
在第一个样例中,萨沙选择了数组 [1,3,3],则数组 b 将为 [min(a1,a2)=1,min(a1,a3)=1,min(a2,a3)=3];对其元素进行重排后,该数组可能变为 [1,3,1]。
在第二个样例中,仅存在一对元素,因此数组 [10,10] 是可行的。另一个可行的数组可以是 [15,10]。
输入解题思路,AI测评打分。不知道怎么写?