| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 4 초 | 1024 MB | 34 | 15 | 11 | 78.571% |
To make some extra money on the side, you have recently started running your own cryptocurrency exchange, where people can trade their Budget Amplifying Profit Coin (BAPC). It is quickly gaining popularity, however, this has also resulted in government regulators asking some questions... As part of their investigation, they have asked for a list of all transactions that have been made via your exchange. You have never bothered to keep track of this, but luckily, you still have the list of all orders that were made since the start of the exchange.
The exchange operates by keeping a list of outstanding buy and sell orders, each with a price and an amount. Whenever a normal order comes in, it is checked whether the new lowest sell price is less than or equal to the highest buy price. If this is the case, a transaction is made between the sell order with the lowest price and the buy order with the highest price, such that at least one of these orders is completely fulfilled. In case of a tie in price, older orders are fulfilled first. This is repeated until the lowest sell price is strictly larger than the highest buy price.
If instead a Fill-or-Kill (FoK) buy order comes in, there must currently be enough outstanding sell orders with a price of at most the offered price to completely fulfil this order. If there are, the order will be fulfilled in the same way as a normal order. Otherwise, the order is completely cancelled, without any transaction taking place. Note that multiple orders may be used to complete a FoK order, as long as it happens immediately.
FoK sell orders are processed in a similar way, but then there should be sufficient outstanding buy orders with a price of at least the asked price.
As an example, consider the first sample case. The six orders are handled as follows:
Given a list of all orders in the order that they have been made, create a list of all transactions that have been performed by your exchange.
The input consists of:
buy" or "sell", the side of the order.normal" or "fok", the type of the order.The output consists of the number of performed transactions, and then for each transaction, in the order that they have been performed:
sell" order.buy" order.Here, the index of an order is its position in the input, where the first order has index 1ドル$.
6 buy normal 700 10 sell normal 500 20 sell normal 800 58 buy fok 600 30 buy fok 900 60 sell normal 300 42
3 2 1 10 2 5 10 3 5 50
3 buy normal 19 10 buy normal 19 20 sell fok 19 17
2 3 1 10 3 2 7
ICPC > Regionals > Europe > Northwestern European Regional Contest > Benelux Algorithm Programming Contest > BAPC 2024 Preliminaries I번