CF1646B.Quality vs Quantity

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Quality vs Quantity

$\def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}}$ \def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}

You are given a sequence of nn non-negative integers a1,a2,,ana_1, a_2, \ldots, a_n. Initially, all the elements of the sequence are unpainted. You can paint each number \RED\RED or \BLUE\BLUE (but not both), or leave it unpainted.

For a color cc, Count(c)\text{Count}(c) is the number of elements in the sequence painted with that color and Sum(c)\text{Sum}(c) is the sum of the elements in the sequence painted with that color.

For example, if the given sequence is [2,8,6,3,1][2, 8, 6, 3, 1] and it is painted this way: [\myblue2,8,\myred6,\myblue3,1][\myblue{2}, 8, \myred{6}, \myblue{3}, 1] (where 66 is painted red, 22 and 33 are painted blue, 11 and 88 are unpainted) then Sum(\RED)=6\text{Sum}(\RED)=6, Sum(\BLUE)=2+3=5\text{Sum}(\BLUE)=2+3=5, Count(\RED)=1\text{Count}(\RED)=1, and Count(\BLUE)=2\text{Count}(\BLUE)=2.

Determine if it is possible to paint the sequence so that Sum(\RED)>Sum(\BLUE)\text{Sum}(\RED) \gt \text{Sum}(\BLUE) and Count(\RED)<Count(\BLUE)\text{Count}(\RED) \lt \text{Count}(\BLUE).

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t10001 \le t \le 1000). Description of the test cases follows.

The first line of each test case contains an integer nn (3n21053\le n\le 2\cdot 10^5) — the length of the given sequence.

The second line of each test case contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n (0ai1090\le a_i\le 10^9) — the given sequence.

It is guaranteed that the sum of nn over all test cases does not exceed 21052\cdot 10^5.

Output

For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise.

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

Note

In the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: [\myblue1,\myblue2,\myred3][\myblue{1},\myblue{2},\myred{3}] (where 33 is painted red, 11 and 22 are painted blue) then Count(\RED)=1<Count(\BLUE)=2\text{Count}(\RED)=1 \lt \text{Count}(\BLUE)=2, but Sum(\RED)=3Sum(\BLUE)=3\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3. So, this is not a possible way to paint the sequence.

In the second test case, a possible way to paint the sequence is described in the statement. We can see that Sum(\RED)=6>Sum(\BLUE)=5\text{Sum}(\RED)=6 \gt \text{Sum}(\BLUE)=5 and Count(\RED)=1<Count(\BLUE)=2\text{Count}(\RED)=1 \lt \text{Count}(\BLUE)=2.

In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: [\myred3,\myred5,\myblue4,\myblue2][\myred{3},\myred{5},\myblue{4}, \myblue{2}] (where 33 and 55 are painted red, 44 and 22 are painted blue) then Sum(\RED)=8>Sum(\BLUE)=6\text{Sum}(\RED) = 8 \gt \text{Sum}(\BLUE) = 6 but $\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$. So, this is not a possible way to paint the sequence.

In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.

Samples

4
3
1 2 3
5
2 8 6 3 1
4
3 5 4 2
5
1000000000 1000000000 1000000000 1000000000 1000000000
NO
YES
NO
NO

在线编程 IDE

建议全屏模式获得最佳体验