CF2126B.No Casino in the Mountains

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

No Casino in the Mountains

You are given an array aa of nn numbers and a number kk. The value aia_i describes the weather on the ii-th day: if it rains on the ii-th day, then ai=1a_i = 1; otherwise, if the weather is good on the ii-th day, then ai=0a_i = 0.

Jean wants to visit as many peaks as possible. One hike to a peak takes exactly kk days, and during each of these days, the weather must be good (ai=0a_i = 0). That is, formally, he can start a hike on day ii only if all aj=0a_j = 0 for all jj (iji+k1)(i \leq j \leq i + k - 1).

After each hike, before starting the next one, Jean must take a break of at least one day, meaning that on the day following a hike, he cannot go on another hike.

Find the maximum number of peaks that Jean can visit.

Input

Each test consists of several test cases. The first line contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers nn and kk (1n1051 \le n \le 10^5, 1kn1 \le k \le n).

The second line contains nn numbers aia_i (ai{0,1}a_i \in \{0, 1\}), where aia_i denotes the weather on the ii-th day.

It is guaranteed that the total value of nn across all test cases does not exceed 10510^5.

Output

For each test case, output a single integer: the maximum number of hikes that Jean can make.

Note

In the first sample:

  • Day 11 — good weather, Jean goes on a hike. (a1=0a_1 = 0)
  • Day 22 — mandatory break.
  • Day 33 — again good weather, Jean goes on the second hike. (a3=0a_3 = 0)
  • Day 44 — break.
  • Day 55 — good weather, third hike. (a5=0a_5 = 0)

Thus, Jean can make 3 hikes, alternating each with a mandatory day of rest.

In the second sample:

  • From day 11 to day 33 — three days of good weather, Jean goes on a hike. (a1=a2=a3=0a_1 = a_2 = a_3 = 0)
  • Day 44 — mandatory break.
  • From day 55 to day 77 — again three days of good weather, Jean goes on the second hike. (a5=a6=a7=0a_5 = a_6 = a_7 = 0)

In total, Jean makes 2 hikes.

In the third sample:

  • There are no days with good weather (ai=1a_i = 1 for all ii)

Jean cannot make any hikes. Answer: 0

Samples

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

在线编程 IDE

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