#P2073. Flower Bouquet Operations
Flower Bouquet Operations
Flower Bouquet Operations
Ming has a series of beautiful flowers. Each flower has a beauty value \(W\) and a price \(C\). At the beginning, his bouquet is empty. He performs a sequence of operations, and the operations are as follows:
- \(1\; W\; C\): Add a flower with beauty value \(W\) and price \(C\) to the bouquet. If there is already a flower in the bouquet with the same price \(C\), this flower will not be added.
- \(2\): Remove the most expensive flower (the one with the maximum \(C\)) from the bouquet.
- \(3\): Remove the cheapest flower (the one with the minimum \(C\)) from the bouquet.
- \(-1\): End the operations and start packing the bouquet.
Note: When the bouquet is empty, operations \(2\) and \(3\) are ignored.
Your task is to simulate these operations and, once the \(-1\) operation is encountered, output the total beauty value (i.e. the sum of \(W\) of all the remaining flowers) and the total price (i.e. the sum of \(C\) of all the remaining flowers) in the bouquet.
inputFormat
The input is a sequence of operations, one operation per line. Each operation is one of the following forms:
1 W C
– add a flower with beauty value \(W\) and price \(C\).2
– remove the most expensive flower.3
– remove the cheapest flower.-1
– terminate the input and start packaging.
It is guaranteed that all numeric values are integers. Operations \(2\) and \(3\) should be ignored if the bouquet is empty.
outputFormat
Output two integers separated by a space: the total beauty value (the sum of all \(W\) values) and the total price (the sum of all \(C\) values) of the remaining flowers in the bouquet.
sample
1 10 5
1 20 6
-1
30 11