Average Speed

Time limit1sMemory limit128 MB

Summary
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:ss since 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.

Examples1

  1. Example 1

    Input
    00:00:01 100
    00:15:01
    00:30:01
    01:00:01 50
    03:00:01
    03:00:05 140
    
    Expected output
    00:15:01 25.00 km
    00:30:01 50.00 km
    03:00:01 200.00 km