#P2073. 送花

送花

Description

Each flower is beautiful, with a beauty value WW and a price CC.

Xiao Ming starts with an empty bouquet and keeps adding flowers. He has the following operations:

  • 1 W C1\ W\ C: Add a flower with beauty value WW and price CC.
    If there is already a flower in the bouquet with the same price, this flower cannot be added.
  • 22: Remove the most expensive flower currently in the bouquet.
  • 33: Remove the cheapest flower currently in the bouquet.
  • 1-1: Finish adding and removing, and start wrapping the bouquet.

When the bouquet is empty, ignore operations 22 and 33.

Please write a program to compute, at the moment wrapping starts, the sum of the beauty values of all flowers in the bouquet and the total price Xiao Ming needs to pay for the bouquet.

Input Format

Multiple lines, one operation per line, ending with 1-1.

Output Format

One line with two space-separated positive integers: the sum of the beauty values of all flowers in the bouquet at the moment wrapping starts, and the total price Xiao Ming needs to pay.

1 1 1
1 2 5
2
1 3 3
3
1 5 2
-1

8 5

Hint

Let the number of operations be mm.

  • For 20%20\% of the testdata, m100m \le 100, 1W,C1031\le W,C\le 10^3.
  • For all testdata, m105m \le 10^5, 1W,C1061\le W,C\le 10^6.

Translated by ChatGPT 5