Codeforces Round 941 (Div. 2)
F
Missing Subarray Sum
Codeforces
未评级
原题
← E→
翻译中…

There is a hidden array $a$ of $n$ positive integers. You know that $a$ is a palindrome, or in other words, for all $1 \le i \le n$, $a_i = a_{n + 1 - i}$. You are given the sums of all but one of its distinct subarrays, in arbitrary order. The subarray whose sum is not given can be any of the $\frac{n(n+1)}{2}$ distinct subarrays of $a$.

翻译中…

Recover any possible palindrome $a$. The input is chosen such that there is always at least one array $a$ that satisfies the conditions.

翻译中…

An array $b$ is a subarray of $a$ if $b$ can be obtained from $a$ by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

翻译中…

Input

翻译中…

The first line of the input contains a single integer $t$ ($1 \le t \le 200$) — the number of test cases. The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($3 \le n \le 1000$) — the size of the array $a$.

翻译中…

The next line of each test case contains $\frac{n(n+1)}{2} - 1$ integers $s_i$ ($1\leq s_i \leq 10^9$) — all but one of the subarray sums of $a$.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.

翻译中…

Additional constraint on the input: There is always at least one valid solution.

翻译中…

Hacks are disabled for this problem.

翻译中…

Output

翻译中…

For each test case, print one line containing $n$ positive integers $a_1, a_2, \cdots a_n$ — any valid array $a$. Note that $a$ must be a palindrome.

翻译中…

If there are multiple solutions, print any.

翻译中…

Note

翻译中…

For the first example case, the subarrays of $a = [1, 2, 1]$ are:

翻译中…
  • $[1]$ with sum $1$,
  • $[2]$ with sum $2$,
  • $[1]$ with sum $1$,
  • $[1, 2]$ with sum $3$,
  • $[2, 1]$ with sum $3$,
  • $[1, 2, 1]$ with sum $4$.
翻译中…

So the full list of subarray sums is $1, 1, 2, 3, 3, 4$, and the sum that is missing from the input list is $3$.

翻译中…

For the second example case, the missing subarray sum is $4$, for the subarray $[2, 2]$.

翻译中…

For the third example case, the missing subarray sum is $13$, because there are two subarrays with sum $13$ ($[3, 5, 5]$ and $[5, 5, 3]$) but $13$ only occurs once in the input.

翻译中…

样例

Input #1
7
3
1 2 3 4 1
4
18 2 11 9 7 11 7 2 9
4
5 10 5 16 3 3 13 8 8
4
8 10 4 6 4 20 14 14 6
5
1 2 3 4 5 4 3 2 1 1 2 3 2 1
5
1 1 2 2 2 3 3 3 3 4 5 5 6 8
3
500000000 1000000000 500000000 500000000 1000000000
Output #1
1 2 1
7 2 2 7
3 5 5 3
6 4 4 6
1 1 1 1 1
2 1 2 1 2
500000000 500000000 500000000
InputCopy OutputCopy
题目信息
题号
1966F
时间限制
5 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。