QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 1024 MB 总分: 100

#7546. 你们都是赢家

统计

营地委员会正在计划举办一场有趣的活动来为参赛队伍加油。在比赛前,委员会为每支队伍提供了一对整数 $A$ 和 $B$ ($A \le B$),这些数字将用于比赛后的幸运抽奖。委员会希望进行 $K$ 次抽奖。在每次抽奖中,委员会会选择一个整数 $C$,所有满足 $A \le C \le B$ 的队伍即为本轮抽奖的获胜者。为了让更多的队伍感到高兴,委员会希望提前选定这 $K$ 个用于抽奖的整数,使得获胜的队伍数量最多。如果一支队伍赢得了多次抽奖,它仍然只被计算一次。

例如,假设有五支队伍参赛,他们的数字对分别是 $(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 \cdot 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.