QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 1024 MB Puntuación total: 100

#5383. 娱乐盒

Estadísticas

Ada、Bertrand 和 Charles 经常为看哪部电视节目而争吵,为了避免争执,他们最终决定购买一台录像机。这台功能强大的新设备可以同时录制 $k$ 个不同的电视节目,并且每当机器的 $k$ 个插槽中的一个节目结束时,该插槽会立即准备好录制另一个节目。

这三位朋友想知道他们一天内最多能录制多少个电视节目。他们为你提供了当天的电视节目指南,并告诉你机器可以同时录制的节目数量。请问使用这台录像机,他们最多能录制多少个节目?只统计完整录制的节目。

Wikimedia, cc-by-sa

输入格式

输入的第一行包含两个整数 $n, k$ ($1 \le k < n \le 100\,000$)。接下来 $n$ 行,每行包含两个整数 $x_i, y_i$,表示节目 $i$ 在时间 $x_i$ 开始,在时间 $y_i$ 结束。这意味着两个节目 $i$ 和 $j$,若满足 $y_i = x_j$,可以在同一个录制插槽中录制,且不会产生冲突。你可以假设 $0 \le x_i < y_i \le 1\,000\,000\,000$。

输出格式

输出仅包含一行,即一个整数:使用录像机可以录制的电视节目指南中完整节目的最大数量。

样例

样例输入 1

3 1
1 2
2 3
2 3

样例输出 1

2

样例输入 2

4 1
1 3
4 6
7 8
2 5

样例输出 2

3

样例输入 3

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

样例输出 3

3

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.