#K14091. To-Do List Operations

    ID: 24057 Type: Default 1000ms 256MiB

To-Do List Operations

To-Do List Operations

You are given a series of operations to manage a to-do list with priorities. There are three types of operations:

  1. Add Task: An operation in the format 1 x means adding a new task with a priority of x.
  2. Remove Task: An operation represented by 2 removes the task with the highest priority. In case of a tie (i.e. tasks with the same priority), the most recently added task is removed first.
  3. Query Task: An operation represented by 3 queries the current highest priority task. If no task exists, output No tasks available.

Each operation is processed sequentially. The underlying data structure should efficiently support insertion and removal of tasks using a priority queue mechanism. For instance, using a max-heap with a secondary key for tie-breaking (most recent insertion) ensures that both the addition and removal operations can be performed in ( O(\log n) ) time.

inputFormat

The input is read from standard input (stdin). The first line contains an integer ( T ) representing the number of operations. The following ( T ) lines each contain a string describing an operation. An operation is one of the following:

  • 1 x: Add a task with priority ( x ).
  • 2: Remove the current highest priority task.
  • 3: Query and output the current highest priority task.

outputFormat

Output to standard output (stdout) the result of each query operation (operation type 3) on a new line. For each query, output the highest priority number. If no task exists at the time of a query, output No tasks available.## sample

7
1 4
1 9
1 2
3
2
3
2
9

4

</p>