B. Rising Sand

Problem - B - Codeforces

There are nn piles of sand where the ii-th pile has aiai blocks of sand. The ii-th pile is called too tall if 1<i<n1<i<n and ai>ai−1+ai+1ai>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 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≤l,r≤n such that r−l+1=kr−l+1=k. Then for all l≤i≤rl≤i≤r, update ai←ai+1ai←ai+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 (1≤t≤10001≤t≤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≤n≤2⋅105; 1≤k≤n1≤k≤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,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the sizes of the piles.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅105.

Output

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

Example

input

Copy

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

output

Copy

2
0
1

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][3,10,2,4,1].
  • Add one unit of sand to piles 44 and 55: [3,10,2,5,2][3,10,2,5,2].
  • Add one unit of sand to piles 33 and 44: [3,10,3,6,2][3,10,3,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.

 

 

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+10;
int t,n,k;
int a[N];
signed main()
{
  
    scanf("%lld",&t);
    while(t--)
    {
        int sum=0;
        scanf("%lld %lld",&n,&k);
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&a[i]);
        }
        if(k==1)
            sum=(n-1)/2;
        else
        {
            for(int i=2;i<=n-1;i++)
            {
                if(a[i]>a[i-1]+a[i+1])
                    sum++;
            }
        }
        printf("%lld\n",sum);
    }
    return 0;
}

题解:

第一步 :先获得性质:在m>=2的情况下你不可能加出tall数,因为你想加中间的数的时候你一定会加到左边或右边。
故对于m>=2的情况tall数等于不操作的tall数,直接暴力。再讨论m=1的情况,因为可以随便加,最大值明显为n中选不相邻的最大数=(n+1)/2,由于不能选1和n,故答案为(n-1)/2;
 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值