QOJ.ac

QOJ

حد الوقت: 1.0 s حد الذاكرة: 256 MB مجموع النقاط: 100 قابلة للهجوم ✓

#7880. 连胜操纵

الإحصائيات

本学期,Mr. Ham 花了大量时间进行 ICPC 训练。他这学期有 $n$ 门课,但他只参加了其中的一部分。他使用一个二进制字符串 $s_{1..n}$ 来表示他参加了哪些课程。如果字符串的第 $i$ 个字符为 1,则表示他参加了第 $i$ 门课;否则,他没有参加第 $i$ 门课。

如果 Mr. Ham 连续参加了 $k$ 门课,他就会获得一个长度为 $k$ 的连胜(streak)。形式化地,如果 $1 \le i \le j \le n$ 满足以下条件,我们称 Mr. Ham 拥有一个长度为 $j - i + 1$ 的连胜:

  • $s_i = s_{i+1} = \dots = s_j = 1$;
  • $i = 1$ 或 $s_{i-1} = 0$;
  • $j = n$ 或 $s_{j+1} = 0$。

例如,如果 $s = 101101$,Mr. Ham 拥有一个长度为 2 的连胜和两个长度为 1 的连胜。

Mr. Ham 发现他缺席了太多的课程,于是他偷走了考勤记录并想要修改它(这是不允许的,所以请不要这样做)。给定 $m$ 和 $k$,他最多可以将 $m$ 条记录从 0 修改为 1。他想知道他能获得的第 $k$ 长连胜的最大长度是多少。

如果连胜的总数少于 $k$ 个,我们定义第 $k$ 长连胜的长度为 $-1$。

输入格式

第一行包含三个整数 $n$、$m$ 和 $k$ ($1 \le m \le n \le 2 \times 10^5$, $1 \le k \le \min(n, 5)$)。 第二行包含一个长度为 $n$ 的字符串 $s$。保证对于所有 $1 \le i \le n$,$s_i \in \{0, 1\}$。

输出格式

输出 Mr. Ham 通过将最多 $m$ 条记录从 0 修改为 1 后,能获得的第 $k$ 长连胜的最大长度。

样例

样例输入 1

8 3 2
10110110

样例输出 1

3

样例输入 2

12 3 3
100100010011

样例输出 2

2

样例输入 3

4 4 4
0000

样例输出 3

-1

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.