You are given a sorted array of $n$ integers, and a number $k$ that represents the number of partitions you must split the array into.
The elements of one partition must form a contiguous part of the array. Each element in the array must belong to exactly one partition.
For each partition from left to right, you are given one piece of information about it: value $x$ appears exactly $y$ times in this partition.
Find if it is possible to split the array into $k$ partitions, such that each partition satisfies the given information about it.
The first line of input contains a single integer $T$ ($1 \le T \le 10^5$), the number of test cases.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 10^5$), the number of elements in the array and the number of partitions, respectively.
The second line contains $n$ sorted integers $a_1$, $a_2$, $\dots$, $a_n$ ($1 \leq a_i \leq n$), the element of the array. It is guaranteed that ($a_{i - 1} \le a_i$) for all $i$ ($i > 1$).
Each of the following $k$ lines contains two integers $x_i$ and $y_i$ ($1 \le x_i, y_i \le n$), representing that the value $x_i$ must appear $y_i$ times in the $i^{th}$ partition from left.
The total sum of $n$ over all test cases doesn't exceed $10^6$.
For each test case, print a single line containing yes
if it is possible to partition the array. Otherwise, print no
. The output is case insensitive.
In the first test case, we can split the array in this way: $1$ $1$ $|$ $1$ $3$ $3$ $4$ $7$ $|$ $7$ $7$, the first partition has two $1$s, the second partition has two $3$s, and the last partition has two $7$s, as required.
Input | Output |
---|---|
3 9 3 1 1 1 3 3 4 7 7 7 1 2 3 2 7 2 5 2 3 3 5 5 5 5 3 3 2 4 2 1 1 2 2 1 1 2 3 Copy
|
yes no no Copy
|