#C7111. Organize Teams
Organize Teams
Organize Teams
You are given a list of employees, each with a name and a role. Your task is to organize these employees into teams under the following conditions:
- The size of each team is at most \(n\) (i.e. \(|team| \le n\)).
- Within the same team, no two employees can share the same role, i.e. each employee in a team must have a distinct role.
The teams should be formed in rounds. In each round, select at most one employee per distinct role (following the order of their appearance in the input) until the team reaches size \(n\) or no more unique roles are available. Continue forming teams until all employees have been assigned to a team.
Output each team on a separate line. Within each team, list the employees in the order they were selected, and format each employee as name role
. Separate multiple employees in a single team by a comma and a space.
inputFormat
The first line contains two integers m
and n
, where m
is the number of employees and n
is the maximum allowed team size.
Each of the following m
lines contains two strings separated by a space: the employee's name
and role
.
outputFormat
Output the formed teams, one team per line. For each team, output the employee information in the order they were added. Each employee should be printed in the format name role
, and employees in the same team should be separated by a comma followed by a space.
5 3
John Engineer
Alice Designer
Bob Manager
Eve Engineer
Frank Analyst
John Engineer, Alice Designer, Bob Manager
Eve Engineer, Frank Analyst
</p>