LCC '24 Contest 1 J4 - Stealing Candy

View as PDF

Submit solution


Points: 5
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

Bob is practicing to grab candy quickly. After all, he has to be speedy if he wants to go trick-or-treating to all 1 million houses. After doing some research, he finds out that during halloween, many of the houses have open doors with candy laid down for people to grab. To practice, he places N candies in a row on a table. He is able to grab K consecutive candies with one hand, but he wants to grab as many of his favourite candy, Sadness Ranchers, in one handful (since his other hand is holding the bucket of candy). Since he wants to be fast, he will only take one handful before moving to the next house. What is the maximum the amount of Sadness Ranchers he can take with him?

Constraints

1 \leq N \leq 10^6

1 \leq K \leq N

|S| = N

Input Specifications

The first line will contain two space separated integers, N and K.

The next line will contain the string S. The string will only contain two letters: c and s. s indicates a Sadness Rancher, while c indicates a different type of candy.

Output Specifications

Output an integer indicating the maximum amount of Sadness Ranchers Bob can take in a single handful of candy.

Sample Input 1

8 3
ccsscscs

Sample Output 1

2

Explanation for Sample Case 1

Taking the substring starting from index 1, we have the substring css, which gives 2 Sadness Ranchers. Notice that there are other substrings that also gives 2 Sadness Ranchers.

Sample Input 2

12 5
csscssscccsc

Sample Output 2

4

Comments

There are no comments at the moment.