Reconnaissance
Time limit3sMemory limit256 MB
Find the minimum distance between the leading and trailing vehicles over all future times given their positions and constant velocities.
- Level
Medium5 of 10
- Topics
- Binary search, Math
- Solved
- No attempts yet
Problem
You have located a major supply line the enemy has been using. Satellite imaging gives you the current position and velocity of every vehicle on that line. The supply line is an infinitely long straight line for all practical purposes, each vehicle moves at a constant velocity, and vehicles pass one another without incident.
You now want to deploy an air drone carrying a special sensor that reads the contents of the vehicles. The sensor reads everything within its range instantly, but power limits let it fire only once. To keep the required range small, send the drone at the moment the vehicles are packed as tightly as possible.
Call the present moment time . At time , the length of the shortest interval covering all vehicles is the distance between the leading vehicle and the trailing vehicle at that moment. Given the current position and velocity of every vehicle, find the smallest such length over all .
Input
The input holds several test cases.
Each test case begins with a line containing the number of vehicles (). Each of the next lines contains two integers and (), the position of that vehicle in meters and its velocity in meters per hour. The sign of gives the direction of travel.
The input ends with a line containing a single .
Output
For each test case, print on its own line the minimum length of an interval that covers all of the vehicles at some moment, in meters.
Round the value to two decimal places and print exactly two digits after the decimal point. Do not put spaces inside a line, and do not print blank lines between outputs.