#B4195. Card Game Winner Determination

    ID: 11852 Type: Default 1000ms 256MiB

Card Game Winner Determination

Card Game Winner Determination

In this problem, a card game is played over n rounds. Initially, every player starts with a score of \(0\). In each of the n rounds, one player either gains or loses points. At the end of the game, the final scores of all players are compared. If there is a unique highest score, the player with that score is declared the winner. However, if two or more players share the highest score, the winner is the player among them who reached a score greater than or equal to the final maximum score first during the game.

Note: It is guaranteed that at least one player's final score is positive.

Example

Suppose we have 3 rounds with the following events:

  • Round 1: Alice gains 10 points.
  • Round 2: Bob gains 5 points.
  • Round 3: Bob gains 5 points.

Final scores: Alice = 10, Bob = 10. Although both players have the same final score, Alice reached 10 points in round 1 while Bob reached 10 points later, so Alice is declared the winner.

inputFormat

The input begins with a single integer \(n\) (number of rounds). Each of the following \(n\) lines contains a player's name and an integer representing the points gained (or lost if negative) during that round. The player's name is a string without spaces.

n
name1 score1
name2 score2
... 
namen scoren

outputFormat

Output a single line containing the name of the winner.

sample

3
Alice 10
Bob 5
Bob 5
Alice

</p>