欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2161A.Round Trip
Round Trip
They say that if you do 1000 rounds, there's a secret cartoon in the end (c)
Petya and Vasya love participating in Codeforces contests. Vasya made a bet with Petya that he will take part in more rated rounds than him. Initially, Vasya's rating is . There will be rounds conducted in total, each of one of two types:
- div. 1 — rated for all participants
- div. 2 — rated for participants with rating strictly less than , and unrated for all others,
In an unrated round, Vasya cannot change his rating. If Vasya's rating before a rated round was , then for any non-negative integer between and (inclusive) Vasya can adopt a strategy such that his rating becomes exactly afterwards (here is a positive integer). Note that rating may never become negative.
Help Vasya determine the maximum number of rated rounds he can participate in.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains four integers: (, , ) — Vasya's initial rating, the rating threshold between divisions, the maximum rating delta, and the number of rounds.
The second line of each test case contains a string of size . The string will only contain the characters "1" and "2", representing div. 1 and div. 2 rounds respectively.
The sum of across all test cases does not exceed .
Output
For each test case, print a single integer — the maximum number of rated rounds Vasya can participate in.
Note
In the first example, since , each div. 2 round is unrated for Vasya, so his rating never changes. Therefore, he cannot make any round rated for himself, and the answer is .
In the second example, one of the optimal sequences of ratings after each round is: $2098 \rightarrow 2103 \rightarrow 2101 \rightarrow 2099 \rightarrow 2097 \rightarrow 2097 \rightarrow 2092$.
Samples
4
2100 2100 5 3
222
2098 2100 5 6
111211
2115 2100 226 7
2211121
0 10 4 8
22111121
0
6
5
8
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |