CF2220A.Blocked
入门
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Given an array $ a $ of integers of size $ n $ , we say that a position $ 1 \le i \le n $ is blocked if $ a_i $ can be expressed as the sum of a subset of $ a_1, a_2, \ldots, a_{i-1} $ (i.e. there exist $ 1 \le j_1 \lt j_2 \lt \ldots \lt j_k \le i-1 $ such that $ a_{j_1} + a_{j_2} + \ldots + a_{j_k} = a_i $ ). Reorder $ a $ so that no position is blocked or report that it is impossible.
For example, reordering the array [ $ 3, 2, 5 $ ] to [ $ 2, 3, 5 $ ] makes position $ 3 $ blocked, since we can express $ 5 = 2 + 3 $ , but if we reorder it to [ $ 3, 5, 2 $ ], no position is blocked.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 400 $ ). The description of the test cases follows.
The first line of each test case contains an integer $ n $ ( $ 1 \le n \le 200 $ ).
The second line contains $ n $ integers, denoting the array $ a $ ( $ \textbf{1} \le a_i \le 100 $ ).
输出格式
For each test case, print any order of $ a $ such that no position is blocked if it exists, otherwise print $ -1 $ .
输入输出样例
输入#1
4 3 1 5 9 4 1 3 3 2 3 1 2 3 1 1
输出#1
5 9 1 -1 3 1 2 1
说明/提示
In the third test case, the array [ $ 3, 1, 2 $ ] has no position blocked:
Position $ 1 $ is not blocked since $ 3 $ can't be expressed as the sum of a subset of [].
Position $ 2 $ is not blocked since $ 1 $ can't be expressed as the sum of a subset of [ $ 3 $ ].
Position $ 3 $ is not blocked since $ 2 $ can't be expressed as the sum of a subset of [ $ 3, 1 $ ].
输入解题思路,AI测评打分。不知道怎么写?