CF2053A.Tender Carpenter

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

Tender Carpenter

I would use a firework to announce, a wave to bid farewell, and a bow to say thanks: bygones are bygones; not only on the following path will I be walking leisurely and joyfully, but also the footsteps won't halt as time never leaves out flowing; for in the next year, we will meet again.— Cocoly1990, Goodbye 2022

In his dream, Cocoly would go on a long holiday with no worries around him. So he would try out for many new things, such as... being a carpenter. To learn it well, Cocoly decides to become an apprentice of Master, but in front of him lies a hard task waiting for him to solve.

Cocoly is given an array a1,a2,,ana_1, a_2,\ldots, a_n. Master calls a set of integers SS stable if and only if, for any possible uu, vv, and ww from the set SS (note that uu, vv, and ww do not necessarily have to be pairwise distinct), sticks of length uu, vv, and ww can form a non-degenerate triangle^{\text{∗}}.

Cocoly is asked to partition the array aa into several (possibly, 11 or nn) non-empty continuous subsegments^{\text{†}}, such that: for each of the subsegments, the set containing all the elements in it is stable.

Master wants Cocoly to partition aa in at least two different^{\text{‡}} ways. You have to help him determine whether it is possible.

^{\text{∗}}A triangle with side lengths xx, yy, and zz is called non-degenerate if and only if:

  • x+y>zx + y \gt z,
  • y+z>xy + z \gt x, and
  • z+x>yz + x \gt y.

^{\text{†}}A sequence bb is a subsegment of a sequence cc if bb can be obtained from cc by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

^{\text{‡}}Two partitions are considered different if and only if at least one of the following holds:

  • the numbers of continuous subsegments split in two partitions are different;
  • there is an integer kk such that the lengths of the kk-th subsegment in two partitions are different.

Input

Each test contains multiple test cases. The first line of the input contains a single integer tt (1t2001 \leq t \leq 200) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn (2n2002 \leq n \leq 200) — the length of the array aa.

The second line contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n (1ai1051 \leq a_i \leq 10^5) — the elements in the array aa.

Output

For each test case, print YES if there are at least two ways to partition aa, and NO otherwise.

You can output the answer in any case (upper or lower). For example, the strings yEs, yes, Yes, and YES will be recognized as positive responses.

Note

In the first test case, here are two possible partitions:

  • [2,3],[5,7][2, 3], [5, 7], since
    • [2,3][2, 3] is stable because sticks of lengths (2,2,2),(2,2,3),(2,3,3),(3,3,3)(2, 2, 2), (2, 2, 3), (2, 3, 3), (3, 3, 3) respectively can all form non-degenerate triangles.
    • [5,7][5, 7] is stable because sticks of lengths (5,5,5),(5,5,7),(5,7,7),(7,7,7)(5, 5, 5), (5, 5, 7), (5, 7, 7), (7, 7, 7) respectively can all form non-degenerate triangles.
  • and [2],[3,5],[7][2], [3, 5], [7], since
    • [2][2] is stable because sticks of lengths (2,2,2)(2, 2, 2) respectively can form a non-degenerate triangle.
    • [3,5][3, 5] is stable because sticks of lengths (3,3,3),(3,3,5),(3,5,5),(5,5,5)(3, 3, 3), (3, 3, 5), (3, 5, 5), (5, 5, 5) respectively can all form non-degenerate triangles.
    • [7][7] is stable because sticks of lengths (7,7,7)(7, 7, 7) respectively can form a non-degenerate triangle.

Note that some other partitions also satisfy the constraints, such as [2],[3],[5],[7][2], [3], [5], [7] and [2],[3],[5,7][2], [3], [5, 7].

In the second test case, Cocoly can only partition each element as a single subsegment, resulting in [115],[9],[2],[28][115], [9], [2], [28]. Since we only have one possible partition, the answer is NO.

In the third test case, please note that the partition [8,4],[1],[6],[2][8, 4], [1], [6], [2] does not satisfy the constraints, because {8,4}\{8, 4\} is not a stable set: sticks of lengths 44, 44, and 88 cannot form a non-degenerate triangle.

Samples

5
4
2 3 5 7
4
115 9 2 28
5
8 4 1 6 2
6
1 5 4 1 4 7
2
100000 100000
YES
NO
NO
YES
YES

在线编程 IDE

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