#P5250. Warehouse Lumber Management
Warehouse Lumber Management
Warehouse Lumber Management
There is a lumber warehouse in Boai City which stores logs of various lengths. The warehouse guarantees that no two logs will have the same length. As the warehouse manager, you need to maintain the inventory as shipments come in and go out.
You will be given no more than 100,000 operations. Each operation is one of the following two types:
- Purchase: In the format
1 Length
. Add a log of length Length (Length ≤ 109) to the warehouse. If a log of the same length already exists, outputAlready Exist
instead and do not insert the new log. - Sale: In the format
2 Length
. Remove a log from the warehouse with length equal to Length. If no log of exactly that length exists, remove the log with the length closest to Length. In case there are multiple logs equally close, remove the log with the smaller length. Output the length of the removed log. If the warehouse is empty, outputEmpty
.
Note: For operations which do not require an output (a successful purchase), nothing is printed.
inputFormat
The first line contains an integer Q (1 ≤ Q ≤ 100,000), the number of operations. Each of the following Q lines contains an operation in one of the formats described above.
outputFormat
For each operation that requires an output, print the result on a new line.
sample
5
1 10
1 20
1 10
2 15
2 20
Already Exist
10
20
</p>