QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 2048 MB Total points: 100

#7950. Lucky Draws

統計

ICPC 委员会正在筹划一场惊喜活动,为参赛队伍加油助威。在比赛开始前,委员会为每支队伍提供了一对数字 $A$ 和 $B$ ($A \le B$),这些数字将用于赛后的幸运抽奖。委员会希望进行 $K$ 次抽奖。在每次抽奖中,委员会会选择一个数字 $C$,所有满足 $A \le C \le B$ 的队伍在本次抽奖中获胜。为了让更多的队伍感到高兴,委员会希望提前选定 $K$ 次抽奖所用的 $K$ 个数字,使得获胜的队伍数量最多。一支队伍可以多次获胜,但只会被计为获胜一次。

例如,有五支队伍参加 ICPC,他们的数字对分别是 $(1, 2), (1, 4), (3, 6), (4, 7)$ 和 $(5, 6)$,且 $K = 2$。当委员会选择数字 2 和 4 时,持有 $(1, 2), (1, 4), (3, 6)$ 和 $(4, 7)$ 的四支队伍获胜。持有 $(1, 4)$ 的队伍获胜了两次,因为它包含两个被选中的数字。事实上,如果选择 2 和 5,所有五支队伍都可以获胜。获胜队伍的最大数量为五。

给定 $n$ 支队伍的数字对以及幸运抽奖的次数 $K$,请编写一个程序,输出获胜队伍的最大数量。

输入格式

程序从标准输入读取数据。输入的第一行包含两个整数 $n$ 和 $K$ ($1 \le n \le 10,000$, $1 \le K \le n$, $1 \le n \times K \le 500,000$),其中 $n$ 是队伍数量,$K$ 是幸运抽奖次数。接下来的 $n$ 行,每行包含两个整数 $A$ 和 $B$,表示一支队伍的数字对,其中 $-10^6 \le A \le B \le 10^6$。

输出格式

程序向标准输出写入数据。仅打印一行,包含获胜队伍的最大数量。多次获胜的队伍仅计为一次。

样例

输入 1

5 2
1 2
1 4
3 6
4 7
5 6

输出 1

5

输入 2

3 2
2 4
1 3
3 5

输出 2

3

输入 3

4 1
2 3
1 1
4 5
4 5

输出 3

2

输入 4

7 2
5 6
7 9
7 7
1 4
2 3
4 7
4 7

输出 4

6

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.