2609.Restaurant

Time Limit: 1s Memory Limit: 256MB

A restaurant received n orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the i-th order is characterized by two time values - the start time li and the finish time ri (li \le ri).

Restaurant management can accept and reject orders. What is the maximal number of orders the restaurant can accept?

No two accepted orders can intersect, i.e. they can't share even a moment of time. If one order ends in the moment other starts, they can't be accepted both.

Input Format(From the terminal/stdin)

The first line contains integer number n (1 \le n \le 5 \cdot 105) - number of orders. The following n lines contain integer values li and ri each (1 \le li \le ri \le 109).

Output Format(To the terminal/stdout)

Print the maximal number of orders that can be accepted.

Sample Input 1

Copy
2
7 11
4 7
 \n
 ·  \n
 · \n

Sample Output 1

Copy
1
 \n

Sample Input 2

Copy
5
1 2
2 3
3 4
4 5
5 6
 \n
 · \n
 · \n
 · \n
 · \n
 · \n

Sample Output 2

Copy
3
 \n

Sample Input 3

Copy
6
4 8
1 5
4 7
2 5
1 3
6 8
 \n
 · \n
 · \n
 · \n
 · \n
 · \n
 · \n

Sample Output 3

Copy
2
 \n

Submit

请先 登录

© 2025 FAQs