Score : $300$ points
We have a multiset of integers $S$, which is initially empty.
Given $Q$ queries, process them in order. Each query is of one of the following types.
1 x
: Insert an $x$ into $S$.
2 x c
: Remove an $x$ from $S$ $m$ times, where $m = \mathrm{min}(c,($ the number of $x$'s contained in $S))$.
3
: Print $($ maximum value of $S)-($ minimum value of $S)$. It is guaranteed that $S$ is not empty when this query is given.
3
is given, $S$ is not empty.Input is given from Standard Input in the following format:
$Q$ $\mathrm{query}_1$ $\vdots$ $\mathrm{query}_Q$
$\mathrm{query}_i$, which denotes the $i$-th query, is in one of the following formats:
$1$ $x$
$2$ $x$ $c$
$3$
Print the answers for the queries of type 3
in the given order, separated by newlines.
8 1 3 1 2 3 1 2 1 7 3 2 2 3 3
1 5 4
The multiset $S$ transitions as follows.
4 1 10000 1 1000 2 100 3 1 10
If the given queries do not contain that of type $3$, nothing should be printed.