Mock CCC '22 Contest 1 J2 - Biking and Hiking

View as PDF

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

Author:
Problem type

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

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

If Bob's speed becomes , 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?

Input Specification

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

The second and final line will contain a string of length 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
FUDDDUDUUUF

Sample Output

3

Explanation

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 .