A16126 | Assembly via Minimums
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $a_i$ and $a_j$ . He obtained a new array $b$ of size $\frac{n\cdot (n-1)}{2}$ .
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 $[-10^9,10^9]$ .
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 $[-10^9,10^9]$ .
输入格式
The first line contains a single integer $t$ ( $1\le t\le 200$ ) — the number of test cases.
The first line of each test case contains a single integer $n$ ( $2\le n\le 10^3$ ) — the length of array $a$ .
The second line of each test case contains $\frac{n\cdot (n-1)}{2}$ integers $b_1,b_2,\dots,b_{\frac{n\cdot (n-1)}{2}}$ ( $−10^9\le b_i\le 10^9$ ) — the elements of array $b$ .
It is guaranteed that the sum of $n$ over all tests does not exceed $10^3$ and for each array $b$ in the test, there exists an original array.
The first line of each test case contains a single integer $n$ ( $2\le n\le 10^3$ ) — the length of array $a$ .
The second line of each test case contains $\frac{n\cdot (n-1)}{2}$ integers $b_1,b_2,\dots,b_{\frac{n\cdot (n-1)}{2}}$ ( $−10^9\le b_i\le 10^9$ ) — the elements of array $b$ .
It is guaranteed that the sum of $n$ over all tests does not exceed $10^3$ and for each array $b$ in the test, there exists an original array.
输出格式
For each test case, output any possible array $a$ of length $n$ .
输入输出样例
输入 #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(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]$ .
In the second sample, there is only one pair, so the array $[10,10]$ is suitable. Another suitable array could be $[15,10]$ .
In the second sample, there is only one pair, so the array $[10,10]$ is suitable. Another suitable array could be $[15,10]$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted