Grade Book
Time limit1sMemory limit256 MB
Each lecture's grade is available in office p at minute t every day; starting anywhere at minute 1, find the fewest days to collect all grades.
- Level
Medium7 of 10
- Topics
- Greedy, Sorting, Intervals, Binary search
- Solved
- No attempts yet
Problem
Maggy is a die hard: she still has a grade book and collects hand written grades from her lecturers. The lecturers' offices are numbered with consecutive natural numbers, starting from , and are located along an infinite corridor. The grade from each lecture can be picked up daily, but only in a specific office and only for one minute during the day. Receiving a grade takes a negligible amount of time, but moving between adjacent offices, in any direction, takes exactly minute. A single lecturer can read several different lectures and then they may, although do not have to, give the grades for some of them at the same time; in such a case, receiving any number of grades still takes a negligible amount of time.
Maggy attended lectures and for each of them she knows in which office and in which minute of the day she can get the grade. Every day Maggy gets up early, so that in minute she can be in any office. Help her determine the minimum number of days she needs to collect all the grades.
Input
The first line of the input contains one integer () denoting the number of lectures Maggy attended.
In each of the next lines there is a description of one lecture. One description consists of two integers (), separated by a single space, meaning that a grade from this lecture can be obtained daily in office in the -th minute counted from the beginning of each day.
Output
You should write one integer number in the first and only line of the output: the minimal number of days Maggy needs to pick up all grades.
Hint
On the first day Maggy can collect all grades from office number 1. On the second day she is able to collect grades in offices 2 and 3, and on the third day in offices 4 and 5.