CF1698B.Rising Sand

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 < i < n and ai>ai1+ai+1a_i > 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?

输入格式

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 .

输出格式

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

输入输出样例

  • 输入#1

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

    输出#1

    2
    0
    1

说明/提示

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 .

首页