CF1698B.Rising Sand

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

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 \lt i \lt n and ai>ai−1+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 1≤l,r≤n1 \leq l,r \leq n such that r−l+1=kr-l+1=k. Then for all l≤i≤rl \leq i \leq r, update ai←ai+1a_i \gets a_i+1.

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

有 nn 堆沙子,其中第 ii 堆包含 aia_i 个沙块。若满足 1<i<n1 \lt i \lt n 且 ai>ai−1+ai+1a_i \gt a_{i-1} + a_{i+1},则称第 ii 堆沙子为「过高」。即:当某堆沙子的沙块数严格大于其左右两个相邻堆沙块数之和时,该堆即为过高。(注意:数组两端的堆不可能过高。)

给定一个整数 kk。一次操作定义为:选择 kk 个连续的沙堆,并向这 kk 个沙堆各添加一单位沙子。形式化地,选择满足 1≤l,r≤n1 \leq l,r \leq n 且 r−l+1=kr-l+1=k 的区间 [l,r][l, r];然后对所有 l≤i≤rl \leq i \leq r,执行更新 ai←ai+1a_i \gets a_i+1。

在经过若干次(可以为零次)操作后,最多能同时有多少堆沙子为「过高」?

输入格式

The input consists of multiple test cases. The first line contains an integer tt (1≤t≤10001 \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 (3≤n≤2⋅1053 \leq n \leq 2 \cdot 10^5; 1≤k≤n1 \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 (1≤ai≤1091 \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 2⋅1052 \cdot 10^5.

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 kk(3≤n≤2⋅1053 \leq n \leq 2 \cdot 10^5;1≤k≤n1 \leq k \leq n),分别表示沙堆的数量和操作的大小。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9),表示各沙堆的大小。

保证所有测试用例的 nn 值之和不超过 2⋅1052 \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.

对于每个测试用例,输出一个整数——在执行若干次(可能为零次)操作后,同时过高(too tall)的堆的最大数量。

输入输出样例

  • 输入#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.

在第一个测试用例中,我们可以执行以下三次操作:

  • 向第 11 和第 22 堆沙子各添加一单位沙子:[3,10,2,4,1][\color{red}{3}, \color{red}{10}, 2, 4, 1]。
  • 向第 44 和第 55 堆沙子各添加一单位沙子:[3,10,2,5,2][3, 10, 2, \color{red}{5}, \color{red}{2}]。
  • 向第 33 和第 44 堆沙子各添加一单位沙子:[3,10,3,6,2][3, 10, \color{red}{3}, \color{red}{6}, 2]。

此时,第 22 堆和第 44 堆沙子过高,因此本例的答案为 22。可以证明,无法使超过 22 堆沙子过高。

在第二个测试用例中,任意操作都会使所有沙堆高度增加 11 单位,因此过高沙堆的数量恒为 00。

在第三个测试用例中,我们可以将任意一堆沙子的高度增加 11 单位。可以证明,过高沙堆的最大数量为 11。

输入解题思路,AI测评打分。不知道怎么写?

首页