CF1472B.Fair Division
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alice and Bob received n candies from their parents. Each candy weighs either 1 gram or 2 grams. Now they want to divide all candies among themselves fairly so that the total weight of Alice's candies is equal to the total weight of Bob's candies.
Check if they can do that.
Note that candies are not allowed to be cut in half.
输入格式
The first line contains one integer t ( 1≤t≤104 ) — the number of test cases. Then t test cases follow.
The first line of each test case contains an integer n ( 1≤n≤100 ) — the number of candies that Alice and Bob received.
The next line contains n integers a1,a2,…,an — the weights of the candies. The weight of each candy is either 1 or 2 .
It is guaranteed that the sum of n over all test cases does not exceed 105 .
输出格式
For each test case, output on a separate line:
- "YES", if all candies can be divided into two sets with the same weight;
- "NO" otherwise.
You can output "YES" and "NO" in any case (for example, the strings yEs, yes, Yes and YES will be recognized as positive).
输入输出样例
输入#1
5 2 1 1 2 1 2 4 1 2 1 2 3 2 2 2 3 2 1 2
输出#1
YES NO YES NO NO
说明/提示
In the first test case, Alice and Bob can each take one candy, then both will have a total weight of 1 .
In the second test case, any division will be unfair.
In the third test case, both Alice and Bob can take two candies, one of weight 1 and one of weight 2 .
In the fourth test case, it is impossible to divide three identical candies between two people.
In the fifth test case, any division will also be unfair.