#P1381B. Unmerge
Unmerge
No submission language available for this problem.
Description
Let and be two arrays of lengths and , respectively, with no elements in common. We can define a new array of length recursively as follows:
- If one of the arrays is empty, the result is the other array. That is, and . In particular, .
- If both arrays are non-empty, and , then . That is, we delete the first element of , merge the remaining arrays, then add to the beginning of the result.
- If both arrays are non-empty, and , then . That is, we delete the first element of , merge the remaining arrays, then add to the beginning of the result.
This algorithm has the nice property that if and are sorted, then will also be sorted. For example, it is used as a subroutine in merge-sort. For this problem, however, we will consider the same procedure acting on non-sorted arrays as well. For example, if and , then .
A permutation is an array consisting of distinct integers from to in arbitrary order. For example, is a permutation, but is not a permutation ( appears twice in the array) and is also not a permutation ( but there is in the array).
There is a permutation of length . Determine if there exist two arrays and , each of length and with no elements in common, so that .
The first line contains a single integer () — the number of test cases. Next lines contain descriptions of test cases.
The first line of each test case contains a single integer ().
The second line of each test case contains integers (). It is guaranteed that is a permutation.
It is guaranteed that the sum of across all test cases does not exceed .
For each test case, output "YES" if there exist arrays , , each of length and with no common elements, so that . Otherwise, output "NO".
Input
The first line contains a single integer () — the number of test cases. Next lines contain descriptions of test cases.
The first line of each test case contains a single integer ().
The second line of each test case contains integers (). It is guaranteed that is a permutation.
It is guaranteed that the sum of across all test cases does not exceed .
Output
For each test case, output "YES" if there exist arrays , , each of length and with no common elements, so that . Otherwise, output "NO".
Samples
Note
In the first test case, .
In the second test case, we can show that is not the merge of two arrays of length .
In the third test case, .
In the fourth test case, , for example.