Walk
InterviewTime limit1sMemory limit1024 MB
Parse walking segments given as duration and pace per kilometre, then report total distance in metres and average speed in km/h.
- Level
Medium4 of 10
- Topics
- Implementation, Math, Simulation, String matching
- Solved
- No attempts yet
Problem
Mart takes a walk every day, and his sports watch records the duration and the speed of each constant-speed segment of the walk. After the walk, Mart can download the log file to his computer. From this file, determine the total distance of the walk and the average speed.
Input
The first line contains an integer (). Each of the next lines contains the following space-separated data about one segment:
- the duration of the segment in minutes and seconds, in the form
ms, where is the integer number of minutes (the minutes part is omitted when the duration is less than one minute) and is the integer number of seconds (which never exceeds ); - the word
kiirusega; - the speed on this segment, expressed as minutes and seconds per kilometre, in the form
ms/km, where is the integer number of minutes and is the integer number of seconds (which never exceeds ). You may assume that Mart needs at least one minute, but less than one hour, per kilometre.
You may also assume that the total duration of all segments does not exceed hours.
Output
Print two lines:
- on the first line, the total distance of the walk rounded to the nearest metre, in the form
m, where is the integer number of metres; - on the second line, the average speed in the form
km/h, where is the average speed in kilometres per hour, rounded to exactly three decimal places.