#P8660. [蓝桥杯 2017 国 A] 区间移位
[蓝桥杯 2017 国 A] 区间移位
Description
There are closed intervals on the number line: .
Interval is described by a pair of integers , satisfying .
It is known that the sum of the lengths of these intervals is at least .
Therefore, by shifting these intervals appropriately, you can always make their union cover . That is, every point in the interval lies in at least one interval.
You want to find a shifting method that minimizes the maximum shift amount among all intervals.
Specifically, suppose you shift to . You want to minimize .
Input Format
The first line contains an integer , indicating the number of intervals.
The next lines each contain two integers , separated by a space, representing the interval .
It is guaranteed that the sum of the lengths of the intervals is at least .
Output Format
Output a number, representing the answer. If the answer is an integer, output only the integer part. If the answer is not an integer, round it to one decimal place.
2
10 5010
4980 9980
20
4
0 4000
3000 5000
5001 8000
7000 10000
0.5
Hint
Sample Explanation
Sample 1: Move the first interval units to the left; move the second interval units to the right.
Sample 2: Move the -nd interval units to the right; move the -rd interval units to the left.
Constraints
For of the test cases, .
For of the test cases, , .
Translated by ChatGPT 5
京公网安备 11011102002149号