#C14213. Task Scheduler
Task Scheduler
Task Scheduler
You are given a task scheduler that supports three commands: adding a task, executing the highest priority task, and peeking at the highest priority task without removing it. Each task is defined by a timestamp and a priority. Tasks with a higher priority value are executed first, and if two tasks have the same priority, the one that was added earlier is executed first. In case there are no tasks available when an execute or peek command is issued, output ( -1 ). The commands are provided via standard input and the results (for exec and peek commands) should be printed to the standard output, each result on a new line.
The operations to be performed are provided in the following format:
- The first line contains an integer (Q), the number of operations.
- Each of the following (Q) lines contains one of the following commands:
• add timestamp priority: Add a task with the given timestamp and priority.
• exec: Execute the highest priority task and print its timestamp.
• peek: Print the timestamp of the highest priority task without removing it.
If there is no task to execute or peek, output ( -1 ).
inputFormat
The input is read from standard input (stdin) and has the following format:
( Q ) command 1 command 2 ... command Q
Where each command can be:
- add timestamp priority: Add a task with the specified timestamp and priority.
- exec: Execute and remove the highest priority task, outputting its timestamp.
- peek: Output the timestamp of the highest priority task without removing it.
Note: For commands that require an output (exec and peek), print the result on a new line. If no valid task exists, output ( -1 ).
outputFormat
For every exec or peek command, print the resulting timestamp on a new line to standard output (stdout). If there is no task available, print ( -1 ).## sample
10
add 1 2
add 2 3
add 3 3
exec
peek
add 4 5
exec
exec
exec
exec
2
3
4
3
1
-1
</p>