Interval
시간 제한3초메모리 제한1024 MB
n개의 닫힌 구간에서 공통점을 가지는 m개를 골라 선택한 구간 길이의 최댓값과 최솟값의 차이를 최소로 만들고, 불가능하면 -1을 출력한다.
문제
There are closed intervals . You need to choose intervals such that the intervals have nonempty intersection. In other words, there exists some such that for any selected interval , .
The cost of selecting a collection of intervals with nonempty intersection is the maximum length of the intervals minus the minimum length of the intervals. The length of interval is .
Compute the minimum cost of choosing intervals with nonempty intersection. If this is impossible, output -1.
입력
The first line consists of two positive integers separated by a single space where is the total number of intervals and is the number of intervals we are going to choose. It is guaranteed that .
In the following lines, each line consists of two integers separated by a space denoting the left and right endpoints of an interval.
출력
Output a line with an integer denoting the minimum cost.