CF1660B.Vlad and Candies

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Not so long ago, Vlad had a birthday, for which he was presented with a package of candies. There were nn types of candies, there are aia_i candies of the type ii (1≤i≤n1 \le i \le n).

Vlad decided to eat exactly one candy every time, choosing any of the candies of a type that is currently the most frequent (if there are several such types, he can choose any of them). To get the maximum pleasure from eating, Vlad does not want to eat two candies of the same type in a row.

Help him figure out if he can eat all the candies without eating two identical candies in a row.

不久之前,弗拉德过生日,收到了一包糖果。共有 nn 种糖果,其中第 ii 种糖果有 aia_i 颗(1≤i≤n1 \le i \le n)。

弗拉德决定每次只吃一颗糖果,并且每次都从当前数量最多的糖果类型中任选一种(若存在多个数量最多的类型,则可任选其一)。为了获得最大的进食愉悦感,弗拉德不希望连续两次吃到同一种类的糖果。

请帮助他判断:能否在不连续吃到相同种类糖果的前提下,将所有糖果全部吃完?

输入格式

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

The following is a description of tt test cases of input, two lines for each.

The first line of the case contains the single number nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of types of candies in the package.

The second line of the case contains nn integers aia_i (1≤ai≤1091 \le a_i \le 10^9) — the number of candies of the type ii.

It is guaranteed that the sum of nn for all cases does not exceed 2⋅1052 \cdot 10^5.

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

接下来是 tt 个测试用例的描述,每个测试用例占两行。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 表示该糖果包中糖果种类的数量。

每个测试用例的第二行包含 nn 个整数 aia_i(1≤ai≤1091 \le a_i \le 10^9)—— 表示第 ii 种糖果的数量。

保证所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

Output tt lines, each of which contains the answer to the corresponding test case of input. As an answer, output "YES" if Vlad can eat candy as planned, and "NO" otherwise.

You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

输出 tt 行,每行包含对应输入测试用例的答案。若弗拉德能按计划吃糖果,则输出 "YES";否则输出 "NO"。

答案的大小写不限(例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 均被视为正确答案)。

输入输出样例

  • 输入#1

    6
    2
    2 3
    1
    2
    5
    1 6 2 4 3
    4
    2 2 2 1
    3
    1 1000000000 999999999
    1
    1

    输出#1

    YES
    NO
    NO
    YES
    YES
    YES

说明/提示

In the first example, it is necessary to eat sweets in this order:

  • a candy of the type 22, it is the most frequent, now a=[2,2]a = [2, 2];
  • a candy of the type 11, there are the same number of candies of the type 22, but we just ate one, now a=[1,2]a = [1, 2];
  • a candy of the type 22, it is the most frequent, now a=[1,1]a = [1, 1];
  • a candy of the type 11, now a=[0,1]a = [0, 1];
  • a candy of the type 22, now a=[0,0]a = [0, 0] and the candy has run out.

In the second example, all the candies are of the same type and it is impossible to eat them without eating two identical ones in a row.

In the third example, first of all, a candy of the type 22 will be eaten, after which this kind will remain the only kind that is the most frequent, and you will have to eat a candy of the type 22 again.

在第一个例子中,必须按以下顺序吃糖果:

  • 一颗类型为 22 的糖果(这是出现频率最高的类型),此时 a=[2,2]a = [2, 2];
  • 一颗类型为 11 的糖果(类型 22 和类型 11 当前数量相同,但我们刚刚吃掉了一颗类型 22 的糖果),此时 a=[1,2]a = [1, 2];
  • 一颗类型为 22 的糖果(这是当前出现频率最高的类型),此时 a=[1,1]a = [1, 1];
  • 一颗类型为 11 的糖果,此时 a=[0,1]a = [0, 1];
  • 一颗类型为 22 的糖果,此时 a=[0,0]a = [0, 0],糖果已全部吃完。

在第二个例子中,所有糖果均为同一类型,因此无法在不连续吃两颗相同类型糖果的情况下吃完所有糖果。

在第三个例子中,首先将吃掉一颗类型为 22 的糖果;此后,类型 22 将成为唯一出现频率最高的类型,因此接下来仍不得不吃一颗类型为 22 的糖果。

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

首页