#C2663. Task Manager with Priority Operations
Task Manager with Priority Operations
Task Manager with Priority Operations
You are given a task manager that supports three operations: ADD
, REMOVE
, and FETCH
. Each task has a unique description (a string) and an associated integer priority. The operations are defined as follows:
- ADD <description> <priority>: Add a new task with the given description and priority. If a task with the same description already exists, it should be updated with the new priority.
- REMOVE <description>: Remove the task with the given description if it exists.
- FETCH: Fetch and output the description of the task with the highest priority. In the event of a tie (multiple tasks have the same highest priority), output the one with the lexicographically smallest description. If there are no tasks, output
NONE
.
The operations are provided from standard input, and the results for each FETCH
operation should be printed on a new line to standard output. Formally, if the highest priority is denoted by \(p\) and tasks may be compared by:
Implement the task manager to process a series of operations efficiently.
inputFormat
The first line contains a single integer n (\(1 \leq n \leq 10^5\)), representing the number of operations. Each of the following n lines contains one operation in one of the following formats:
ADD <description> <priority>
REMOVE <description>
FETCH
Operations are read from standard input.
outputFormat
For each FETCH
operation, output the result on a new line. If there is no task available, output NONE
.
Results should be written to standard output.
## sample7
ADD task1 10
ADD task2 20
ADD task3 15
FETCH
REMOVE task2
FETCH
REMOVE task1
task2
task3
</p>