When he's not busy fighting with Dr. Robotnik, Sonic makes a living delivering submarine…
- User
When he's not busy fighting with Dr. Robotnik, Sonic makes a living delivering submarine sandwiches via an empty subway tunnel. The tunnel goes past N N stations, numbered from 1 1 to N N. Station i i is located i i miles away from Sonic, who plans to run from one end of the tunnel to the other, tossing a sandwich to an awaiting customer at every station. At each station, a customer is scheduled to meet Sonic within an expected delivery window. Sonic can deliver a sandwich to station i i only if he arrives within the inclusive interval [ A i , B i ] [A i ,B i ] seconds. Chasing Dr. Robotnik is tiring enough, so Sonic doesn't want to exert himself more than he has to. If he runs at a constant speed, what’s the minimum speed, in miles per second, that will allow him to deliver to every station? If no such constant speed exists, output − 1 −1. Your answer will be accepted if it is within an absolute or relative error of 1 0 − 6 10 −6 (even if the expected answer is − 1 −1). Constraints 1 ≤ T ≤ 95 1≤T≤95 1 ≤ N ≤ 1 , 000 , 000 1≤N≤1,000,000 0 ≤ A i < B i ≤ 1 , 000 , 000 0≤A i <B i ≤1,000,000 The sum of N N across all test cases is at most 5 , 000 , 000 5,000,000. Input Format Input begins with an integer T T, the number of test cases. Each case starts with a line containing the integer N N. Then, N N lines follow, the i ith of which contains the integers A i A i and B i B i . Output Format For the i ith test case, print "Case #i: " followed by the minimum constant speed, in miles per second, that Sonic can run that will get him to each door while it's open, or − 1 −1 if no such constant speed exists. Sample Explanation In the first case, Sonic needs to reach the station 3 3 miles away within 10 10 seconds, so he can run at a speed of 3 / 10
0.3 3/10=0.3 miles per second. The second case is depicted below, with delivery windows in green, and Sonic's path in blue. The last station's delivery window is wide, so the third station is the one that Sonic really has to run to get to. It's 3 3 miles away and he needs to get there within 2 2 seconds, so he'll run at a speed of 3 / 2
1.5 3/2=1.5 miles per second.
In the third case, the first station's delivery window doesn't open until the second station's closes, so there's no constant speed that lets Sonic deliver both sandwiches. In the fourth case, a speed of 0.5 0.5 miles per second gets Sonic to catch the first station right as the delivery window closes, and the second station right as the delivery window opens. Sample Input 4 3 0 10 0 10 0 10 4 0 3 1 4 1 2 0 10 2 5 10 0 5 2 1 2 4 10
Sample Output Case #1: 0.3 Case #2: 1.5 Case #3: -1 Case #4: 0.5
- Assistant