#K59512. List Operation Processor
List Operation Processor
List Operation Processor
You are given a list that supports three types of operations:
- ADD x: Append the integer \(x\) to the end of the list.
- REMOVE x: Remove the first occurrence of the integer \(x\) from the list if it exists.
- MAX: Print the maximum element in the list. If the list is empty, print
EMPTY
.
You will be given \(n\) operations. Your task is to process these operations sequentially and output the result of each MAX
operation.
Example:
Input: 8 ADD 3 ADD 1 MAX REMOVE 3 MAX ADD 2 REMOVE 4 MAX</p>Output: 3 1 2
inputFormat
The first line contains an integer \(n\) representing the number of operations. Each of the following \(n\) lines contains a string representing one of the three operations:
ADD x
where \(x\) is an integer.REMOVE x
where \(x\) is an integer.MAX
outputFormat
For each MAX
operation, output the maximum element of the list on a new line. If the list is empty during a MAX
operation, output EMPTY
instead.
8
ADD 3
ADD 1
MAX
REMOVE 3
MAX
ADD 2
REMOVE 4
MAX
3
1
2
</p>