#K79602. Top Students Selector
Top Students Selector
Top Students Selector
Janet has a list of students' names along with their marks in Mathematics, Science, and English. Your task is to select the top \(K\) students based on their average marks. The average marks for each student is given by: \(\text{avg} = \frac{m_1 + m_2 + m_3}{3}\). In the case of two or more students having the same average, they should be sorted alphabetically by their names.
Each test case begins with two integers \(n\) and \(K\) where \(n\) is the number of students and \(K\) is the number of top students to choose. This is followed by \(n\) lines where each line contains a student's name and their marks in the three subjects.
inputFormat
The input is read from standard input (stdin). The first line contains an integer (t) (1 ≤ (t) ≤ 50) representing the number of test cases. For each test case:
- The first line contains two integers (n) (1 ≤ (n) ≤ 1000) and (K) (1 ≤ (K) ≤ (n)).
- Each of the next (n) lines contains a student's name (a non-empty string of at most 100 characters) followed by three integers (m_1), (m_2), (m_3) (0 ≤ marks ≤ 100) representing the marks in Mathematics, Science, and English respectively.
outputFormat
For each test case, output exactly (K) lines to standard output (stdout). Each line should contain the name of one of the top students. The names must be listed in descending order of their average marks, and in the case of equal averages, in ascending alphabetical order.## sample
1
4 2
Alice 78 82 91
Bob 88 90 85
Charlie 85 83 87
David 90 91 89
David
Bob
</p>