F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Equalize the Array

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 431    Accepted Submission(s): 204


Problem Description
You are given an array $a$ consisting of $n$ integers.

In one move, you can choose a positive integer $x$, such that $x$ is one of the modes of the array, then add $1$ to each $x$ in $a$.

An integer $x$ is a mode of an array $a$ if and only if $x$ appears most frequently in $a$. Note that an array may have multiple modes (e.g. $2,3$ are both the modes of $[2,2,1,3,3]$).

Find out if it is possible to get an array that all elements in it are equal through several (possibly zero) such moves.
 

Input
The first line contains a single integer $T$ ($1\le T\le 100$), denoting the number of test cases.

For each test case, the first line contains an integer $n$ ($1\le n\le 5\cdot 10^5$).

The next line contains $n$ integers. The $i$-th number denotes $a_i$ ($1\le a_i\le n$).

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.
 

Output
For each test case, output a string. If it is possible, output `YES`; otherwise, output `NO`.
 

Sample Input
3 5 1 2 3 4 5 5 4 4 1 4 4 4 2 2 2 2
 

Sample Output
YES NO YES
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-19 09:47:50, Gzip enabled