Order book 
Simulate a sell-side order book and calculate the cost of a final purchase as fast as possible.
Input
1,000,000 order updates on STDIN, one per line:
+ <price> <size>– add a new sell order- <position>– delete the order at the given position= <size>– buy<size>shares from the top of the order book
After all updates are processed, buy 1,000 shares from the top of the order book.
Output
Print the total cost of the final 1,000-share purchase to STDOUT.
Order Book Rules
Orders are sorted by price ascending (lower is better). Orders at the same price are sorted by arrival time (earlier first). Position 0 is the best (lowest-price) offer.
The = (buy) operation consumes shares starting from position 0. If an order is fully consumed, it is removed from the book.
Example
| Input | Order book state |
|---|---|
+ 1137 100 |
(1137,100) |
+ 1130 10 |
(1130,10), (1137,100) |
+ 1130 50 |
(1130,10), (1130,50), (1137,100) |
- 0 |
(1130,50), (1137,100) |
+ 1150 200 |
(1130,50), (1137,100), (1150,200) |
= 200 |
(1150,150) |
Total cost of the last buy: 50 * 1130 + 100 * 1137 + 50 * 1150.
| Date | Author | Language | Status | Score | |
|---|---|---|---|---|---|
| Feb 16, 2024 08:29 | RUSTrust-1.76.0 | Error | |||
| Feb 16, 2024 08:02 | CPPg++9.4.0 | Success | 2,239,621+4.47 RP | ||
| Feb 16, 2024 07:33 | CPPg++9.4.0 | Error | |||
| Feb 16, 2024 07:32 | CPPg++9.4.0 | Error | |||
| Feb 16, 2024 07:31 | CPPg++9.4.0 | Error | |||
| Feb 16, 2024 06:37 | CPPg++9.4.0 | Error | |||
| Feb 16, 2024 06:36 | CPPg++9.4.0 | Error | |||
| Feb 16, 2024 06:16 | CPPg++9.4.0 | Error | |||
| Feb 16, 2024 06:14 | CPPg++9.4.0 | Error | |||
| Feb 16, 2024 05:54 | CPPg++9.4.0 | Error | |||
| Feb 16, 2024 05:53 | CPPg++9.4.0 | Error | |||
| Feb 16, 2024 05:49 | CPPg++9.4.0 | Error | |||
| Feb 16, 2024 05:49 | CPPg++9.4.0 | Success | 45,830+15.81 RP | ||
| Feb 16, 2024 05:47 | CPPg++9.4.0 | Error | |||
| Feb 16, 2024 05:47 | CPPg++9.4.0 | Error | |||
| Feb 16, 2024 05:47 | CPPg++9.4.0 | Success | 53,688 | ||
| Feb 16, 2024 05:45 | CPPg++9.4.0 | Error | |||
| Feb 16, 2024 05:44 | CPPg++9.4.0 | Error | |||
| Feb 16, 2024 03:24 | CPPg++9.4.0 | Error | |||
| Feb 16, 2024 03:17 | CPPg++9.4.0 | Error | |||
| Feb 16, 2024 03:16 | CPPg++9.4.0 | Success | 60,784 | ||
| Feb 16, 2024 03:06 | CPPg++9.4.0 | Error | |||
| Feb 16, 2024 03:06 | CPPg++9.4.0 | Error | |||
| Feb 16, 2024 03:05 | CPPg++9.4.0 | Success | 49,409+23.94 RP | ||
| Feb 16, 2024 03:01 | CPPg++9.4.0 | Error | |||
| Feb 16, 2024 03:00 | CPPg++9.4.0 | Error | |||
| Feb 15, 2024 20:25 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 20:24 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 20:11 | CPPg++9.4.0 | Success | 1,111,914+0.12 RP | ||
| Feb 15, 2024 20:03 | CPPg++9.4.0 | Success | 1,127,357+0.98 RP | ||
| Feb 15, 2024 20:01 | CPPg++9.4.0 | Success | 1,867,866 | ||
| Feb 15, 2024 19:57 | CPPg++9.4.0 | Error | |||
| Feb 15, 2024 19:54 | CPPg++9.4.0 | Error | |||
| Feb 15, 2024 19:49 | CPPg++9.4.0 | Error | |||
| Feb 15, 2024 19:48 | CPPg++9.4.0 | Error | |||
| Feb 15, 2024 19:41 | CPPg++9.4.0 | Success | 1,267,096+0.05 RP | ||
| Feb 15, 2024 19:40 | CPPg++9.4.0 | Error | |||
| Feb 15, 2024 19:36 | CPPg++9.4.0 | Error | |||
| Feb 15, 2024 19:32 | CPPg++9.4.0 | Error | |||
| Feb 15, 2024 19:26 | CPPg++9.4.0 | Success | 1,274,388+2.60 RP | ||
| Feb 15, 2024 19:23 | CPPg++9.4.0 | Error | |||
| Feb 15, 2024 19:14 | CPPg++9.4.0 | Error | |||
| Feb 15, 2024 19:12 | CPPg++9.4.0 | Error | |||
| Feb 15, 2024 19:09 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 19:08 | CPPg++9.4.0 | Error | |||
| Feb 15, 2024 19:08 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 19:02 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 19:00 | CPPg++9.4.0 | Error | |||
| Feb 15, 2024 19:00 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 18:50 | CPPg++9.4.0 | Error | |||
| Feb 15, 2024 18:49 | CPPg++9.4.0 | Error | |||
| Feb 15, 2024 18:27 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 18:24 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 18:21 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 18:19 | CPPg++9.4.0 | Success | 2,171,102 | ||
| Feb 15, 2024 18:05 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 18:04 | CPPg++9.4.0 | Success | 2,190,250 | ||
| Feb 15, 2024 18:00 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 17:54 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 17:47 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 17:45 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 17:43 | CPPg++9.4.0 | Success | 2,205,069 | ||
| Feb 15, 2024 17:40 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 17:40 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 17:35 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 17:33 | CPPg++9.4.0 | Success | 2,305,313 | ||
| Feb 15, 2024 17:30 | CPPg++9.4.0 | Success | 2,201,189 | ||
| Feb 15, 2024 17:20 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 17:14 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 17:10 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 17:08 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 17:02 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 16:56 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 16:49 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 16:44 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 16:43 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 16:36 | CPPg++9.4.0 | Success | 1,906,746+5.24 RP | ||
| Feb 15, 2024 16:34 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 16:33 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 16:32 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 16:30 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 16:24 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 16:24 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 16:21 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 14:45 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 14:45 | RUSTrust-1.76.0 | Error | |||
| Feb 15, 2024 10:08 | RUSTrust-1.76.0 | Error | |||
| Feb 14, 2024 20:56 | RUSTrust-1.76.0 | Error | |||
| Feb 14, 2024 20:56 | RUSTrust-1.74.0 | Error | |||
| Feb 14, 2024 20:38 | RUSTrust-1.74.0 | Error | |||
| Feb 14, 2024 17:43 | RUSTrust-1.74.0 | Error | |||
| Feb 14, 2024 17:39 | RUSTrust-1.74.0 | Error | |||
| Feb 14, 2024 17:00 | RUSTrust-1.74.0 | Error | |||
| Feb 14, 2024 16:45 | RUSTrust-1.74.0 | Error | |||
| Feb 14, 2024 16:15 | RUSTrust-1.74.0 | Error | |||
| Feb 14, 2024 16:03 | RUSTrust-1.74.0 | Error | |||
| Feb 14, 2024 15:07 | RUSTrust-1.74.0 | Error | |||
| Feb 14, 2024 14:39 | RUSTrust-1.74.0 | Error | |||
| Feb 14, 2024 14:35 | RUSTrust-1.74.0 | Error | |||
| Feb 14, 2024 14:33 | RUSTrust-1.74.0 | Error |