Need for Speed
InterviewTime limit1sMemory limit512 MB
Given segment distances and speedometer readings plus a total time, find the constant offset c making the summed travel times equal t.
- Level
Medium4 of 10
- Topics
- Binary search, Math, Implementation
- Solved
- No attempts yet
Problem

Sheila is a student and she drives a typical student car: old, slow, rusty, and falling apart. Recently the needle on the speedometer fell off. She glued it back on, but she might have placed it at the wrong angle. So when the speedometer reads , her true speed is , where is an unknown constant that may be negative.
Sheila kept a careful record of a recent journey and wants to use it to compute . The journey consisted of segments. In the th segment she traveled a distance of , and the speedometer read for that entire segment. The whole journey took time . Help Sheila by computing .
The speedometer may show a negative reading, but her true speed was greater than zero on every segment.
Input
The first line contains two integers and . Here is the number of segments of the journey (), and is the total time of the journey ().
Each of the next lines describes one segment. The th of these lines contains two integers and (, ), the distance and the speedometer reading for the th segment. Time is given in hours, distance in miles, and speed in miles per hour.
A real number that makes every true speed greater than zero and the total time exactly always exists. The sum strictly decreases in , so that value is unique.
Output
Print the constant in miles per hour, rounded to exactly six digits after the decimal point. If the value is zero, print 0.000000 and not -0.000000.