CF1698B.Rising Sand

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

Rising Sand

There are nn piles of sand where the ii-th pile has aia_i blocks of sand. The ii-th pile is called too tall if 1<i<n1 \lt i \lt n and ai>ai1+ai+1a_i \gt a_{i-1} + a_{i+1}. That is, a pile is too tall if it has more sand than its two neighbours combined. (Note that piles on the ends of the array cannot be too tall.)

You are given an integer kk. An operation consists of picking kk consecutive piles of sand and adding one unit of sand to them all. Formally, pick 1l,rn1 \leq l,r \leq n such that rl+1=kr-l+1=k. Then for all lirl \leq i \leq r, update aiai+1a_i \gets a_i+1.

What is the maximum number of piles that can simultaneously be too tall after some (possibly zero) operations?

Input

The input consists of multiple test cases. The first line contains an integer tt (1t10001 \leq t \leq 1000) — 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 (3n21053 \leq n \leq 2 \cdot 10^5; 1kn1 \leq k \leq n) — the number of piles of sand and the size of the operation, respectively.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1091 \le a_i \le 10^9) — the sizes of the piles.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, output a single integer — the maximum number of piles that are simultaneously too tall after some (possibly zero) operations.

Note

In the first test case, we can perform the following three operations:

  • Add one unit of sand to piles 11 and 22: [3,10,2,4,1][\color{red}{3}, \color{red}{10}, 2, 4, 1].
  • Add one unit of sand to piles 44 and 55: [3,10,2,5,2][3, 10, 2, \color{red}{5}, \color{red}{2}].
  • Add one unit of sand to piles 33 and 44: [3,10,3,6,2][3, 10, \color{red}{3}, \color{red}{6}, 2].

Now piles 22 and 44 are too tall, so in this case the answer is 22. It can be shown that it is impossible to make more than 22 piles too tall.

In the second test case, any operation will increase all piles by 11 unit, so the number of too tall piles will always be 00.

In the third test case, we can increase any pile by 11 unit of sand. It can be shown that the maximum number of too tall piles is 11.

Samples

3
5 2
2 9 2 4 1
4 4
1 3 2 1
3 1
1 3 1
2
0
1

在线编程 IDE

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