Top Scorer
Completed
Read n lines name points (a name may repeat — add up the points). Print the name with the most total points and that total. Break ties alphabetically.
Input
Line 1: n. Then n lines.
Output
name total
Example
Input
4 ann 10 bob 15 ann 7 cy 3
Output
ann 17
Editor
Python
Hints
Sum points per name in a dict.
Sort/compare by (-total, name) to handle ties.
Solution explanation
A key of (-total, name) means "highest total first, then alphabetical".
Show solution
n = int(input())
totals = {}
for _ in range(n):
name, pts = input().split()
totals[name] = totals.get(name, 0) + int(pts)
best = min(totals, key=lambda name: (-totals[name], name))
print(best, totals[best])