An esports league records every match a player takes part in, together with the score the player posted in that match. Match IDs and player IDs come from independent numbering schemes assigned by the league's system. For scouting purposes, analysts need to know, for every player, the ID of the single match where that player scored highest; if a player is tied for their best score across two or more matches, the tie is broken by choosing the smaller match ID.
The first line contains a single integer n, the number of match records.
Each of the next n lines contains three integers playerId, matchId, and score — the score that player posted in that match.
For every distinct player ID that appears in the input, in ascending order of player ID, print a line containing the player ID and the ID of their best match (highest score, ties broken by the smaller match ID), separated by a single space.
Example 1
Input
5 1 101 90 1 102 90 1 103 75 2 201 85 2 202 95
Expected
1 101 2 202
Explanation
Player 1's highest score is 90, achieved in both match 101 and match 102; the tie is broken by choosing the smaller match ID, 101. Player 2's highest score is 95, achieved only in match 202. Players are printed in ascending ID order: 1 before 2.
Example 2
Input
3 5 20 40 5 21 40 5 19 40
Expected
5 19
Explanation
Player 5 scored 40 in three different matches (20, 21, and 19) — a three-way tie for the best score. The tie is broken by the smallest match ID among the tied matches, which is 19, so the output is '5 19'.
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 →