CF1297C Dream Team

题目描述

IT 公司的高管 Polycarp 要在 $n(2\le n\le 10^5)$ 名员工中选出一些来组成一个团队。每名员工有一个技能点数 $a(-10^4\le a_i\le 10^4)$。Polycarp 希望这些员工的 $a$ 值之和尽可能大,但是如果是最大的那种可能又会被其他同事排挤。所以,Polycarp 会这么选员工:他们的 $a$ 之和要是比最大值小的解中最大的(次优解)。 如果有多组解,输出其中任意一种即可。你可以认为 Polycarp 总是能选出一个非空的团队。

输入格式

第一行有一个整数 $t(1\le t\le10^4)$,表示输入样例的组数. 每组样例的第一行是 $n$。 接下来一行有 $n$ 个整数 $a$。 数据保证所有的 $n$ 之和不超过 $10^5$。

输出格式

输出共 $2\times t$ 行。每组数据的第一行是一个数 $s$,表示 Polycarp 选的员工数,第二行 $n$ 个整数,第 $i$ 个数是 $1$ 表示选了 $i$ 员工,反之亦然。

说明/提示

In the first test case, the maximum subset $ a_1, a_3, a_5 $ has a sum equal to $ 3 $ , so Polycarp should choose a team with the maximum total sum which is less than $ 3 $ . In the second test case, the maximum subset $ a_1, a_2 $ has a sum equal to $ 12 $ , so Polycarp should choose a team with the maximum total sum which is less than $ 12 $ . In the third test case, the maximum subset $ a_1, a_3 $ has a sum equal to $ 9 $ . In the fourth test case, the maximum subset $ a_1, a_2 $ has a sum equal to $ 8 $ . In the fifth test case, there are several subsets with a maximum sum equal to $ 3 $ , so Polycarp should choose a team with a lower total sum.