Covering an Interval
Time limit2sMemory limit1024 MB
Given N segments on a line, pick at most three that cover the interval from S to E, minimizing the total length of overlaps between the chosen pairs.
- Level
Medium6 of 10
- Topics
- Intervals, Sorting, Dynamic programming
- Solved
- No attempts yet
Problem
There are segments on a one-dimensional line. You want to cover the interval from to using at most 3 of the given segments.
A segment with start point and end point covers a point when . A set of segments can cover the interval when, for every real number with , at least one segment in covers .
The 'error' of a covering is the sum of the lengths of the overlaps between every pair of two different segments used. If one segment alone covers the whole interval from to , the error of that covering is 0.
Find the minimum possible 'error' over all coverings that use at most 3 segments.
Input
The first line contains the number of segments , the start point , and the end point , separated by spaces.
The next lines contain the start point and the end point of the -th segment, separated by spaces.
Output
Print the minimum possible error on the first line.
If the interval from to cannot be covered in any way, print .
Limits
- All numbers in the input are integers.