#K67382. Taco Task Manager

    ID: 32630 Type: Default 1000ms 256MiB

Taco Task Manager

Taco Task Manager

Implement a Task Manager that supports adding tasks with priorities, updating their priorities, retrieving the task with the highest priority, removing tasks, and listing all tasks sorted by descending priority. When multiple tasks have the same priority, the one added first should be returned first.

The commands to be supported are:

  • ADD <task> <priority>: Adds a new task or updates the priority of an existing task. The original insertion order is preserved even if the task's priority is updated.
  • REMOVE <task>: Removes the specified task. If the task does not exist, do nothing.
  • GET: Prints the task with the highest priority. If there are multiple tasks with the same priority, the one that was added earliest is printed. If no tasks exist, print an empty line.
  • ALL: Prints all tasks sorted by descending priority. For tasks with the same priority, the order of insertion determines the order; tasks added earlier come first. The tasks should be printed on one line separated by a single space. If no tasks are available, print an empty line.

You are required to read the input from stdin and output the results to stdout.

inputFormat

The first line contains an integer Q, the number of commands.

Each of the next Q lines contains one of the following commands:

  • ADD <task> <priority>
  • REMOVE <task>
  • GET
  • ALL

outputFormat

For every command that produces output (GET and ALL), print the result on a new line. If there is no applicable task, output an empty line.

## sample
5
ADD task1 5
GET
ADD task2 10
GET
ALL
task1

task2 task2 task1

</p>