#P14458. [ICPC 2025 Xi'an R] Let's Make a Convex!

[ICPC 2025 Xi'an R] Let's Make a Convex!

题目描述

Kevin is the chief judge of the $\textit{International Convex Polygon Championship (ICPC)}$. He proposed a geometry task for the contest. However, due to his lack of experience in geometry, he was unable to generate the correct convex polygons for the task.

To prove his geometry skills, Kevin starts playing with sticks. He has nn sticks, the ii-th of which has a length aia_i. He would like to select kk sticks so that they can be arranged as a non-degenerate convex polygon.

Since stronger test data are needed, Kevin wants to maximize the perimeter of the polygon (i.e., maximize the sum of aia_i of all sticks in the subset). Could you help him find out the value for all integers kk from 11 to nn? If no such polygon exists, tell him a single integer 00 instead.

输入格式

The input consists of multiple test cases. The first line contains an integer tt (1t1051 \leq t \leq 10^5), the number of test cases. For each test case:

  • The first line contains a single integer nn (1n21051 \leq n \leq 2 \cdot 10^5), which is the number of sticks.
  • The second line contains nn integers a1,,ana_1, \ldots, a_n (1ai1091 \leq a_i \leq 10^9), which are the lengths of each stick.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

输出格式

For each test case, output a single line containing nn integers, representing the maximal perimeter of the polygon. Specifically, if no such polygon exists, output a single integer 00.

7
5
1 2 3 4 5
5
1 2 4 8 16
5
2 2 2 2 2
4
1 4 10 7
2
1 2
3
2 3 4
4
3 1 2 6
0 0 12 14 15
0 0 0 0 0
0 0 6 8 10
0 0 21 22
0 0
0 0 9
0 0 0 0

提示

In the first test case, it can be shown that there does not exist a convex polygon of 11 or 22 sides. When k=3k = 3, the maximal perimeter of the convex polygon is 1212, since sticks of side lengths 33, 44, and 55 are known for forming a right triangle. Similarly, when k=4k = 4, the maximal perimeter of the polygon is 2+3+4+5=142 + 3 + 4 + 5 = 14; when k=5k = 5, selecting all sticks is a valid scheme and obtains a perimeter of 1+2+3+4+5=151 + 2 + 3 + 4 + 5 = 15.

In the second test case, it can be proven that no matter how the sticks are selected, they cannot form a convex polygon.