Problem D
Squash
Languages
en
sv
Göran has started playing squash with his friends. He is very dedicated and plays $N$ matches per day. Göran’s goal is, of course, to win as many matches and lose as few matches as possible. His satisfaction after a day of playing squash is equal to the number of matches he won minus the number of matches he lost.
In addition to getting better at squash and winning more matches, Göran has an extra trick to increase his satisfaction: he claims that he only played seriously during $K$ different series of consecutive matches. Only these matches count in the calculation of his satisfaction. Göran always chooses these $K$ match series to maximize his satisfaction.
A match series always consists of all matches between the $i$-th and the $j$-th match for some chosen $i$ and $j$, but Göran can let one (or all!) match series be empty (e.g., maybe he took a very serious water break instead). The consecutive match series he chooses must not overlap, i.e., each match played can be part of at most one chosen match series.
Given the match history for a day, what will Göran’s satisfaction be if he chooses the match series optimally?
Input
The first line of input contains the integer $N$ and $K$ ($1 \leq K \leq N \leq 1\, 000$), the number of matches an the number of serious matches.
The following line contains a string with $N$ characters, the results of the matches that Göran played. The $i$:th of these characters is V if Göran won the $i$:th match, and F if he lost it.
Output
Print an integer: the maximum satisfaction that Göran can achieve.
Scoring
Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group you need to solve all test cases in the test group.
Group |
Points |
Constraints |
$1$ |
$10$ |
$K = 1$ |
$2$ |
$20$ |
$K = 2$ |
$3$ |
$30$ |
$K = 3$ |
$4$ |
$40$ |
No additional constraints. |
Sample Input 1 | Sample Output 1 |
---|---|
5 1 VVFVV |
3 |
Sample Input 2 | Sample Output 2 |
---|---|
5 2 VVFVV |
4 |
Sample Input 3 | Sample Output 3 |
---|---|
19 3 VVFFVFVVVFVVVFFFFVV |
9 |
Sample Input 4 | Sample Output 4 |
---|---|
1 1 F |
0 |