#C4982. Balanced Teams Formation
Balanced Teams Formation
Balanced Teams Formation
You are given the task of dividing employees into teams of a fixed size k such that the difference between the highest and lowest scores in each team is minimized. To achieve this, you need to sort the scores in ascending order and then group them into contiguous subarrays of length k. Finally, format and output each team on a new line.
In mathematical terms, if you have a list of scores \(S = [s_1, s_2, \dots, s_n]\) and a team size \(k\), then after sorting \(S\) into \(S' = [s'_1, s'_2, \dots, s'_n]\), you are required to form teams \(T_i = [s'_{(i-1)k+1}, s'_{(i-1)k+2}, \dots, s'_{ik}]\) for each valid \(i\) such that \(\max T_i - \min T_i\) is minimized.
inputFormat
The input consists of one or more datasets. Each dataset is provided in a single line as space-separated integers. The first integer n represents the number of employees, the second integer k represents the team size, followed by \(n\) integers denoting the employee scores. Input is terminated by a line where the first integer is 0.
outputFormat
For each dataset, output the formed teams. Each team should appear on its own line in the format:
Team i: s1 s2 ... sk
where i is the team number (starting from 1) and \(s1, s2, \dots, sk\) are the scores in the team.
## sample6 2 10 20 30 40 50 60
0
Team 1: 10 20
Team 2: 30 40
Team 3: 50 60
</p>