#K13671. Team Leaderboard using HackCraft
Team Leaderboard using HackCraft
Team Leaderboard using HackCraft
In this problem, you are required to implement a scoring system for teams. You must design a module called HackCraft
that supports three operations:
- add team_name member_name score: Adds a new member to a team and increases the team's total score by the given score. If the team does not exist, it is created.
- score team_name member_name new_score: Updates the score of an existing member. The team's total score is adjusted by the difference between the new score and the previous score.
- max_score: Returns the name of the team with the highest total score. In case of a tie, choose the team with the lexicographically smallest name.
All operations are supplied via the standard input. For every max_score
operation, you are required to output the winning team.
Formally, if a team has members with scores \(s_1, s_2, \ldots, s_k\), the total team score is \(S = \sum_{i=1}^k s_i\). Your solution should efficiently update this sum and determine the team with maximum \(S\) after a series of operations.
inputFormat
The first line of input contains an integer T representing the number of operations. Each of the next T lines contains one operation in one of the following formats:
add team_name member_name score
score team_name member_name new_score
max_score
All input is read from standard input.
outputFormat
For each max_score
operation, output the name of the team with the highest total score on a new line to standard output.
3
add TeamA Alice 50
add TeamA Bob 30
max_score
TeamA
</p>