Problem I. Bus Line

Xem dạng PDF

Gửi bài giải

Điểm: 1,00
Giới hạn thời gian: 1.0s
Giới hạn bộ nhớ: 256M
Input:stdin
Output:stdout

Authors:
Dạng bài

Every morning, at UMT University, hundreds of buses transport students to their lecture halls. Each bus trip is defined by its start and end time, corresponding to when the first student is picked up and the last one is dropped off on that day, like the picture below.

To optimize operating costs, the university administration wants to identify a main operating time window during which buses are active, in order to eliminate unnecessary expenses. Realizing that this problem could be solved through programming, a professor presented the following interesting challenge during a Computer Science Club meeting.

Find a time interval ~(A, B)~ such that the total active time of all bus trips that are completely contained within this interval is exactly K minutes. To simplify the task:

• If there are multiple valid pairs ~(A, B)~, choose the one with the smallest ~A~, and if there's a tie, the smallest ~B~.

• If no such interval exists, print 0 0.

Though the problem is simple in description, it requires precise time handling and efficient searching across a large dataset, a worthy challenge for all algorithm enthusiasts at UMT. Let's work together to solve it!


Input

The first line contains two integers ~N~ and ~K~ ~(1 ≤ N ≤ 10^3, 1 ≤ K ≤ 10^6)~.

The next ~N~ lines (from line 2 to line ~N + 1~) each contain two integers representing the left and right endpoints of a segment. Both endpoints are integers in the range ~0~ to ~10^6~.


Output

Print two integers, A and B. If no such pair exists, print "0 0".

If there are multiple valid pairs, choose the one with the smallest A. If multiple pairs share the same A, choose the one with the smallest B among them.


Sample Input 1

4 25
0 10
3 15
0 8
3 10

Sample Ouput 1

2 9

Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.