#K5396. Task Scheduler

    ID: 29647 Type: Default 1000ms 256MiB

Task Scheduler

Task Scheduler

You are given a series of operations to manage a task scheduler. Each task has an integer priority and a description. The scheduler executes tasks in order of descending priority. If two tasks share the same priority, they must be executed in the same order they were added (i.e., first-in, first-out).

The scheduler supports two types of operations:

  • ADD <priority> <task>: Add a task with the specified priority and description. The task description is a string and may include spaces.
  • EXECUTE: Execute all tasks currently in the scheduler. When executed, tasks are output in the required order, each on a new line.

If no tasks have been added when the EXECUTE command is issued, nothing should be output.

Note: All arithmetic or formulae (if any) must be formatted in LaTeX. In this problem no such formula is necessary.

inputFormat

The first line contains an integer Q representing the number of operations. Each of the following Q lines contains an operation in one of the two formats:

  • ADD <priority> <task>
  • EXECUTE

Each ADD operation will add a task with the specified priority and description. The EXECUTE operation instructs the program to output all tasks according to the rules specified.

outputFormat

When the EXECUTE operation is encountered, output the descriptions of all tasks in order, each on a separate line. If no tasks were added, output nothing.

## sample
4
ADD 1 Write report
ADD 3 Implement feature
ADD 2 Fix bugs
ADD 3 Code review
EXECUTE
Implement feature

Code review Fix bugs Write report

</p>