Revenge of the Hot Dogs (Small)
InterviewTime limit5sMemory limit512 MB
Vendors on a line move at speed 1 and must end at least D apart, so find the smallest time that allows such positions.
- Level
Medium6 of 10
- Topics
- Binary search, Greedy, Sorting
- Solved
- No attempts yet
Problem
Last year several hot dog vendors lined up along a street and ran an algorithm to spread themselves out. The algorithm was so slow that it is still running, so the vendors decided to try a new one.
The trouble is that vendors standing too close to each other take each other's business. A vendor moves along the street at 1 meter per second. To stay out of each other's way, they want to stand so that every pair of vendors is at least meters apart.
The street is very long, so no vendor ever runs out of room in either direction. Given the starting positions of all vendors, find the minimum time needed until every pair of vendors is at least meters apart. Several vendors can start at the same point, and each vendor can move east or west.
Input
Every point of the street carries an integer label. The point labeled is meters east of the point labeled when is positive, and meters west of it when is negative.
The first line contains the number of test cases . Each test case begins with a line holding the number of points that have at least one vendor in the starting configuration and the minimum distance the vendors want between them, separated by a space. The next lines each hold two space separated integers and , meaning that vendors stand at the point labeled .
Limits
- Within one test case all values are distinct and are given in increasing order.
- is a positive integer, and the sum of the values in one test case is at most .
Output
For each test case print one line in the form Case #x: y, where is the test case number starting from 1 and is the minimum time until every pair of vendors is at least meters apart.
The answer is always a multiple of , so print it with exactly one digit after the decimal point. An answer of prints as 1.0, and an answer of prints as 2.5.