408311: GYM103091 K Marbles
Description
You are trying to solve a puzzle posed by some Stanford students.
You have a line of marbles, with some white and some black. You can only remove marbles from either end of the line. What is the greatest number of white marbles you can remove, given that you are only allowed to remove at most $$$K$$$ black marbles? You can assume there are at least $$$K+1$$$ black marbles in the line.
InputThe first line of the input contains 2 space separated integers $$$N$$$, ($$$1\leq N \leq 10^6$$$) and $$$K$$$, ($$$1 \leq K < N$$$). $$$N$$$ is the total number of marbles, and $$$K$$$ is the maximum number of black marbles you're able to remove. The second line of input is a string of length $$$N$$$, with the characters 'W' for white marbles and 'B' for black marbles.
OutputOutput a single integer representing the greatest number of white marbles you can remove.
ExamplesInput10 3 WWWBBBBWWWOutput
6Input
15 3 WWBBBWWWWWBBBBBOutput
7