All problems

Arcade Podium

Medium · heap

An arcade shows a podium for its k best players. Nobody has played yet. You are given a list of operations: operations[i] is either "add" or "podium", and args[i] holds its arguments: [player, points] for an "add" and [] (empty) for a "podium".

Return a list with the answer to every "podium", in the order they appear.

Examples

Example 1

Input: k = 2, operations = ["add", "add", "podium", "add", "podium", "add", "podium"], args = [[7, 5], [3, 4], [], [9, 6], [], [3, 4], []]

Output: [9, 11, 14]

Two players have been seen at first, so the podium is 5 + 4. Player 9 arrives with 6, so the best two are 6 and 5. Player 3 then reaches 8, so the best two are 8 and 6.

Example 2

Input: k = 1, operations = ["podium", "add", "podium", "add", "podium"], args = [[], [4, 2], [], [8, 3], []]

Output: [0, 2, 3]

Nobody has played at first, so the first podium is 0. Then player 8 with 3 points beats player 4 with 2.

Constraints