EISWMED1 - Get K Consecutive Black Blocks
Xem dạng PDF
Gửi bài giải
Điểm:
1,00 (OI)
Giới hạn thời gian:
1.0s
Giới hạn bộ nhớ:
256M
Input:
stdin
Output:
stdout
Nguồn bài:
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch
You are given a string ~B~ of length ~n~ (called a block), where each character ~B_i~ is either W or B, representing a white block or a black block at position ~i~, respectively.
You are also given an integer ~k~, representing the desired number of consecutive black blocks.
In one operation, you are allowed to change a white block W into a black block B.
Task: Determine the minimum number of operations required so that the string contains at least one segment of ~k~ consecutive black blocks.
Input
- The first line contains the string ~B~ (consisting of characters
WandB) of length ~n~. - The second line contains an integer ~k~.
Output
- An interger which is the minimum number of operations required.
Sample Input
WBBWWBBWBW
7
Sample Output
2
Bình luận