QOJ.ac

QOJ

حد الوقت: 2.0 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓

#10492. 流水线

الإحصائيات

流水线上有 $k$ 名工人,编号为 $1$ 到 $k$,每人都有一个收件箱。他们将处理 $n$ 个工件,其中第 $i$ 个工件将在第 $t_i$ 分钟开始时被放入第 $w_i$ 号工人的收件箱中。每一分钟,按顺序发生以下事件:

  1. 新的工件(如果有)被添加到某些工人的收件箱中。
  2. 如果工人的收件箱不为空,他/她会从箱中取出一个工件并进行处理。此事件对所有工人同时发生。
  3. 如果工人刚刚处理完一个工件:
    • 对于工人 $1 \le i < k$,他/她将工件放入工人 $(i + 1)$ 的收件箱中。
    • 对于工人 $k$,他/她将工件放入发货箱中,该工件即告完成。 此事件也对所有工人同时发生。

这些工人需要多少分钟才能完成所有 $n$ 个工件?

输入格式

输入包含多组测试数据。第一行包含一个整数 $T$ ($1 \le T \le 10^4$),表示测试数据组数。对于每组测试数据:

第一行包含两个整数 $n$ 和 $k$ ($1 \le n \le 2 \times 10^5, 1 \le k \le 10^9$),分别表示工件数量和工人数量。

接下来的 $n$ 行中,第 $i$ 行包含两个整数 $w_i$ 和 $t_i$ ($1 \le w_i \le k, 1 \le t_i \le 10^9$),表示第 $i$ 个工件将在第 $t_i$ 分钟开始时被放入第 $w_i$ 号工人的收件箱中。

保证所有测试数据的 $n$ 之和不超过 $2 \times 10^5$。

输出格式

对于每组测试数据,输出一行,包含一个整数,表示完成所有 $n$ 个工件所需的分钟数。

样例

输入 1

2
4 3
3 2
2 1
3 2
1 2
2 10
1 7
4 20

输出 1

5
26

说明

我们现在解释第一个样例测试数据。下表显示了每一分钟第 1 个事件和第 3 个事件之后所有收件箱中的工件数量。数字由序列 $\{c_1, c_2, c_3\}$ 给出,其中 $c_i$ 是第 $i$ 号工人收件箱中的工件数量。

分钟 事件 1 事件 3
1 $\{0, 1, 0\}$ $\{0, 0, 1\}$
2 $\{1, 0, 3\}$ $\{0, 1, 2\}$
3 $\{0, 1, 2\}$ $\{0, 0, 2\}$
4 $\{0, 0, 2\}$ $\{0, 0, 1\}$
5 $\{0, 0, 1\}$ $\{0, 0, 0\}$

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.