A14007 | Fair Division
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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$ .
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).
- "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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted