#C8742. Top Nominee Determination
Top Nominee Determination
Top Nominee Determination
You are given multiple datasets. In each dataset, every vote is represented by three integers: the voter ID, the nominee ID, and the score awarded. The task is to sum up the scores for each nominee and determine the nominee(s) with the highest total score. In case of a tie, output the nominee IDs in increasing order. If there are no votes in a dataset, output NA.
The input consists of several datasets. A dataset begins with an integer n specifying the number of votes, followed by n lines each containing three space-separated integers. A dataset where n is 0 marks the end of input.
Mathematically, if we denote the score of nominee i as
\(S_i = \sum_{j=1}^{k} s_{ij}\)
where \(s_{ij}\) is the score given in the j-th vote for nominee i, then the winners satisfy \(S_i = \max_j\{S_j\}\).
inputFormat
The input is read from stdin and consists of multiple datasets. Each dataset starts with an integer n indicating the number of votes. This is followed by n lines, each containing three space-separated integers: the voter ID, the nominee ID, and the score. A dataset starting with 0 indicates the end of input and should not be processed.
outputFormat
For each dataset, output a single line to stdout containing the nominee ID(s) with the highest total score. If there is more than one top nominee, output their IDs in increasing order separated by a single space. If a dataset contains no votes (resulting in no nominee score), output NA.
## sample5
1001 2001 8
1002 2001 9
1003 3001 10
1004 3001 7
1005 2001 6
3
1010 2020 5
1020 2020 7
1030 2030 6
2
2010 3010 8
2020 3010 8
0
2001
2020
3010
</p>