1D Eraser

1D Eraser

Problem

You are given a strip of paper s that is n cells long. Each cell is either black or white. In an operation you can take any k consecutive cells and make them all white.

Find the minimum number of operations needed to remove all black cells.

Input

The first line contains a single integer ttt (1≤t≤1000)(1≤t≤1000)(1t1000) — the number of test cases.

The first line of each test case contains two integers nnn and kkk (1≤k≤n≤2⋅105)(1≤k≤n≤2⋅10^5)(1kn2105) — the length of the paper and the integer used in the operation.

The second line of each test case contains a string s of length n consisting of characters B
(representing a black cell) or W (representing a white cell).

The sum of n over all test cases does not exceed 2⋅1052⋅10^52105.

Output

For each test case, output a single integer — the minimum number of operations needed to remove all black cells.

Example

Input
8
6 3
WBWWWB
7 3
WWBWBWW
5 4
BWBWB
5 5
BBBBB
8 2
BWBWBBBB
10 2
WBBWBBWBBW
4 1
BBBB
3 2
WWW
Output
2
1
2
1
4
3
4
0

Note

  • In the first test case you can perform the following operations:
    WBWWWB→WWWWWB→WWWWWW
  • In the second test case you can perform the following operations:
    WWBWBWW→WWWWWWW
  • In the third test case you can perform the following operations:
    BWBWBBWWWW→WWWWW

Code

// #include <iostream>
// #include <algorithm>
// #include <cstring>
// #include <sstream>//整型转字符串
// #include <stack>//栈
// #include <deque>//堆/优先队列
// #include <queue>//队列
// #include <map>//映射
// #include <unordered_map>//哈希表
// #include <vector>//容器,存数组的数,表数组的长度
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll N=2e5+10;
ll a[N];

int main()
{
    ll t;
    cin>>t;

    while(t--)
    {
        ll n,k;
        cin>>n>>k;
        string s;
        cin>>s;

        ll sum=0;
        for(ll i=0,j=0;i<n;i++)
        {
            if(s[i]=='B')
            {
                sum++;
                while(j-i<k) j++;
                i=j-1;
            }
            else j++;
        }

        cout<<sum<<endl;
    }
    
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Pretty Boy Fox

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值