The Motorway
Time limit6sMemory limit128 MB
Given sorted entry positions, find the smallest and largest even toll spacing that puts one entry between consecutive tolls, printed as reduced fractions.
- Level
Hard8 of 10
- Topics
- Math, Geometry, Binary search
- Solved
- No attempts yet
Problem
Autobyte is building one of the motorways of Byteland. Until recently the company collected a toll only at the start of the motorway, so the amount a driver paid did not depend on the distance he covered in bytemiles. The new chairman, Byteasar, decided to place toll points along the whole motorway.
On one of his trips Byteasar used the odometer of his car to write down the positions of all entry points. The position of an entry point is its distance from the start of the motorway. The company will build toll points spaced evenly, so the distance between two consecutive toll points is the same everywhere. Between every two consecutive toll points there has to be an entry point, and between every two consecutive entry points there has to be a toll point. The positions Byteasar wrote down do allow such an arrangement.
Formally, look for the spacings for which a position of the first toll point exists such that the remaining toll points stand at , , ..., and entry point satisfies
A toll point may land exactly on an entry point. The booth is then built immediately before or immediately after it, which is why the interval above is closed.
Find the smallest and the largest spacing that admits such an arrangement.
Input
The first line contains one integer , the number of entry points ().
The second line contains integers , the positions of the entry points in increasing order ().
The given positions always admit at least one valid arrangement, and the smallest and the largest spacing differ by at least .
Output
Print the smallest spacing and the largest spacing between two consecutive toll points, in that order, on one line separated by a single space.
Both answers are rational, so print each one as an exact fraction p/q in lowest terms, with and . Write the denominator even when it is , so a spacing of is printed as 3/1.