Ads

시간 제한3초메모리 제한2048 MB

요약
영상 n개의 순서를 정해, 영상 3개마다 또는 마지막 광고로부터 k분이 지날 때마다 강제로 나오는 광고의 수를 최소화한다.
난이도

보통10점 중 7점

유형
그리디, 정렬, 동적 계획법
정답자
아직 제출이 없습니다

문제

You have nn videos on your watchlist on the popular platform YooCube. The ii-th video lasts d_id\_i minutes.

YooCube has recently increased the frequency of their ads. Ads are shown only between videos. After finishing a video, an ad is shown if either of these two conditions is true:

  • three videos have been watched since the last ad;
  • at least kk minutes have passed since the end of the last ad.

You want to watch the nn videos in your watchlist. Given that you have just watched an ad, and that you can choose the order of the nn videos, what is the minimum number of ads that you are forced to watch? You can start a new video immediately after the previous video or ad ends, and you don’t have to watch any ad after you finish.

입력

Each test contains multiple test cases. The first line contains an integer tt (1≤t≤100,0001 ≤ t ≤ 100\\, 000) — the number of test cases. The descriptions of the tt test cases follow.

The first line of each test case contains two integers nn and kk (1≤n≤100,0001 ≤ n ≤ 100\\, 000, 1≤k≤30,0001 ≤ k ≤ 30\\, 000) — the number of videos in your watchlist and the parameter that determines when ads are shown.

The second line contains nn integers d_1,d_2,…,d_nd\_1, d\_2, \dots , d\_n (1≤d_i≤10,0001 ≤ d\_i ≤ 10\\, 000) — the lengths of the videos.

The sum of the values of nn over all test cases does not exceed 10610^6.

출력

For each test case, print the minimum number of ads that you need to watch.

예제1

  1. 예제 1

    입력
    5
    8 25
    4 5 18 3 17 17 18 14
    7 21
    20 14 1 4 20 8 4
    8 1
    20 5 9 4 14 12 2 20
    8 37
    2 13 13 11 12 19 16 18
    4 38
    15 3 14 7
    
    예상 출력
    2
    2
    7
    2
    1