QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 64 MB Total points: 80

#13739. Telefoni

Statistics

房间里有 $N$ 张桌子,从左到右依次相邻排列。有些桌子上有电话,而有些桌子是空的。所有的电话都坏了,因此如果第 $j$ 张桌子上的电话响了,且第 $i$ 张桌子与第 $j$ 张桌子的距离最多为 $D$ 张桌子(即满足 $|j - i| \le D$),那么第 $i$ 张桌子上的电话也会响。第一张和最后一张桌子上总是会有电话。最开始,最左边的电话会响。为了让最后一架电话也响起来,最少需要在桌子上新放置多少部电话?

输入格式

第一行包含两个正整数 $N$ ($1 \le N \le 300\,000$) 和 $D$ ($1 \le D \le N$)。

第二行包含 $N$ 个数字,每个数字为 $0$ 或 $1$。如果第 $i$ 个数字是 $1$,则表示从左数第 $i$ 张桌子上有电话,否则表示第 $i$ 张桌子是空的。

输出格式

输出第一行且仅一行,包含所需的最少电话数量。

子任务

在占总分 40 分的测试数据中,满足 $1 \le N \le 20$。

样例

输入样例 1

4 1
1 0 1 1

输出样例 1

1

输入样例 2

5 2
1 0 0 0 1

输出样例 2

1

输入样例 3

8 2
1 1 0 0 1 0 0 1

输出样例 3

2

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.