Richi Pichichi S.A. 

Richi Pichichi S.A. is a company that sells and purchases shares:
receives, in real time, petitions to sell and to purchase of shares,
attached with the price that the customers are prepared to do the
operation. If, at any time, Richi Pichichi S.A. discovers that has a
customer that wants to sell n_(s) shares at a sale price p_(s), and
other customer that wants to purchase n_(p) shares at a purchase price
p_(p) greater or equal than the sale price, then does the operation:
exactly n = min(n_(s), n_(p)) shares change of hands at the price of
n ⋅ (p_(c) + p_(v))/2, rounding towards zero (besides of a minimal,
economic comission, that does not matter). After an operation of
purchase/sale, one of the two orders dissapears from the Richi Pichichi
S.A. database, while the purchase or sale petition of the other one is
decreased in n units.

If it was possible to match various purchasers with sellers, Richi
Pichichi S.A. will always start matching the purchaser that is prepared
to purchase at the greatest price with the seller that accepts to sell
at the least price. In a event of a tie, the order that is most time in
the Richi Pichichi S.A. database will have preference. An order that has
been partially satisfied does not lose age.

You are asked to, given a sequence of purchase and sale orders, indicate
the operations that Richi Pichichi S.A. will do.

Input

Each test data contains a sequence of purchase and sale orders, each one
of them occupying a line. An order is given by a character P (purchase
order) or S (sale order), a number a that identifies the type of action
(from 1 to 1000), the price p and the quantity of shares n, separated by
spaces.

Output

Each time that is possible to do an operation, your program must print
the number of line in what the purchase order was given, the number of
line in what the sale order was given, the type of action, the number of
shares sold and the total cost of the operation. Follow the format of
the instances.

Author: Omer Giménez

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T11:56:35.105Z

© Jutge.org, 2006–2026.
https://jutge.org
