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 11, 2024 23:27 | GOgo1.19.3 | Success | 186,936 | ||
| Feb 11, 2024 04:21 | CPPg++9.4.0 | Error | |||
| Feb 10, 2024 20:42 | GOgo1.19.3 | Success | 152,183 | ||
| Feb 10, 2024 20:38 | GOgo1.19.3 | Error | |||
| Feb 10, 2024 20:30 | GOgo1.19.3 | Error | |||
| Feb 10, 2024 20:21 | GOgo1.21.3 | Error | |||
| Feb 10, 2024 20:14 | GOgo1.21.3 | Error | |||
| Feb 10, 2024 16:04 | RUSTrust-1.75.0 | Success | 115,181 | ||
| Feb 10, 2024 16:03 | RUSTrust-1.75.0 | Error | |||
| Feb 10, 2024 16:03 | RUSTrust-1.75.0 | Success | 135,542 | ||
| Feb 10, 2024 15:55 | RUSTrust-1.75.0 | Error | |||
| Feb 10, 2024 15:54 | RUSTrust-1.75.0 | Error | |||
| Feb 10, 2024 15:53 | RUSTrust-1.75.0 | Error | |||
| Feb 10, 2024 15:52 | RUSTrust-1.75.0 | Error | |||
| Feb 10, 2024 15:42 | RUSTrust-1.75.0 | Success | 112,076+0.02 RP | ||
| Feb 10, 2024 15:36 | RUSTrust-1.75.0 | Success | 112,097+26.19 RP | ||
| Feb 10, 2024 15:33 | RUSTrust-1.75.0 | Success | 158,682+0.44 RP | ||
| Feb 10, 2024 15:32 | RUSTrust-1.75.0 | Error | |||
| Feb 10, 2024 14:43 | CPPg++9.4.0 | Success | 2,240,066+4.46 RP | ||
| Feb 10, 2024 14:12 | CPPg++9.4.0 | Success | 57,638 | ||
| Feb 10, 2024 14:12 | CPPg++9.4.0 | Error | |||
| Feb 10, 2024 14:11 | CPPg++9.4.0 | Error | |||
| Feb 10, 2024 14:11 | CPPg++9.4.0 | Error | |||
| Feb 10, 2024 14:10 | CPPg++9.4.0 | Error | |||
| Feb 10, 2024 13:54 | CPPg++9.4.0 | Success | 56,037+91.73 RP | ||
| Feb 10, 2024 13:45 | CPPg++9.4.0 | Error | |||
| Feb 10, 2024 13:11 | CPPg++9.4.0 | Error | |||
| Feb 10, 2024 12:43 | CPPg++9.4.0 | Error | |||
| Feb 10, 2024 12:42 | CPPg++9.4.0 | Error | |||
| Feb 10, 2024 12:41 | CPPg++9.4.0 | Error | |||
| Feb 10, 2024 07:06 | CPPg++9.4.0 | Success | 2,249,809 | ||
| Feb 10, 2024 07:02 | CPPg++9.4.0 | Success | 2,413,163 | ||
| Feb 10, 2024 06:41 | CPPg++9.4.0 | Success | 2,240,490+4.46 RP | ||
| Feb 10, 2024 06:34 | CPPg++9.4.0 | Error | |||
| Feb 10, 2024 06:33 | CPPg++9.4.0 | Error | |||
| Feb 10, 2024 05:08 | CPPclang++10.0.0 | Success | 189,325 | ||
| Feb 10, 2024 04:34 | CPPg++9.4.0 | Success | 115,312+32.22 RP | ||
| Feb 10, 2024 04:12 | CPPg++9.4.0 | Error | |||
| Feb 10, 2024 02:28 | CPPclang++10.0.0 | Success | 259,378 | ||
| Feb 10, 2024 02:28 | CPPg++9.4.0 | Success | 183,493+0.04 RP | ||
| Feb 9, 2024 22:15 | RUSTrust-1.75.0 | Success | 159,793+2.73 RP | ||
| Feb 7, 2024 23:46 | RUSTrust-1.75.0 | Success | 167,214 | ||
| Feb 7, 2024 23:45 | RUSTrust-1.75.0 | Success | 169,082 | ||
| Feb 7, 2024 01:52 | RUSTrust-1.75.0 | Success | 678,626 | ||
| Feb 7, 2024 01:44 | RUSTrust-1.75.0 | Success | 648,837 | ||
| Feb 7, 2024 01:22 | RUSTrust-1.75.0 | Error | |||
| Feb 7, 2024 01:12 | RUSTrust-1.75.0 | Error | |||
| Feb 6, 2024 19:37 | RUSTrust-1.74.0 | Error | |||
| Feb 6, 2024 19:09 | RUSTrust-1.75.0 | Error | |||
| Feb 6, 2024 18:56 | RUSTrust-1.75.0 | Error | |||
| Feb 6, 2024 18:56 | RUSTrust-1.75.0 | Error | |||
| Feb 6, 2024 18:24 | RUSTrust-1.75.0 | Error | |||
| Feb 6, 2024 18:18 | RUSTrust-1.75.0 | Error | |||
| Feb 6, 2024 17:48 | RUSTrust-1.75.0 | Error | |||
| Feb 6, 2024 17:34 | RUSTrust-1.74.0 | Error | |||
| Feb 6, 2024 17:33 | RUSTrust-1.74.0 | Error | |||
| Feb 6, 2024 16:05 | RUSTrust-1.75.0 | Success | 1,280,306 | ||
| Feb 6, 2024 16:03 | RUSTrust-1.75.0 | Error | |||
| Feb 6, 2024 16:01 | RUSTrust-1.75.0 | Success | 1,252,085 | ||
| Feb 6, 2024 15:26 | RUSTrust-1.75.0 | Success | 272,849 | ||
| Feb 6, 2024 14:36 | RUSTrust-1.74.0 | Error | |||
| Feb 6, 2024 14:28 | RUSTrust-1.74.0 | Error | |||
| Feb 6, 2024 14:21 | RUSTrust-1.74.0 | Error | |||
| Feb 6, 2024 13:46 | RUSTrust-1.74.0 | Error | |||
| Feb 6, 2024 12:51 | RUSTrust-1.74.0 | Success | 2,833,321 | ||
| Feb 6, 2024 11:28 | RUSTrust-1.74.0 | Error | |||
| Feb 6, 2024 10:07 | CPPg++9.4.0 | Error | |||
| Feb 6, 2024 10:06 | CPPg++9.4.0 | Error | |||
| Feb 6, 2024 09:47 | CPPg++9.4.0 | Error | |||
| Feb 6, 2024 09:33 | CPPg++9.4.0 | Success | 183,636+15.75 RP | ||
| Feb 6, 2024 09:23 | CPPclang++10.0.0 | Success | 258,341+17.82 RP | ||
| Feb 6, 2024 09:21 | CPPg++9.4.0 | Error | |||
| Feb 6, 2024 09:20 | CPPg++9.4.0 | Success | 666,729 | ||
| Feb 6, 2024 05:59 | CPPclang++10.0.0 | Error | |||
| Feb 6, 2024 05:45 | CPPclang++10.0.0 | Error | |||
| Feb 6, 2024 05:42 | CPPclang++10.0.0 | Error | |||
| Feb 6, 2024 05:39 | CPPclang++10.0.0 | Error | |||
| Feb 6, 2024 05:38 | CPPclang++10.0.0 | Error | |||
| Feb 6, 2024 05:31 | CPPclang++10.0.0 | Error | |||
| Feb 6, 2024 02:34 | RUSTrust-1.75.0 | Success | 268,896+5.88 RP | ||
| Feb 6, 2024 02:29 | RUSTrust-1.75.0 | Error | |||
| Feb 6, 2024 01:31 | RUSTrust-1.75.0 | Success | 319,441+24.85 RP | ||
| Feb 6, 2024 01:13 | RUSTrust-1.75.0 | Success | 1,548,956+0.52 RP | ||
| Feb 6, 2024 00:46 | CPPg++9.4.0 | Error | |||
| Feb 6, 2024 00:44 | CPPg++9.4.0 | Error | |||
| Feb 6, 2024 00:39 | CPPg++9.4.0 | Error | |||
| Feb 6, 2024 00:38 | CPPg++9.4.0 | Error | |||
| Feb 6, 2024 00:37 | CPPg++9.4.0 | Error | |||
| Feb 6, 2024 00:28 | CPPg++9.4.0 | Error | |||
| Feb 6, 2024 00:12 | CPPclang++10.0.0 | Error | |||
| Feb 5, 2024 23:53 | RUSTrust-1.75.0 | Success | 6,551,014 | ||
| Feb 5, 2024 23:42 | CPPclang++10.0.0 | Error | |||
| Feb 5, 2024 16:56 | RUSTrust-1.74.0 | Error | |||
| Feb 5, 2024 16:39 | RUSTrust-1.75.0 | Success | 6,719,457 | ||
| Feb 5, 2024 16:36 | RUSTrust-1.75.0 | Success | 7,828,003 | ||
| Feb 5, 2024 16:23 | RUSTrust-1.74.0 | Error | |||
| Feb 5, 2024 16:21 | RUSTrust-1.75.0 | Error | |||
| Feb 5, 2024 14:12 | RUSTrust-1.75.0 | Success | 1,685,138+0.02 RP | ||
| Feb 5, 2024 14:11 | RUSTrust-1.75.0 | Success | 1,689,457+5.92 RP | ||
| Feb 5, 2024 00:06 | RUSTrust-1.75.0 | Success | 197,671 |