407877: GYM102916 A Absenteeism

Memory Limit:512 MB Time Limit:4 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Absenteeismtime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputAbsenteeism is a habitual pattern of absence from a duty or obligation without good reason.Wikipedia

Alex works at work. n employees work together with him. Unlike Alex, they strictly follow their schedule: the i-th employee comes to work at the time moment ai and leaves at the time moment bi (ai < bi).

Alex has to come to work not earlier the time moment 0, leave not later the time moment m and work for k hours a day (k ≤ m). But, of course, he wants to work as little as possible. The problem is, his colleagues don't like lazy people, and if one of them discovers that Alex works less than k hours a day, they will complain to the boss and Alex will be fired.

In other words, let's say Alex comes to work at the time moment x and leaves work at the time moment y, where 0 ≤ x < y ≤ m. Then Alex is in danger if at least one of the following conditions is satisfied:

  • y - x < k, and there exists an employee i such that ai ≤ x and y ≤ bi (the segment [x, y] is entirely nested into [ai, bi]) — in this case the i-th employee sees how Alex works less than k hours with their own eyes;
  • there exists an employee i such that x < ai ≤ y ≤ bi, and y < k — in this case the i-th employee sees how Alex leaves work earlier than the time moment k;
  • there exists an employee i such that ai ≤ x ≤ bi < y, and x > m - k — in this case the i-th employee sees how Alex comes to work later than the time moment m - k;
  • there exists an employee i such that y < ai or bi < x (the segments [x, y] and [ai, bi] don't intersect), and ai ≤ k and bi ≥ m - k — in this case the i-th employee doesn't see Alex at work at all, but it's exactly the reason they conclude Alex couldn't work for k hours.

What is the minimal time Alex can spend at work such that nobody of his colleagues complains to the boss?

Input

The first line contains three integers n, m, k (1 ≤ n ≤ 105, 1 ≤ m ≤ 109, 1 ≤ k ≤ m) — the number of employees working together with Alex, the day length and the number of hours Alex has to work in a day.

Each of the following n lines contains two integers ai and bi (0 ≤ ai < bi ≤ m) — the moments of time when the i-th employee comes to work and leaves work.

Output

If Alex is able not to come to work at all, output "-1 -1".

Otherwise, output two integers x, y (0 ≤ x < y ≤ m, y - x ≤ k) — the moments of time when Alex should come to work and leave work so that nobody of his colleagues complains to the boss and the working time is minimal.

If there are several possible solutions, output any of them.

ExamplesInput
2 20 10
0 12
8 20
Output
7 13
Input
2 20 18
0 10
10 20
Output
2 18

加入题单

算法标签: