Bessie Slows Down
Time limit1sMemory limit128 MB
Bessie runs 1000 metres with speed 1/(k+1) after k slowdowns triggered by time or distance events, and the total time is rounded to the nearest second.
- Level
Medium4 of 10
- Topics
- Simulation, Sorting, Math
- Solved
- No attempts yet
Problem
Bessie the cow is racing in the cross-country skiing event at the winter Moolympic games. She starts out at 1 metre per second. She tires as the race goes on, so she keeps slowing down. After the first slowdown she moves at metre per second, after the second at metre per second, and in general after slowdowns she moves at metre per second.
When and where Bessie slows down is given as a list of events. T 17 means she slows down at a specific time, 17 seconds into the race. D 10 means she slows down at a specific distance from the start, 10 metres in this case.
Given such events, compute how many seconds Bessie needs to cover a full kilometre. Round the answer to the nearest integer second, and round up when the fractional part is exactly .
Input
The first line has . ()
Each of the next lines holds one event, either T x or D x. T x is a time event and D x is a distance event, and is a non-negative integer. Every event happens before Bessie completes 1000 metres. Several events can land on the same moment, and then Bessie slows down that many times at once. The events are not necessarily listed in order.
No input makes the exact finishing time land on .
Output
Print the total time Bessie takes to travel 1 kilometre.
Hint
Suppose one event sits at time 30 and another at distance 10. Bessie covers the first 10 metres at 1 metre per second, which takes 10 seconds. Her speed then drops to metre per second, so the next 10 metres take 20 seconds. That moment is the 30 second mark, where she slows again to metre per second. The remaining 980 metres take seconds, so the total is seconds.