Recruiting New SCCC Members
InterviewTime limit2sMemory limit1024 MB
Assign applicants in descending score order to K groups of capacity X, accepting each one only if all accepted applicants can still be seated, moving earlier ones if needed.
Problem
Chansol, the president of SCCC, is running the selection process for new members in the first semester of 2023. In that semester, SCCC runs study groups, each with a capacity of . Each new member must join exactly one of the study groups. An applicant who cannot join any study group cannot be accepted, so every applicant selects at least one study group they can join.
Chansol gave the applicants distinct scores after a fair and strict review. To assign the new members to study groups, he sorts the applicants from the highest score to the lowest and assigns them one at a time.
Consider the moment when the applicant with the -th highest score is about to be assigned. If the applicant can be added while keeping the set of people already assigned to the studies, the applicant is assigned. Otherwise, if no seat remains for the applicant no matter how the people already assigned are moved, the applicant cannot be assigned.
For example, let , , , and let the study groups each applicant can join, from the highest score, be .
Suppose the highest and second highest applicants are both assigned to group 1, and the third applicant is next. Move the second applicant to group 2, then assign the third applicant to group 1. The people already assigned remain in the study groups, so the third applicant is accepted.
On the other hand, suppose group 1 holds the first and third applicants and group 2 holds the second applicant. No arrangement lets the fourth applicant be assigned. The lowest-scoring applicant can still join group 2. The final result is that group 1 holds the first and third applicants, and group 2 holds the second and fifth applicants.
Chansol wants to assign the applicants by these rules. Write a program that finds the number of people assigned to study groups and the list of applicants in each study group.
Input
The first line contains the number of applicants , the number of study groups , and the capacity of each study group , separated by spaces.
From the second line onward, the -th of the lines gives the information for the -th applicant ().
Each line starts with the number of study groups the applicant can join, followed by the study group numbers , separated by spaces.
The line contains the scores of the students, separated by spaces.
Output
Print lines. The -th line describes group ().
Each line starts with the number of people assigned to that study group, followed by the numbers of the assigned people, separated by spaces.
If several answers exist, you may print any of them. The order of the assigned people in each line does not matter.
Constraints
- If , then . In other words, every element in a row is distinct.
- If , then . In other words, every element of is distinct.
- All numbers in the input are integers.