#C13. Pirate Arrangement

    ID: 42488 Type: Default 1000ms 256MiB

Pirate Arrangement

Pirate Arrangement

You are given several test cases. In each test case, you are provided with a list of integers that represent the trust levels of pirates. The task is to determine if the pirates can be arranged in a circle such that no pirate is more trusted than both of his neighbors.

After sorting the list of trust levels in non-decreasing order, a necessary and sufficient condition for a valid circular arrangement is that the largest trust level is not greater than the sum of the second and third largest trust levels. In other words, if the sorted list is \(A_0 \leq A_1 \leq \cdots \leq A_{N-1}\), then an arrangement is possible if and only if \[ A_{N-1} \leq A_{N-2} + A_{N-3} \] where \(N\) is the number of pirates (with \(N \geq 3\)).

If the condition holds, output YES; otherwise, output NO.

inputFormat

The input is given via standard input (stdin). The first line contains a single integer (T) (1 ≤ (T) ≤ 104), representing the number of test cases. Each test case consists of two lines:

  1. The first line of each test case contains an integer (N) (3 ≤ (N) ≤ 105), denoting the number of pirates.
  2. The second line contains (N) space-separated integers, where each integer denotes the trust level of a pirate. It is guaranteed that the sum of all (N) over all test cases does not exceed 106.

outputFormat

For each test case, print a single line on standard output (stdout) containing either 'YES' if a valid circular arrangement exists, or 'NO' otherwise.## sample

1
5
1 2 3 4 5
YES

</p>