P5778 [CTSC2001] GPA Ranking System

Description

At present, universities and colleges often use GPA *(Grade Point Average)* to evaluate students’ academic performance. The traditional ranking method is to compute each student’s average score and rank students based on that average. However, this ranking method has caused controversy in education and in society, because it has many drawbacks. For different courses, the average score of enrolled students is affected to different degrees by the difficulty of the course and how strict the instructor is. Therefore, this ranking system indirectly encourages students to choose easier courses, because they can get a higher average score with less effort. To overcome these drawbacks, we need to improve the ranking system. One improved approach is to add a specific adjustment value $d_i$ to the score of every student who takes course $i$. For example, the score $G_{ij}$ of student $j$ in this course is changed to $G’_{ij}=G_{ij}+d_i$. The goal is that, after adjustment, the average score of this course equals the average of all courses taken by all students who take this course. Perform such an adjustment for every course so that the above condition holds for all courses. This adjustment method can reduce the unfairness of the traditional ranking system to some extent. Your task is to produce the ranking based on the scores of students in one grade of a university for one academic year. Assume that every student takes at least one course.

Input Format

The first line contains two positive integers $m$ and $n$, representing the number of students and the number of courses. The next $m$ lines form a matrix. The element in row $i$, column $j$ represents the score $G_{ij}$ of student $i$ in course $j$. If the student did not take this course, then $G_{ij}=-1$. Since this approach is only used to obtain a more scientific ranking, the absolute values of the adjusted scores themselves are not meaningful, so the adjusted scores do not have to be within $0\sim 100$.

Output Format

Output the ranking of these students under the improved approach. Output student indices, one per line. If, after the adjustment, several students have the same average score (accurate to three digits after the decimal point), then they share the same rank, and they should be output in lexicographical order. Of course, in many cases, the adjustment above cannot be carried out successfully, meaning the target cannot be achieved. (Therefore, in real problems, we often find an adjustment scheme that is closest to the target in the least-squares sense.) It is also possible that the students’ ranks cannot be determined because the adjustment is not unique. If either of the above two situations occurs, output `fail`.

Explanation/Hint

#### Sample Explanation One feasible adjustment method is: Add $10$ to each student’s score in the first course, and add $35$ to each student’s score in the second course. The adjusted results are: ```plain 70 –1 80 –1 90 80 -1 100 ``` After adjustment, the average score of the first course is: $(70+80+90)/3=80$. The average of all courses taken by all students who take the first course is: $(70+80+90+80)/4=80$. The average score of the second course is: $(80+100)/2=90$. The average of all courses taken by all students who take the second course is: $(90+80+100)/3=90$. Then, compute each student’s average score and rank them, and you obtain the output result. #### Constraints For all testdata, $1\le m\le 500$, $1\le n\le 100$, $-1\le G_{ij}\le 100$。 Translated by ChatGPT 5