No.78 クジ付きアイスバー
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
Problem Statement
A-kun loves ice bars that come with a lottery.
Each ice bar is one of "no prize", "1-bar prize", or "2-bar prize".
A no-prize bar gives nothing, but a prize bar lets him get that many bars for free.
The store sells ice bars packed in boxes.
One box contains N ice bars.
A-kun can only take ice bars out of the box in order from the front.
Ice bars are taken from this box both when buying them and when exchanging prizes for them.
The arrangement of no-prize and prize bars within a box is the same for every box.
The store has one box of ice bars, and when it sells out, one new box is restocked.
Right now the store has a new, untouched box of ice bars.
A-kun initially has no prize tickets, and his budget is unlimited.
In order to eat K ice bars, at least how many ice bars does A-kun need to buy?
Input
N K S
$N$ is the number of ice bars in one box. $1 \le N \le 50$. $N$ is a positive integer.
$K$ is the number of ice bars A-kun plans to eat. $1 \le K \le2000000000=2 \cdot 10^9$. $K$ is a positive integer.
The length of $S$ is equal to the value of $N$.
The string S consists of three kinds of characters: '0', '1', and '2'.
'0' represents "no prize", '1' represents "1-bar prize", and '2' represents "2-bar prize".
The ice bars are considered to be in the box from the front in the order of the characters of the string.
Output
Output the number of ice bars A-kun buys.
Do not forget the newline at the end.
Sample
Sample 1
Input
5 4 01200
Output
2
One box contains 5 ice bars.
From the front, they are "no prize", "1-bar prize", "2-bar prize", "no prize", "no prize".
The first 2 ice bars must be bought.
The 2nd ice bar is a "1-bar prize", so the 3rd ice bar can be obtained for free.
The 3rd ice bar is a "2-bar prize", so the 4th and 5th ice bars can also be obtained for free.
The number of ice bars A-kun wants to eat is 4, so the goal has been achieved at this point.
A-kun bought 2 ice bars.
Sample 2
Input
2 8 10
Output
4
One box of ice bars contains 2 ice bars.
The box contains ice bars in the order "1-bar prize", "no prize".
Each time he buys 1 bar he gets 1 bar, so we can consider that buying 1 bar lets him eat 2 bars.
Therefore, to eat 8 bars, he needs to buy 4 bars.
Sample 3
Input
10 100 2222222222
Output
1
One box contains 10 ice bars, all of which are "2-bar prize".
He can get as many ice bars as he wants using the prizes, but the first bar must be bought no matter what.
Sample 4
Input
2 5 01
Output
3
One box of ice bars contains 2 ice bars.
The box contains ice bars in the order "no prize", "1-bar prize".
To eat 5 ice bars, he needs to buy 3 ice bars.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
nmnmnmnmnmnmnm