#K67807. Coin Sequence Arrangement

    ID: 32724 Type: Default 1000ms 256MiB

Coin Sequence Arrangement

Coin Sequence Arrangement

Vlad has a collection of coins of different types. For each test case, you are given an integer (n) which denotes the number of distinct coin types, followed by a list of (n) integers where the (i^{th}) integer represents the number of coins available of the (i^{th}) type. Vlad wants to arrange all the coins in a sequence such that no two adjacent coins are of the same type. It can be proven that a necessary and sufficient condition for such an arrangement to exist is:

[ \max{a_i} \leq \left(\sum_{i=1}^n a_i - \max{a_i}\right) + 1 ]

If the condition holds, then an arrangement is possible and you should output "YES"; otherwise, output "NO".

Note: There may be multiple test cases.

inputFormat

The input is read from standard input. The first line contains an integer (T) representing the number of test cases. Each test case consists of two lines:

  • The first line contains an integer (n), the number of coin types.
  • The second line contains (n) space-separated integers, where the (i^{th}) integer is the number of coins of the (i^{th}) type.

outputFormat

For each test case, output a single line containing either "YES" if an arrangement is possible, or "NO" otherwise.## sample

4
2
1 1
3
3 1 2
4
2 3 1 1
1
10
YES

YES YES NO

</p>