Caravan Robbers
Time limit1sMemory limit128 MB
Given nested-free intervals, place equal-length disjoint subintervals inside them and output the maximum common length as an exact fraction.
- Level
Hard8 of 10
- Topics
- Binary search, Greedy, Sorting, Math
- Solved
- No attempts yet
Problem
Long ago, in a faraway land, there were two great cities joined by the Great Caravan Road. Many robber gangs "worked" along that road.
By an old custom, the -th gang robbed every merchant who dared to travel between miles and of the Great Caravan Road. The custom was old but clever: there were no two distinct gangs and with and (that is, no gang's interval contained another's). Still, whenever two gangs' intervals overlapped, bloody fights sometimes broke out.
To end the wars, the gang leaders decided to reassign each gang a new interval so that:
- all new intervals are pairwise non-overlapping (to avoid bloodshed),
- each gang's new interval is a subinterval of its old one (to respect the old custom), and
- all new intervals have the same length (to keep things fair).
Compute the maximum possible common length of the intervals after this redistribution.
Input
The first line contains () — the number of gangs.
Each of the next lines contains two integers and (), describing one gang's interval. The input satisfies the condition stated above: no gang's interval contains another's.
Output
Output the maximum possible common interval length, in miles, as an irreducible fraction .
Note
For the sample with gangs , , and , one optimal redistribution gives every gang an interval of length :
- the first gang takes , a subinterval of its original ;
- the second gang takes , a subinterval of its original ;
- the third gang takes , a subinterval of its original .