欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2117A.False Alarm
False Alarm
Yousef is at the entrance of a long hallway with doors in a row, numbered from to . He needs to pass through all the doors from to in order of numbering and reach the exit (past door ).
Each door can be open or closed. If a door is open, Yousef passes through it in second. If the door is closed, Yousef can't pass through it.
However, Yousef has a special button which he can use at most once at any moment. This button makes all closed doors become open for seconds.
Your task is to determine if Yousef can pass through all the doors if he can use the button at most once.
Input
The first line of the input contains an integer () — the number of test cases.
The first line of each test case contains two integers () — the number of doors and the number of seconds of the button, respectively.
The second line of each test case contains integers () — the state of each door. Open doors are represented by '0', while closed doors are represented by '1'.
It is guaranteed that each test case contains at least one closed door.
Output
For each test case, output "YES" if Yousef can reach the exit, and "NO" otherwise.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
Note
In the first test case, the optimal way is as follows:
- At time , the door is open, so Yousef passes.
- At time , the door is closed, Yousef can use the button now and pass through the door.
- At time , the button's effect is still on, so Yousef can still pass.
- At time , the button's effect has finished, but the door is open. Yousef passes and reaches the exit.
In the second test case, Yousef has a 3-second button, but he would need at least a 4-second button to reach the exit. Therefore, the answer is NO.
In the third test case, Yousef can turn on the button before starting to move. All the doors will stay open until he reaches the exit.
Samples
7
4 2
0 1 1 0
6 3
1 0 1 1 0 0
8 8
1 1 1 0 0 1 1 1
1 2
1
5 1
1 0 1 0 1
7 4
0 0 0 1 1 0 1
10 3
0 1 0 0 1 0 0 1 0 0
YES
NO
YES
YES
NO
YES
NO
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |