Problems
Bessie is learning to code using a simple programming language. In this language, a program is a nonempty sequence of statements. A statement is one of the following:
PRINT c: where c is an integer.
REP o: followed by a program and then an END; here o is an integer that is at least 1.
When a program is executed, its statements run sequentially. Executing a PRINT c statement appends c to the output sequence, while executing a REP o statement causes the enclosed program to be executed o times in sequence.
For example, consider the following program:
REP 3
PRINT 1
REP 2
PRINT 2
END
END
This program outputs the sequence [1, 2, 2, 1, 2, 2, 1, 2, 2].
Now, Bessie wants to output a sequence of N positive integers (1 ≤ N ≤ 100). Elsie challenges her to write a program that uses at most K "PRINT" statements (1 ≤ K ≤ 3). Bessie may use as many REP statements as she wishes, and every integer in the sequence is guaranteed to be at most K. For each of T (1 ≤ T ≤ 100) independent test cases, decide whether Bessie can write a program that outputs the given sequence using no more than K PRINT statements.
Input
The first line contains an integer T.
For each test case:
The first line contains two space-separated integers, N and K.
The second line contains N space-separated positive integers (each at most K), which is the sequence that Bessie wants to produce.
Output
For each test case, output either "YES" or "NO" (case sensitive) on a separate line.
Subtask
| # | Score | Condition |
|---|---|---|
| #1 | 20 | |
| #2 | 30 | |
| #3 | 50 | No additional constraints. |
Example #1
2
1 1
1
4 1
1 1 1 1
YES
YES
Example #2
11
4 2
1 2 2 2
4 2
1 1 2 1
4 2
1 1 2 2
6 2
1 1 2 2 1 1
10 2
1 1 1 2 2 1 1 1 2 2
8 3
3 3 1 2 2 1 2 2
9 3
1 1 2 2 2 3 3 3 3
16 3
2 2 3 2 2 3 1 1 2 2 3 2 2 3 1 1
24 3
1 1 2 2 3 3 3 2 2 3 3 3 1 1 2 2 3 3 3 2 2 3 3 3
9 3
1 2 2 1 3 3 1 2 2
6 3
1 2 1 2 2 3
YES
NO
YES
NO
YES
YES
YES
YES
YES
NO
NO