CF1746A.Maxmina

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

Maxmina

You have an array aa of size nn consisting only of zeroes and ones and an integer kk. In one operation you can do one of the following:

  • Select 22 consecutive elements of aa and replace them with their minimum (that is, let $a := [a_{1}, a_{2}, \ldots, a_{i-1}, \min(a_{i}, a_{i+1}), a_{i+2}, \ldots, a_{n}]$ for some 1in11 \le i \le n-1). This operation decreases the size of aa by 11.
  • Select kk consecutive elements of aa and replace them with their maximum (that is, let $a := [a_{1}, a_{2}, \ldots, a_{i-1}, \max(a_{i}, a_{i+1}, \ldots, a_{i+k-1}), a_{i+k}, \ldots, a_{n}]$ for some 1ink+11 \le i \le n-k+1). This operation decreases the size of aa by k1k-1.

Determine if it's possible to turn aa into [1][1] after several (possibly zero) operations.

Input

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

The first line of each test case contains two integers nn and kk (2kn502 \le k \le n \le 50), the size of array aa and the length of segments that you can perform second type operation on.

The second line contains nn integers a1,a2,,ana_{1}, a_{2}, \ldots, a_{n} (aia_i is 00 or 11), elements of array aa.

Output

For each test case, if it is possible to turn aa into [1][1], print "YES", otherwise print "NO".

Note

In the first test case, you can perform the second type operation on second and third elements so aa becomes [0,1][0, 1], then you can perform the second type operation on first and second elements, so aa turns to [1][1].

In the fourth test case, it's obvious to see that you can't make any 11, no matter what you do.

In the fifth test case, you can first perform a type 2 operation on the first three elements so that aa becomes [1,0,0,1][1, 0, 0, 1], then perform a type 2 operation on the elements in positions two through four, so that aa becomes [1,1][1, 1], and finally perform the first type operation on the remaining elements, so that aa becomes [1][1].

Samples

7
3 2
0 1 0
5 3
1 0 1 1 0
2 2
1 1
4 4
0 0 0 0
6 3
0 0 1 0 0 1
7 5
1 1 1 1 1 1 1
5 3
0 0 1 0 0
YES
YES
YES
NO
YES
YES
YES

在线编程 IDE

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