#K92017. Task Manager Operations

    ID: 38104 Type: Default 1000ms 256MiB

Task Manager Operations

Task Manager Operations

You are given a sequence of commands to manage tasks. Each task has a name and an integer priority. The program should support the following operations:

  • ADD name priority: Add a new task with the given name and priority. If the task already exists, update its priority.
  • REMOVE name: Remove the task with the given name. If the task does not exist, do nothing.
  • UPDATE name priority: Update the priority of the specified task. If the task does not exist, do nothing.
  • DISPLAY: Display all tasks sorted by increasing priority. If two tasks have the same priority, sort them by name in lexicographical order.

The sorting condition can be represented in LaTeX as follows:

$$sorted = \{(name, priority): priority \in \mathbb{Z} \text{ and } name \in \Sigma^* \}\text{, where tasks are sorted by } priority \text{ and then by } name. $$

inputFormat

The input contains several lines. Each line is a command. The commands are one of the following:

  • ADD name priority
  • REMOVE name
  • UPDATE name priority
  • DISPLAY

Input is read from standard input (stdin) until EOF.

outputFormat

Whenever a DISPLAY command is encountered, output the list of tasks to standard output (stdout). Each task is printed on a separate line, in the format:

name priority

Tasks must be sorted in ascending order of priority, and for tasks with equal priority, sorted in lexicographical order of the task name.

## sample
ADD task1 3
ADD task2 1
ADD task3 2
DISPLAY
task2 1

task3 2 task1 3

</p>