CF809D.Hitchhiking in the Baltic States

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Leha and Noora decided to go on a trip in the Baltic States. As you know from the previous problem, Leha has lost his car on the parking of the restaurant. Unfortunately, requests to the watchman didn't helped hacker find the car, so friends decided to go hitchhiking.

In total, they intended to visit nn towns. However it turned out that sights in ii -th town are open for visitors only on days from lil_{i} to rir_{i} .

What to do? Leha proposed to choose for each town ii a day, when they will visit this town, i.e any integer xix_{i} in interval [li,ri][l_{i},r_{i}] . After that Noora choses some subsequence of towns id1,id2,...,idkid_{1},id_{2},...,id_{k} , which friends are going to visit, that at first they are strictly increasing, i.e idi<idi+1id_{i}<id_{i+1} is for all integers ii from 11 to k1k-1 , but also the dates of the friends visits are strictly increasing, i.e xidi<xidi+1x_{idi}<x_{idi+1} is true for all integers ii from 11 to k1k-1 .

Please help Leha and Noora in choosing such xix_{i} for each town ii , and such subsequence of towns id1,id2,...,idkid_{1},id_{2},...,id_{k} , so that friends can visit maximal number of towns.

You may assume, that Leha and Noora can start the trip any day.

输入格式

The first line contains a single integer nn ( 1<=n<=31051<=n<=3·10^{5} ) denoting the number of towns Leha and Noora intended to visit.

Each line ii of the nn subsequent lines contains two integers lil_{i} , rir_{i} (1<=li<=ri<=109)(1<=l_{i}<=r_{i}<=10^{9}) , denoting that sights in ii -th town are open for visitors on any day .

输出格式

Print a single integer denoting the maximal number of towns, that Leha and Noora can visit.

输入输出样例

  • 输入#1

    5
    6 6
    1 2
    3 4
    2 2
    1 4
    

    输出#1

    3
    

说明/提示

Consider the first example.

Let's take this plan: let's visit the sight in the second town on the first day, in the third town on the third day and in the fifth town on the fourth. That's would be the optimal answer.

首页