#K41367. Stack Operation Simulator
Stack Operation Simulator
Stack Operation Simulator
You are given a stack that can hold at most (N) plates. The stack supports three operations:
- PUSH x: Push the plate with value (x) onto the stack if there is available space. If the stack is at capacity, ignore the command.
- POP: Pop the topmost plate from the stack. If the stack is empty, print
EMPTY
. - MAX: Output the maximum value among all plates currently in the stack. If the stack is empty, print
EMPTY
.
The operations are provided in sequence, and you need to process them accordingly. Only the results for the MAX
operations and unsuccessful POP
operations (when the stack is empty) should be output.
Example:
For input
10 7
PUSH 5
PUSH 3
MAX
POP
MAX
POP
MAX
The output will be
5
5
EMPTY
inputFormat
The first line contains two integers (N) and (Q), representing the maximum capacity of the stack and the number of queries respectively. The following (Q) lines each contain one query, which is one of the three operations: PUSH x
, POP
, or MAX
.
outputFormat
For each query of type MAX
, output the current maximum value in the stack. For a POP
operation executed on an empty stack, output EMPTY
. Each output should be printed on a new line.## sample
10 7
PUSH 5
PUSH 3
MAX
POP
MAX
POP
MAX
5
5
EMPTY
</p>