Design a class Season that keeps the scoreboard of a gaming season:
Season()starts with no players.add(player, points)addspoints(a positive integer) toplayer's total. A player who is not on the board yet joins with total0first.top(k)returns the sum of thekhighest totals on the board. If fewer thankplayers are on the board, sum all of them (an empty board gives0).reset(player)removesplayerfrom the board (a lateraddstarts them again from0). Resetting a player who is not on the board does nothing.
Examples
ops: ["Season", "add", "add", "add", "add", "top", "reset", "top", "top", "add", "top"]
args: [[], ["ana", 40], ["bo", 25], ["cy", 50], ["bo", 30], [2], ["bo"], [2], [5], ["bo", 5], [3]]
Output: [None, None, None, None, None, 105, None, 90, 90, None, 95]
Explanation: bo reaches 55, so the top two are 55 + 50. After the reset the top two are cy and ana (90);
bo comes back with 5, and the top three sum to 50 + 40 + 5.
Constraints
1 <= points <= 1000,1 <= k <= 10**4, up to10**4calls in total- Target:
addandresetinO(1),top(k)inO(n log k)fornplayers on the board
Goals
- Keep running totals per player in a dictionary
- Sum the k largest totals without sorting everything