B. Vaccination(cf)(贪心)

Ethan runs a vaccination station to help people combat the seasonal flu. He analyses the historical data in order to develop an optimal strategy for vaccine usage.

Consider there are 𝑛 patients coming to the station on a particular day. The 𝑖-th patient comes at the moment 𝑡𝑖. We know that each of these patients can be asked to wait for no more than 𝑤time moments. That means the 𝑖-th patient can get vaccine at moments 𝑡𝑖,𝑡𝑖+1,…,𝑡𝑖+𝑤.

Vaccines come in packs, each pack consists of 𝑘doses. Each patient needs exactly one dose. Packs are stored in a special fridge. After a pack is taken out of the fridge and opened, it can no longer be put back. The lifetime of the vaccine outside the fridge is 𝑑moments of time. Thus, if the pack was taken out of the fridge and opened at moment 𝑥, its doses can be used to vaccinate patients at moments 𝑥,𝑥+1,…,𝑥+𝑑. At moment 𝑥+𝑑+1 all the remaining unused doses of this pack are thrown away.

Assume that the vaccination station has enough staff to conduct an arbitrary number of operations at every moment of time. What is the minimum number of vaccine packs required to vaccinate all 𝑛 patients?

Input

The first line of the input contains the number of test cases 𝑡 (1≤𝑡≤104). Then follow 𝑡 descriptions of the test cases.

The first line of each test case contains four integers 𝑛, 𝑘, 𝑑and 𝑤 (1≤𝑛,𝑘≤2⋅105, 0≤𝑑,𝑤≤106). They are the number of patients, the number of doses per vaccine pack, the number of moments of time the vaccine can live outside the fridge, and the number of moments of time each of the patients can wait, respectively.

The second line of each test case contains a non-decreasing sequence 𝑡1,𝑡2,…,𝑡𝑛 (0≤𝑡1≤𝑡2≤…≤𝑡𝑛≤106). The 𝑖-th element of this sequence is the moment when the 𝑖-th patient comes to the vaccination station.

It is guaranteed that the sum of 𝑛 over all test cases won't exceed 2⋅1052⋅105.

Output

Output one integer, the minimum number of vaccine packs required to vaccinate all 𝑛 patients.

Example

input

Copy

 
 

5

6 3 5 3

1 2 3 10 11 18

6 4 0 0

3 3 3 3 3 4

9 10 2 2

0 1 2 3 4 5 6 7 8

3 10 3 6

10 20 30

5 5 4 4

0 2 4 6 8

output

Copy

2
3
2
3
1

 

从头到位遍历,以当前点为开头,找到他允许时间范围内的所有点,然后给药,然后这个点为头,找药效时间内所有的合格点 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;

constexpr int N=2e5+7;
typedef long long ll;
int main(){
    int T;
    scanf("%d",&T);
    while(T--) {
       int n,k,w,d,a[N];
        scanf("%d%d%d%d",&n,&k,&d,&w);
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        int t=1,pre=1e9+10;
        int ans=0;
        while(t<=n){
            int s=0;
            if(s<k&&a[t]<pre){
                while(s<k&&a[t]<pre){
                    pre=min(a[t]+w,pre);
                    s++;
                    t++;
                }
                while(s<k&&a[t]<=pre+d){
                    s++;
                    t++;
                }
            }
            else{
                t++;
            }
            pre=1e9+10;
            ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

q619718

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

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

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

打赏作者

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

抵扣说明:

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

余额充值