Hackathon leaderboard with dense ranks
A coding club in Lagos runs a weekly hackathon. Players submit several tasks and every submission earns points. The final leaderboard adds up each player's points. Names are typed freely, so ada OKAFOR and Ada Okafor are the same player: names are compared after trimming, collapsing runs of spaces into one and ignoring upper/lower case. A player is shown with the spelling of their first submission (after trimming and collapsing spaces).
Ranks are dense: the best total gets rank 1, and players with the same total share a rank; the next lower total gets the next rank number (1, 1, 2, 3, 3, 4 ...). Within one rank players are ordered by name, ignoring case, in alphabetical order.
Task: line 1 is K, line 2 is N, then N lines of the form name, points (a comma, points is a non-negative integer, spaces around it are possible). Print every player whose rank is at most K, one per line as rank. name - total, for instance 2. Ada Okafor - 140.
Sample tests
Input
2 7 Ada Okafor, 50 li Wei, 70 ada okafor , 40 Mateo Silva, 70 John Doe, 10 Priya Nair, 90 John DOE, 5
Expected output
1. Ada Okafor - 90 1. Priya Nair - 90 2. li Wei - 70 2. Mateo Silva - 70
Input
1 3 beta, 10 Alpha, 10 gamma, 9
Expected output
1. Alpha - 10 1. beta - 10
Your answer is also checked against 3 hidden tests.
Log in or create a free account to run your code, submit and earn points.
Run your code to see the output here. Ctrl + Enter also runs it.
