P2073 Sending Flowers

Background

Xiao Ming plans to give Xiao Hong a bouquet of flowers to express his love. He picked out some flowers at the shop and intends to bundle them into a bouquet.

Description

Each flower is beautiful, with a beauty value $W$ and a price $C$. Xiao Ming starts with an empty bouquet and keeps adding flowers. He has the following operations: - $1\ W\ C$: Add a flower with beauty value $W$ and price $C$. If there is already a flower in the bouquet with the same price, this flower cannot be added. - $2$: Remove the most expensive flower currently in the bouquet. - $3$: Remove the cheapest flower currently in the bouquet. - $-1$: Finish adding and removing, and start wrapping the bouquet. When the bouquet is empty, ignore operations $2$ and $3$. 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$.

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.

Explanation/Hint

Let the number of operations be $m$. - For $20\%$ of the testdata, $m \le 100$, $1\le W,C\le 10^3$. - For all testdata, $m \le 10^5$, $1\le W,C\le 10^6$. Translated by ChatGPT 5