QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 2048 MB Total points: 100

#10312. Ads

الإحصائيات

你在热门平台 YooCube 的观看列表中有 $n$ 个视频。第 $i$ 个视频的时长为 $d_i$ 分钟。

YooCube 最近增加了广告频率。广告仅在视频之间播放。在看完一个视频后,如果满足以下两个条件中的任意一个,就会播放广告:

  • 自上次广告以来已经观看了三个视频;
  • 自上次广告结束以来已经过去了至少 $k$ 分钟。

你想要观看列表中的 $n$ 个视频。已知你刚刚看完一个广告,且你可以选择这 $n$ 个视频的观看顺序,请问你被迫观看的最少广告次数是多少?你可以在上一个视频或广告结束后立即开始下一个视频,且在看完所有视频后无需观看任何广告。

输入格式

每个测试包含多个测试用例。第一行包含一个整数 $t$ ($1 \le t \le 100\,000$) —— 测试用例的数量。接下来是 $t$ 个测试用例的描述。

每个测试用例的第一行包含两个整数 $n$ 和 $k$ ($1 \le n \le 100\,000, 1 \le k \le 30\,000$) —— 观看列表中的视频数量以及决定广告播放时机的参数。

第二行包含 $n$ 个整数 $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10\,000$) —— 视频的时长。

所有测试用例的 $n$ 之和不超过 $10^6$。

输出格式

对于每个测试用例,输出你需要观看的最少广告次数。

样例

输入 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

输出 1

2
2
7
2
1

说明 1

在第一个测试用例中,一种可能的观看顺序是 4, 1, 8, 2, 5, 6, 7, 3(对应的时长分别为 3, 4, 14, 5, 17, 17, 18, 18)。按照这个顺序,你需要在看完前三个视频后观看一个广告,然后在看完接下来的三个视频后再观看一个广告。注意,在看完所有视频后,你不需要观看广告。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.