Pinely Round 5 (Div. 1 + Div. 2)
A
Round Trip
Codeforces
800
原题
←B →
翻译中…

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 $R_0$. There will be $n$ 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 $X$, and unrated for all others,
翻译中…

In an unrated round, Vasya cannot change his rating. If Vasya's rating before a rated round was $R$, then for any non-negative integer $x$ between $R-D$ and $R+D$ (inclusive) Vasya can adopt a strategy such that his rating becomes exactly $x$ afterwards (here $D$ 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 $t$ ($1 \le t \le 1000$). The description of the test cases follows.

翻译中…

The first line of each test case contains four integers: $R_0, X, D, n$ ($0 \leq R_0 \leq 10^9$, $1 \leq X \leq 10^9$, $1 \leq D, n \leq 1000$) — 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 $n$. The string will only contain the characters "1" and "2", representing div. 1 and div. 2 rounds respectively.

翻译中…

The sum of $n$ across all test cases does not exceed $3 \cdot 10^4$.

翻译中…

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 $R_0 \geq X$, 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 $0$.

翻译中…

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$.

翻译中…

样例

Input #1
4
2100 2100 5 3
222
2098 2100 5 6
111211
2115 2100 226 7
2211121
0 10 4 8
22111121
Output #1
0
6
5
8
InputCopy OutputCopy
题目信息
题号
2161A
时间限制
1 s
内存限制
512 MB
标签
博弈论
贪心
模拟
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。