Given start times and speeds from one spot, find the smallest gap between the first and last cheetah at any time after all have started.
Medium6Binary searchMathNo attempts yetTime limit3sMemory limit256 MBA film crew is shooting a documentary about animal speed and wants several cheetahs sprinting at full pace in a single shot. One running cheetah has been filmed many times already, so this time the crew is after a pack.
Herding every cheetah into one box and opening it all at once is too dangerous to try. Each cheetah gets its own start box instead, and the slower ones are released first. After a while the faster cheetahs overtake the slower ones and the pack draws together as tightly as it ever will. The crew wants the length of the pack at that moment.
All start boxes stand at the same place. Cheetah k is released at time tk and runs at the constant speed vk from that moment on. At time T the length of the pack is the distance between the leading cheetah and the trailing one.
The length is measured only once every cheetah has started, that is at T≥max(t1,…,tN). The track is long enough that the shortest moment arrives before the leading cheetah reaches the finish line. Find the minimum length of the pack.
The input holds several test cases. The first line of a test case contains the number of cheetahs N (1≤N≤100000). Each of the next N lines contains two integers tk and vk separated by a space (1≤tk,vk≤99999), the start time and the speed of cheetah k.
The last line of the input contains a single 0. That line is not a test case.
For each test case print the minimum length of the pack on its own line. Round the value to three digits after the decimal point and print all three digits, trailing zeros included.