QOJ.ac

QOJ

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

#1990. 餐厅

الإحصائيات

大家都非常高兴能重新出门,去巴黎的餐厅用餐。然而,由于餐厅的座位非常有限,我们希望确保餐厅能尽可能多地接待顾客,并让顾客坐在他们心仪的位置。

我们有 $N$ 位顾客(编号为 $1$ 到 $N$)和 $M$ 家餐厅(编号为 $1$ 到 $M$)。每位顾客会在一个餐厅子集中进行预订,并按偏好顺序给出他们的预订列表。每家餐厅会根据某种偏好顺序对收到的预订进行排序——例如,餐厅可能希望先报名的顾客排名更高。每家餐厅 $i$ 还有一个容量 $c_i$,即它所能容纳的顾客最大数量。

你的任务是找到一种顾客在餐厅中的分配方案,使得满足以下条件:

  1. 没有餐厅安排的顾客数量超过其容量。
  2. 每位顾客最多只能在一家餐厅获得一个座位。
  3. 不存在餐厅 $r$ 和顾客 $c$($c$ 曾预订过 $r$),使得:
    • $c$ 没有获得座位,或者 $c$ 比起他当前获得的餐厅更偏好 $r$,并且
    • $r$ 还有剩余座位,或者 $r$ 已满但比起当前分配给它的一位顾客更偏好 $c$。

其他注意事项: 每位顾客至少进行了一次预订。 餐厅仅对向其表达过预订意向的顾客进行排序。餐厅可能没有顾客希望预订。

输入格式

第一行包含 $N$ 和 $M$。 接下来的 $M$ 行描述容量,其中第 $i$ 行包含一个整数 $c_i$,即餐厅 $i$ 的容量。 接下来的 $N$ 行描述顾客的预订列表,按偏好排序:每行包含一个由空格分隔的互不相同的整数列表(在 $1$ 到 $M$ 之间),按从最偏好到最不偏好的顺序排列。 接下来的 $M$ 行描述餐厅 $i$ 的排序偏好。该行要么包含数字 $0$(表示没有顾客预订餐厅 $i$),要么包含一个由空格分隔的互不相同的整数列表,即预订了餐厅 $i$ 的顾客列表,按餐厅从最偏好到最不偏好的顺序排列。

输出格式

输出在一种可能的分配方案中(根据上述规则)获得座位的顾客集合。输出按顾客编号升序排列,每行一个顾客编号。

数据范围

  • $1 \leqslant N \leqslant 50\,000$
  • $1 \leqslant M \leqslant 10\,000$
  • 预订选项的总数最多为 $1\,000\,000$
  • $1 \leqslant c_i \leqslant N$

样例

样例输入 1

4 4
2
2
2
1
2
2 3
2 1 3
1 2 4 3
3 4
3 2 4 1
3 4 2
4

样例输出 1

2
3
4

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.