Mock CCC '22 Contest 1 J2 - Biking and Hiking

View as PDF

Submit solution

Points: 3
Time limit: 0.25s
Memory limit: 256M

Problem type

Bob is biking on a trail with N sections. This trail has uphills, downhills, and flat sections, denoted by U, D, and F, respectively. He starts with a speed of K, and will bike through the entire trail. When biking:

  • On uphill sections, Bob will lose 1 unit of speed.
  • On downhill sections, Bob will gain 1 unit of speed.
  • On flat sections, Bob's speed will not change.

If Bob's speed becomes 0, he will have to get off his bike and walk until he reaches either a downhill section or the end of the trail. His speed cannot be negative.

How many total sections will Bob have to walk on?


1 \le N, K \le 10^4

Input Specification

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

The second and final line will contain a string of length N with only the characters U, D, and F.

Output Specification

Output one integer on one line, the number of sections Bob will have to walk on.

Sample Input

11 1

Sample Output



Bob has to walk the second section and from the tenth section to the end of the trail, as in these sections, his speed is 0.


There are no comments at the moment.