Speed Limit
Time limit1sMemory limit128 MB
Given segments of constant speed with cumulative elapsed times, compute the total distance for each data set until n equals -1.
- Level
Easy1 of 10
- Topics
- Implementation, Math, Simulation
- Solved
- No attempts yet
Problem
Bill and Ted are on a road trip, but their car's odometer is broken, so they don't know how far they have driven. Fortunately, Bill has a working stopwatch, so they can record their speed and the total time driven since the start of the trip. Their record-keeping is a little unusual, so they need help computing the total distance. Write a program to do this computation.
For example, suppose their log is:
This means they drove 2 hours at 20 mph, then hours at 30 mph, then hour at 10 mph. The total distance driven is miles. Note that each elapsed time is measured from the beginning of the trip, not from the previous log entry.
Input
The input consists of one or more data sets. Each set begins with a line containing an integer (), followed by pairs of values, one pair per line. In each pair, the first value is the speed in miles per hour and the second value is the total elapsed time; both 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".