#P1165. Container Warehouse Operations

    ID: 13737 Type: Default 1000ms 256MiB

Container Warehouse Operations

Container Warehouse Operations

M Shipping Company needs to analyze the flow of containers in and out of its warehouses. The only record available is a log recording container operations. There are three types of operations:

  • Operation 1 (Inbound): A container enters the warehouse along with its weight.
  • Operation 2 (Outbound): A container leaves the warehouse. The rule is Last In, First Out (LIFO), meaning the container that was most recently added among those still present is removed.
  • Operation 3 (Query): Report the maximum container weight currently in the warehouse. Mathematically, if the warehouse contains weights \(w_1, w_2, \dots, w_k\), output \(\max\{w_1, w_2, \dots, w_k\}\).

The log is provided in chronological order. It is guaranteed that when a query is executed (operation 3) the warehouse is not empty.

inputFormat

The first line contains an integer \(n\) (the number of operations). Each of the following \(n\) lines represents an operation in one of the following forms:

  • 1 w: Inbound operation. A container with weight w is added to the warehouse.
  • 2: Outbound operation. The most recently stored container is removed from the warehouse.
  • 3: Query operation. Report the maximum weight among containers currently in the warehouse.

outputFormat

For each query operation (operation 3), output the maximum container weight in the warehouse on a separate line.

sample

4
1 10
1 20
3
2
20