200763: [AtCoder]ARC076 F - Exhausted?

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $1000$ points

Problem Statement

There are $M$ chairs arranged in a line. The coordinate of the $i$-th chair $(1 ≤ i ≤ M)$ is $i$.

$N$ people of the Takahashi clan played too much games, and they are all suffering from backaches. They need to sit in chairs and rest, but they are particular about which chairs they sit in. Specifically, the $i$-th person wishes to sit in a chair whose coordinate is not greater than $L_i$, or not less than $R_i$. Naturally, only one person can sit in the same chair.

It may not be possible for all of them to sit in their favorite chairs, if nothing is done. Aoki, who cares for the health of the people of the Takahashi clan, decides to provide additional chairs so that all of them can sit in chairs at their favorite positions.

Additional chairs can be placed at arbitrary real coordinates. Find the minimum required number of additional chairs.

Constraints

  • $1 ≤ N,M ≤ 2 × 10^5$
  • $0 ≤ L_i < R_i ≤ M + 1(1 ≤ i ≤ N)$
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

$N$ $M$
$L_1$ $R_1$
$:$
$L_N$ $R_N$

Output

Print the minimum required number of additional chairs.


Sample Input 1

4 4
0 3
2 3
1 3
3 4

Sample Output 1

0

The four people can sit in chairs at the coordinates $3$, $2$, $1$ and $4$, respectively, and no more chair is needed.


Sample Input 2

7 6
0 7
1 5
3 6
2 7
1 6
2 6
3 7

Sample Output 2

2

If we place additional chairs at the coordinates $0$ and $2.5$, the seven people can sit at coordinates $0$, $5$, $3$, $2$, $6$, $1$ and $2.5$, respectively.


Sample Input 3

3 1
1 2
1 2
1 2

Sample Output 3

2

Sample Input 4

6 6
1 6
1 6
1 5
1 5
2 6
2 6

Sample Output 4

2

Input

题意翻译

有 $m$ 个椅子在数轴上排列,第 $i$ 张椅子的坐标为i。 高桥君和他的朋友一共有 $n$ 个人。高桥君他们因为玩了太久的游戏,大家的腰和背都很痛,所以他们很有必要坐在椅子上休息一下。 高桥君他们每个人坐的椅子的坐标都很讲究,第 $i$ 个人想坐在坐标在 $l_i$ 以下(包括 $l_i$)的椅子上,或者坐在坐标在 $r_i$ 以上(包括 $r_i$)的椅子上。当然,一个的椅子只能坐一个人。 可这样计算下去,可能会让他们不能都坐在椅子上休息。青木君关心高桥君他们的健康,尽可能多地增加椅子,让高桥君他们都能够坐在椅子上休息。 椅子可以添加到任意的实数坐标上,请求出需要添加椅子数量的最小值。 ## 输入输出格式 ### 输入 第一行输入两个数 $n$ 和 $m$。 接下来的第二行到 $n+1$ 行依次输入 $l_i$ 和 $r_i$。 ### 输出 输出需要添加的椅子数量的最小值 ## 数据范围 $1 \leq N,M \leq 2\times 10^5$,$0\leq l_i < r_i \leq M+1$。所有的数都是整数 ## 样例解释 ### 样例一: $4$ 个人依次坐在坐标为 $3, 2, 1, 4$ 的椅子上,所以椅子不需要添加。 ### 样例二: 如果将椅子添加到坐标 $0$ 和 $7$,则可以将 $7$ 人按顺序放在坐标 $0, 5, 3, 2, 6, 1, 7$ 中。

加入题单

上一题 下一题 算法标签: