#C3106. Stack Operations on a Constrained Capacity Stack
Stack Operations on a Constrained Capacity Stack
Stack Operations on a Constrained Capacity Stack
You are given a stack with a maximum capacity \(N\) and you need to perform \(M\) operations on it. The operations are provided as a list of strings where each string can be one of the following commands:
- PUSH x: Pushes the integer \(x\) onto the stack if the stack size is less than \(N\).
- POP: Removes the top element from the stack if the stack is not empty.
- INCREMENT k m: Increments each of the bottom \(k\) elements of the stack by the integer \(m\). If \(k\) is greater than the current size of the stack, then increment all the elements.
After processing all \(M\) operations, output the final state of the stack from top to bottom. If the stack is empty, output "EMPTY".
inputFormat
The first line contains two integers (N) and (M), representing the maximum capacity of the stack and the number of operations, respectively. Each of the following (M) lines contains an operation in one of the following formats:
PUSH x POP INCREMENT k m
where x, k, and m are integers.
outputFormat
Output the final state of the stack, with each element on a new line, starting from the top. If the stack is empty after performing all operations, output a single line with the text "EMPTY".## sample
5 6
PUSH 1
PUSH 2
PUSH 3
INCREMENT 2 5
POP
PUSH 6
6
7
6
</p>