Codeforces Round 1008 (Div. 1)
D
Maximum Polygon
Codeforces
3100
原题
← CE →
翻译中…

Given an array $a$ of length $n$, determine the lexicographically largest$^{\text{∗}}$ subsequence$^{\text{†}}$ $s$ of $a$ such that $s$ can be the side lengths of a polygon.

翻译中…

Recall that $s$ can be the side lengths of a polygon if and only if $|s| \geq 3$ and

翻译中…

$$ 2 \cdot \max(s_1, s_2, \ldots, s_{|s|}) \lt s_1 + s_2 + \ldots + s_{|s|}. $$

翻译中…

If no such subsequence $s$ exists, print $-1$.

翻译中…

$^{\text{∗}}$A sequence $x$ is lexicographically smaller than a sequence $y$ if and only if one of the following holds: $x$ is a prefix of $y$, but $x \ne y$; in the first position where $x$ and $y$ differ, the sequence $x$ has a smaller element than the corresponding element in $y$.$^{\text{†}}$A sequence $x$ is a subsequence of a sequence $y$ if $x$ can be obtained from $y$ by deleting several (possibly zero or all) elements.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) — the length of the array $a$.

翻译中…

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the array $a$.

翻译中…

It is guaranteed that the total sum of all values of $n$ across all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output the answer in the following format:

翻译中…

If the answer exists, output the following.

翻译中…

In the first line, output the integer $k$ ($1 \leq k \leq n$) — the length of the subsequence $s$.

翻译中…

In the second line, output $k$ integers $s_1, s_2, \ldots, s_k$ ($1 \leq s_i \leq 10^9$, $s$ is a subsequence of $a$) — the subsequence $s$. Note that the desired output is the value, not the index.

翻译中…

Otherwise, output a single line with the integer $-1$.

翻译中…

Note

翻译中…

In the first test case, there are no subsequences that can be the side lengths of a polygon.

翻译中…

In the second test case, there are $2$ subsequences that can be the side lengths of a polygon: $1, 4, 2, 3$ and $4, 2, 3$. The latter is the lexicographically larger subsequence.

翻译中…

样例

Input #1
5
3
3 1 2
4
1 4 2 3
6
1 6 4 5 3 2
6
43 12 99 53 22 4
7
9 764 54 73 22 23 1
Output #1
-1
3
4 2 3
4
6 5 3 2
5
43 99 53 22 4
4
54 73 23 1
InputCopy OutputCopy
题目信息
题号
2077D
时间限制
3 s
内存限制
256 MB
标签
暴力
数据结构
贪心
模拟
数学

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