Average Speed
Time limit1sMemory limit128 MB
Track a car's speed changes over time and answer queries asking the total distance travelled up to a given elapsed time.
- Level
Easy3 of 10
- Topics
- Simulation, Implementation, Prefix sum
- Solved
- No attempts yet
Problem
You have bought a car to drive from Waterloo to a big city. The car's odometer is broken, so you cannot measure distance directly. However, the speedometer and cruise control both work, so the car can hold a constant speed that you adjust from time to time in response to speed limits, traffic jams, and border queues. You also have a stopwatch, and you note the elapsed time since the start of the trip every time the speed changes.
From time to time you wonder, "how far have I come?" To answer this, write a program to run on the laptop in the passenger seat.
Input
Standard input consists of several lines, each of which is one of the following:
- Speed change: an elapsed time
hh:mm:sssince the start of the trip, followed by the new speed in km/h (an integer), separated by a space. - Query: a single elapsed time
hh:mm:ss.
At the start of the trip (elapsed time 0) the car is stationary (speed 0). Elapsed times are given in non-decreasing order, and there is at most one speed change at any given time.
Output
For each query, print one line. First write the query's elapsed time in hh:mm:ss format, then a single space, then the total distance travelled up to that time in kilometres, rounded to two decimal places, followed by km.