QOJ.ac

QOJ

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

#5011. 选课

الإحصائيات

Wonderfulness 大学不小心录取了比其教学能力更多的学生。不幸的是,这意味着一些课程可能会满员,而一些学生可能无法选修他们想上的课程。你能帮助大学处理这种情况吗?

每位学生选择了 5 门他们想上的课程。每门课程都有一个硬性的人数限制。你的任务是在遵守课程人数限制的前提下,尽可能多地为每位学生安排他们选择的课程。

学生的幸福度等于他们被录取的课程数量。如果他们能选上所有 5 门想上的课程,他们的幸福度就是 5。如果其中两门课程已满,他们只能选上 5 门中的 3 门,那么他们的幸福度就只有 3。大学希望最大化所有学生的幸福度之和。

这个目标可以用另一种等价的方式来表述。每位学生每选修一门课程需支付 $1000 的学费。选修了全部 5 门课程的学生支付 $5000。只选修了 5 门课程中的 3 门的学生支付 $3000。大学希望最大化其收取的学费总额。

你的任务是在遵守限制条件的同时,为学生分配课程,并最大化学生的总幸福度以及收取的学费总额。

输入格式

输入的第一行包含两个由空格分隔的整数 $5 \le c \le 1000$(课程数量)和 $1 \le s \le 10000$(学生数量)。接下来有 $c$ 行,第 $i$ 行包含一个整数 $1 \le m_i \le 10000$,表示第 $i$ 门课程最多能容纳的学生人数。这 $c$ 行之后是 $s$ 行,每行对应一名学生。每行包含五个由空格分隔的不同整数,表示该学生想上的五门课程。每个课程编号都是一个 $1 \le i \le c$ 的整数,对应于输入中第 $c$ 行之后给出的第 $i$ 门课程的限制 $m_i$。

输出格式

输出的第一行应包含一个整数,即可以达到的最大幸福度之和。第一行输出之后应跟随 $s$ 行,每行对应一名学生,顺序与输入相同。每行应包含 0 到 5 个由空格分隔的整数,表示该学生为了达到第一行输出的最大幸福度之和而被录取的课程编号 $1 \le i \le c$。

如果存在多种课程分配方案能达到相同的最大幸福度之和,输出其中任意一种即可。

样例

样例输入 1

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

样例输出 1

9
1 2 3 4 5
2 3
3 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.