An assessment records n candidates. Each candidate has a distinct integer id, a written mark w, and a viva mark v. A candidate's total score is 3 * w + 2 * v. Rank the candidates from highest total score to lowest. When two candidates have the same total score, the one with the smaller id ranks first. Output the ids in ranked order.
Line 1: an integer n.
Each of the next n lines: three integers id w v.
n space-separated integers on one line: the candidate ids in ranked order.
Example 1
Input
3 1 10 5 2 8 20 3 10 5
Expected
2 1 3
Explanation
Scores: id1 = 3*10 + 2*5 = 40, id2 = 3*8 + 2*20 = 64, id3 = 3*10 + 2*5 = 40. id2 ranks first; id1 and id3 tie at 40, so the smaller id 1 comes before 3. Ranked: 2 1 3.
Example 2
Input
2 5 0 0 9 0 0
Expected
5 9
Explanation
Both score 0, so the smaller id wins the tie: 5, 9.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →