Road Repair
The national road is in bad condition. The pavement is damaged and needs immediate repair. Unfortunately, the repair crew assigned to the task is not very organized. Every day, they start repairing a continuous section of the road, which we know where it begins and ends. However, it is possible that on some subsequent day they may repair a section that has already been fully or partially repaired!
The national road has a total length of kilometers. The crew has scheduled to work for days, and on the -th day, they plan to repair the section of the road that extends from position to position . The Ministry of Public Works wants the repair to be completed as soon as possible. It wants to know after how many days the length of the longest continuous section of the road that has not yet been repaired will not exceed .
Problem
Write a program in one of the IOI languages which, given the length of the road, the repair crew's schedule (, , ), and the number , finds the minimum number of days the crew must work so that the length of the longest continuous section of the road that has not yet been repaired does not exceed . If this is never going to happen based on the crew's schedule, your program should print the number .
Input Files:
The input files named roadwork.in are text files structured as follows: The first line contains three integers: , , and , separated in pairs by a single space. This is followed by lines, each containing two integers , , separated by a single space.
Output Files:
The output files named roadwork.out are text files consisting of a single line containing a single integer .
Examples of Input - Output Files:
1st
STDIN (roadwork.in)
4 30 6
1 5
11 27
2 14
18 28
STDOUT (roadwork.out)
2
2nd
STDIN (roadwork.in)
4 30 1
1 5
11 27
2 14
18 28
STDOUT (roadwork.out)
-1
Explanation of the examples:
In both examples, the length of the road and the schedule of the repair crew are the same, and only differs. After the first day, the longest continuous section of the road that has not yet been repaired has a length of (from position to position ). After the second day, it has a length of (from position to position ). After the third day, it has a length of (from position to position ), and after the fourth day, it has a length of (from position to position ). Therefore, the correct answer for the 1st example is (after the second day, the length of the longest continuous section of the road will not exceed ), while for the 2nd example, the correct answer is (the length of the longest continuous section of the road that has never been repaired will never become equal to or less).
Formatting: In the output, each line terminates with a newline
character.
Maximum execution time: 2 sec.
Maximum available memory: 64 MB.
Comments