#T231. 奖学金

奖学金

Description

A certain primary school recently received a sponsorship and decided to allocate part of it to award scholarships to the top 5 students with outstanding academic performance.

At the end of the term, each student has grades for three subjects: Chinese, Mathematics, and English. The students are first ranked based on their total scores in descending order. If two students have the same total score, they are then ranked by their Chinese scores in descending order. If both the total scores and Chinese scores are the same, the student with the smaller student ID is ranked higher. This ensures that each student's ranking is uniquely determined.

Task: First, calculate the total score for each student based on the input grades for the three subjects. Then, sort the students according to the rules mentioned above. Finally, output the student IDs and total scores of the top five students in order of their ranking.

Note: Among the top five students, each scholarship amount is different, so you must strictly follow the sorting rules. For example, in a correct solution, if the first two lines of output (each line contains two numbers: student ID and total score) are:

7 279  
5 279  

This means the student IDs of the two highest-scoring students are 7 and 5, respectively. Both students have the same total score of 279 (the sum of their Chinese, Mathematics, and English grades), but the student with ID 7 has a higher Chinese score. If your output for the top two students is:

5 279  
7 279  

it will be considered incorrect, and no points will be awarded.

Input Format

The input consists of n+1 lines:

  • The first line contains a positive integer n (less than 300), representing the number of students participating in the selection.
  • Lines 2 to n+1 each contain three space-separated numbers, each between 0 and 100.
  • The three numbers in the j-th line represent the Chinese, Mathematics, and English grades of the student with ID j-1.
  • Each student's ID is sequentially numbered from 1 to n (which corresponds to the input line number minus 1).

Output Format

The output consists of 5 lines. Each line contains two space-separated positive integers, representing the student ID and total score of the top five students in order.

7 279
5 279

5 279
7 279