QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#6965. 使数组相等

Statistics

给定一个包含 $n$ 个整数的数组 $a$。

在一次操作中,你可以选择一个正整数 $x$,使得 $x$ 是当前数组的众数之一,然后将数组中所有的 $x$ 加 $1$。

整数 $x$ 是数组 $a$ 的众数,当且仅当 $x$ 在 $a$ 中出现的次数最多。注意,一个数组可能有多个众数(例如,在 $[2, 2, 1, 3, 3]$ 中,$2$ 和 $3$ 都是众数)。

请判断是否可以通过若干次(可能为零次)上述操作,使得数组中所有的元素都相等。

输入格式

第一行包含一个整数 $T$ ($1 \le T \le 100$),表示测试用例的数量。

对于每个测试用例,第一行包含一个整数 $n$ ($1 \le n \le 10^6$)。

第二行包含 $n$ 个整数,第 $i$ 个数表示 $a_i$ ($1 \le a_i \le n$)。

保证所有测试用例的 $n$ 之和不超过 $2 \cdot 10^6$。

输出格式

对于每个测试用例,输出一个字符串。如果可能,输出 YES;否则,输出 NO

样例

样例输入 1

3
5
1 2 3 4 5
5
4 4 1 4 4
4
2 2 2 2

样例输出 1

YES
NO
YES

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.