CF1698B.Rising Sand
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n piles of sand where the i -th pile has ai blocks of sand. The i -th pile is called too tall if 1<i<n and ai>ai−1+ai+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 k . An operation consists of picking k consecutive piles of sand and adding one unit of sand to them all. Formally, pick 1≤l,r≤n such that r−l+1=k . Then for all l≤i≤r , update ai←ai+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 t ( 1≤t≤1000 ) — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers n and k ( 3≤n≤2⋅105 ; 1≤k≤n ) — the number of piles of sand and the size of the operation, respectively.
The second line of each test case contains n integers a1,a2,…,an ( 1≤ai≤109 ) — the sizes of the piles.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105 .
输出格式
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 1 and 2 : [3,10,2,4,1] .
- Add one unit of sand to piles 4 and 5 : [3,10,2,5,2] .
- Add one unit of sand to piles 3 and 4 : [3,10,3,6,2] .
Now piles 2 and 4 are too tall, so in this case the answer is 2 . It can be shown that it is impossible to make more than 2 piles too tall.In the second test case, any operation will increase all piles by 1 unit, so the number of too tall piles will always be 0 .
In the third test case, we can increase any pile by 1 unit of sand. It can be shown that the maximum number of too tall piles is 1 .