#P17303. [ICPC 2026 Xi'an I] Would You Make a Convex?

    ID: 19713 远端评测题 1000ms 512MiB 尝试: 26 已通过: 11 显示难度普及+/提高− 上传者: 标签>贪心二分Special Judge排序ICPC2026双指针 two-pointer省赛/邀请赛西安

[ICPC 2026 Xi'an I] Would You Make a Convex?

Problem Description

Yuki is the chief judge of the International Convex Polygon Championship (ICPC). He proposed a geometry problem for the competition. However, due to his lack of experience in geometry, he failed to generate correct convex polygon data.

To prove his geometric ability, Yuki started playing with sticks again. He has nn sticks, where the length of the ii-th stick is aia_i. He intends to choose at least 33 sticks from them such that these sticks can form a non-degenerate convex polygon^\ast.

However, since Yuki does not know much about geometry, he does not know how to choose the sticks. As a good friend of Yuki, you need to help him find a subset of sticks such that:

  • The subset contains at least 33 sticks, and the number of sticks is as large as possible;
  • For any\textbf{any} subset of at least 33 sticks chosen from this subset, these sticks can form a non-degenerate convex polygon.

Or report that no such subset exists.

^\ast: A non-degenerate convex polygon is a polygon where all side lengths are greater than zero, no three vertices are collinear, and all interior angles are strictly less than 180180^\circ.

Input Format

This problem contains multiple test cases.

The first line contains a positive integer tt (1t105)(1 \le t \le 10^5), representing the number of test cases.

For each test case:

  • The first line contains a positive integer nn (3n5105)(3 \le n \le 5\cdot10^5).
  • The second line contains nn positive integers a1,,ana_1, \dots, a_n (1ai109)(1 \le a_i \le 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 51055\cdot10^5.

Output Format

For each test case, output one line:

  • If no such subset exists, output a single integer 00.
  • If such a subset exists, first output an integer kk, representing the size of the subset you found, followed by kk integers b1,,bkb_1, \dots, b_k, representing the lengths of the kk sticks in your subset.
3
4
6 9 2 6
3
4 4 9
6
3 1 4 6 5 9
3 6 2 6
0
4 3 4 5 6

Hint

For the first test case:

  • {6,2,6}\{6,2,6\} is a valid subset; since 2+6>62 + 6 > 6, these 33 sticks can form a non-degenerate triangle; it is easy to prove that no larger valid subset exists.
  • {6,6,9}\{6,6,9\} is also a valid subset.

For the second test case:

  • It can be proven that no valid subset exists.

For the third test case:

  • {3,4,5,6}\{3,4,5,6\} is a valid subset; in this case, Yuki has 55 ways to choose sticks: $\{3,4,5\}, \{3,4,6\}, \{3,5,6\}, \{4,5,6\}, \{3,4,5,6\}$, and each way can form a non-degenerate convex polygon; it is easy to prove that no larger valid subset exists.
  • {3,4,5,6,9}\{3,4,5,6,9\} is not a valid subset because the sticks with lengths 3,4,93, 4, 9 cannot form a non-degenerate triangle.
  • {3,5,6}\{3,5,6\} is not a valid subset because there exists a larger valid subset.