308139: CF1472B. Fair Division

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Fair Division

题意翻译

### 题目描述 Alice 和 Bob 从他们的父母那里收到 $n$ 颗糖果。每一颗糖果重达 $1$ 或 $2$ 克。现在,他们想要公平地将糖果分为两组,使得两组糖果的重量只和相等。 请你判断是否可以实现。注意,糖果都不能被切成两半。 ### 输入格式 输入第一行一个整数 $t$($1\le t\le 10^4$),表示测试数据的组数。 接下来,每组数据第一行一个整数 $n$($1\le n\le 100$),表示两人收到的糖果数量。 接下来一行 $n$ 个整数 $a_1,a_2,\dots,a_n$,表示每颗糖果的重量。糖果的重量为 $1$ 或 $2$。 ### 输出格式 输出共 $t$ 行。对于每组测试数据,输出一行一个字符串、如果可以分成重量相等的两组,则输出 `YES`,否则输出 `NO`。 translate by @[1289H2051N343O375S8](https://www.luogu.com.cn/user/45475)。

题目描述

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 \le t \le 10^4 $ ) — the number of test cases. Then $ t $ test cases follow. The first line of each test case contains an integer $ n $ ( $ 1 \le n \le 100 $ ) — the number of candies that Alice and Bob received. The next line contains $ n $ integers $ a_1, a_2, \ldots, a_n $ — 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 $ 10^5 $ .

输出格式


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.

Input

题意翻译

### 题目描述 Alice 和 Bob 从他们的父母那里收到 $n$ 颗糖果。每一颗糖果重达 $1$ 或 $2$ 克。现在,他们想要公平地将糖果分为两组,使得两组糖果的重量只和相等。 请你判断是否可以实现。注意,糖果都不能被切成两半。 ### 输入格式 输入第一行一个整数 $t$($1\le t\le 10^4$),表示测试数据的组数。 接下来,每组数据第一行一个整数 $n$($1\le n\le 100$),表示两人收到的糖果数量。 接下来一行 $n$ 个整数 $a_1,a_2,\dots,a_n$,表示每颗糖果的重量。糖果的重量为 $1$ 或 $2$。 ### 输出格式 输出共 $t$ 行。对于每组测试数据,输出一行一个字符串、如果可以分成重量相等的两组,则输出 `YES`,否则输出 `NO`。 translate by @[1289H2051N343O375S8](https://www.luogu.com.cn/user/45475)。

加入题单

算法标签: