CF1472B.Fair Division

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alice and Bob received nn 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.

爱丽丝和鲍勃从父母那里收到了 nn 颗糖果。每颗糖果的重量要么是 1 克,要么是 2 克。现在他们希望将所有糖果公平地分给自己,使得爱丽丝所获得糖果的总重量等于鲍勃所获得糖果的总重量。

请判断他们是否能做到这一点。

注意:糖果不允许被切成两半。

输入格式

The first line contains one integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. Then tt test cases follow.

The first line of each test case contains an integer nn (1≤n≤1001 \le n \le 100) — the number of candies that Alice and Bob received.

The next line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n — the weights of the candies. The weight of each candy is either 11 or 22.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。随后是 tt 个测试用例。

每个测试用例的第一行包含一个整数 nn(1≤n≤1001 \le n \le 100)—— 表示 Alice 和 Bob 收到的糖果数量。

下一行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n —— 表示各颗糖果的重量。每颗糖果的重量为 11 或 22。

保证所有测试用例的 nn 之和不超过 10510^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";
  • 否则输出 "NO"。

你可以以任意大小写形式输出 "YES" 和 "NO"(例如,字符串 yEs、yes、Yes 和 YES 均会被识别为肯定回答)。

输入输出样例

  • 输入#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 11.

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 11 and one of weight 22.

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.

在第一个测试用例中,Alice 和 Bob 各取一颗糖果,此时两人的总重量均为 11。

在第二个测试用例中,任何分配方式都是不公平的。

在第三个测试用例中,Alice 和 Bob 各取两颗糖果,其中一颗重量为 11,另一颗重量为 22。

在第四个测试用例中,无法将三颗完全相同的糖果公平地分给两个人。

在第五个测试用例中,任何分配方式也都是不公平的。

输入解题思路,AI测评打分。不知道怎么写?

首页