Speed Limit
InterviewTime limit5sMemory limit512 MB
For each log entry, multiply the speed by the time since the previous entry, sum these products, and print the total distance in miles.
- Level
Easy2 of 10
- Topics
- Implementation, Math, Simulation
- Solved
- No attempts yet
Problem
Basri, Lim and Rama are taking a road trip during their semester break. But the odometer in their car is broken, so they don't know how many miles they have driven. Fortunately, Bill has a working stopwatch, so they can record their speed and the total time they have driven. Unfortunately, their record keeping strategy is a little odd, so they need help computing the total distance driven. Write a program to do this computation.
For example, suppose their log shows
This means they drove 2 hours at 20 miles per hour, then hours at 30 miles per hour, then hour at 10 miles per hour. The distance driven is then miles. Note that the total elapsed time is always measured from the beginning of the trip, not from the previous entry in the log.
Input
The input consists of one or more data sets. Each set starts with a line containing an integer (), followed by pairs of values, one pair per line. The first value in a pair, , is the speed in miles per hour, and the second value, , is the total elapsed time. Both and are integers with and . The values of are always in strictly increasing order. A value of for signals the end of the input.
Output
For each data set, print the distance driven, followed by a space, followed by the word "miles".