14941 - Vending Mid   

Description

SpongeBob is hungry while waiting the bus. As a vending machine, now you want to sell the median-price kandy to SpongBob.

The Median Price is defined as the price of the element at index [(size - 1) / 2] in the sorted list of kandy prices.

If you have the following kandy prices: [10, 25, 40, 50], whose size is 4 and index is 0-based, then you should sell the kandy at index (size - 1) / 2 =  1.

If you have the following kandy prices: [10, 25, 40, 50, 100], whose size is 5 and index is 0-based, then you should sell the kandy at index (size - 1) / 2 =  2.

This is a partial judge probelm. Please implement these two functions:

  1. store <price>: Add an item with a given price (integer) into the vending machine.

  2. sell: Sell the Median-Price kandy. If the machine is empty, ignore this command.

Constraints

  • number of operations <= 2 * 105.
  • price <= 109.

 

Please note that you CANNOT use STL to solve this problem.

Input

A sequence of commands (store <num> or sell).

Output

A single line containing two integers separated by a space:

  1. The total number of items sold.

  2. The total revenue with '\n'.

Sample Input  Download

Sample Output  Download

Partial Judge Code

14941.cpp

Partial Judge Header

14941.h

Tags




Discuss