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 14, 2024 14:33 | RUSTrust-1.74.0 | Error | |||
| Feb 14, 2024 01:23 | RUSTrust-1.76.0 | Success | 111,154 | ||
| Feb 14, 2024 01:22 | RUSTrust-1.76.0 | Error | |||
| Feb 14, 2024 01:21 | RUSTrust-1.76.0 | Success | 112,279 | ||
| Feb 14, 2024 01:19 | RUSTrust-1.76.0 | Success | 110,622+0.25 RP | ||
| Feb 14, 2024 01:16 | RUSTrust-1.76.0 | Success | 114,788 | ||
| Feb 14, 2024 01:09 | RUSTrust-1.76.0 | Success | 112,690 | ||
| Feb 14, 2024 01:09 | RUSTrust-1.76.0 | Success | 112,697 | ||
| Feb 14, 2024 01:09 | RUSTrust-1.76.0 | Success | 112,672 | ||
| Feb 14, 2024 01:08 | RUSTrust-1.76.0 | Success | 379,183 | ||
| Feb 14, 2024 01:01 | RUSTrust-1.76.0 | Success | 111,567 | ||
| Feb 14, 2024 00:20 | RUSTrust-1.76.0 | Success | 114,397 | ||
| Feb 13, 2024 23:51 | RUSTrust-1.76.0 | Success | 271,357 | ||
| Feb 13, 2024 23:46 | RUSTrust-1.76.0 | Success | 112,131 | ||
| Feb 13, 2024 23:45 | RUSTrust-1.76.0 | Success | 112,554 | ||
| Feb 13, 2024 23:44 | RUSTrust-1.76.0 | Success | 114,333 | ||
| Feb 13, 2024 23:38 | RUSTrust-1.76.0 | Success | 111,935 | ||
| Feb 13, 2024 23:33 | RUSTrust-1.76.0 | Success | 112,588 | ||
| Feb 13, 2024 23:31 | RUSTrust-1.76.0 | Success | 110,932+0.68 RP | ||
| Feb 13, 2024 23:30 | RUSTrust-1.76.0 | Success | 114,905 | ||
| Feb 13, 2024 23:29 | RUSTrust-1.76.0 | Error | |||
| Feb 13, 2024 23:26 | RUSTrust-1.76.0 | Error | |||
| Feb 13, 2024 23:24 | RUSTrust-1.76.0 | Error | |||
| Feb 13, 2024 23:16 | RUSTrust-1.76.0 | Success | 111,780+0.64 RP | ||
| Feb 13, 2024 23:15 | RUSTrust-1.76.0 | Success | 112,580+4.71 RP | ||
| Feb 13, 2024 23:14 | RUSTrust-1.76.0 | Error | |||
| Feb 13, 2024 23:11 | RUSTrust-1.76.0 | Error | |||
| Feb 13, 2024 23:05 | RUSTrust-1.76.0 | Success | 120,870 | ||
| Feb 13, 2024 23:01 | RUSTrust-1.76.0 | Success | 128,010 | ||
| Feb 13, 2024 23:00 | RUSTrust-1.76.0 | Success | 119,980 | ||
| Feb 13, 2024 22:59 | RUSTrust-1.75.0 | Error | |||
| Feb 13, 2024 22:09 | RUSTrust-1.75.0 | Success | 120,512 | ||
| Feb 13, 2024 22:00 | RUSTrust-1.75.0 | Success | 118,883+0.32 RP | ||
| Feb 13, 2024 21:58 | RUSTrust-1.75.0 | Success | 121,476 | ||
| Feb 13, 2024 20:10 | RUSTrust-1.74.0 | Error | |||
| Feb 13, 2024 20:10 | RUSTrust-1.74.0 | Error | |||
| Feb 13, 2024 20:08 | RUSTrust-1.74.0 | Error | |||
| Feb 13, 2024 20:08 | RUSTrust-1.74.0 | Error | |||
| Feb 13, 2024 20:07 | RUSTrust-1.74.0 | Error | |||
| Feb 13, 2024 19:49 | RUSTrust-1.74.0 | Error | |||
| Feb 13, 2024 19:47 | RUSTrust-1.74.0 | Error | |||
| Feb 13, 2024 09:57 | RUSTrust-1.74.0 | Error | |||
| Feb 13, 2024 09:52 | RUSTrust-1.74.0 | Error | |||
| Feb 13, 2024 09:51 | RUSTrust-1.74.0 | Error | |||
| Feb 13, 2024 09:48 | CPPg++9.4.0 | Error | |||
| Feb 13, 2024 09:47 | CPPg++9.4.0 | Error | |||
| Feb 13, 2024 09:45 | CPPg++9.4.0 | Error | |||
| Feb 13, 2024 09:44 | CPPg++9.4.0 | Error | |||
| Feb 13, 2024 09:42 | CPPg++9.4.0 | Error | |||
| Feb 13, 2024 09:39 | CPPg++9.4.0 | Error | |||
| Feb 13, 2024 09:37 | CPPg++9.4.0 | Error | |||
| Feb 12, 2024 20:44 | RUSTrust-1.74.0 | Error | |||
| Feb 12, 2024 20:43 | RUSTrust-1.74.0 | Error | |||
| Feb 12, 2024 20:33 | RUSTrust-1.74.0 | Error | |||
| Feb 12, 2024 20:33 | RUSTrust-1.74.0 | Error | |||
| Feb 12, 2024 20:31 | RUSTrust-1.74.0 | Error | |||
| Feb 12, 2024 20:30 | RUSTrust-1.74.0 | Error | |||
| Feb 12, 2024 20:27 | RUSTrust-1.74.0 | Success | 61,922+33.02 RP | ||
| Feb 12, 2024 20:26 | RUSTrust-1.74.0 | Error | |||
| Feb 12, 2024 20:25 | RUSTrust-1.74.0 | Error | |||
| Feb 12, 2024 20:21 | RUSTrust-1.74.0 | Error | |||
| Feb 12, 2024 20:20 | RUSTrust-1.74.0 | Error | |||
| Feb 12, 2024 20:18 | RUSTrust-1.74.0 | Error | |||
| Feb 12, 2024 16:52 | GOgo1.21.7 | Success | 275,780 | ||
| Feb 12, 2024 16:49 | GOgo1.21.7 | Success | 268,049 | ||
| Feb 12, 2024 16:41 | GOgo1.21.7 | Success | 272,918 | ||
| Feb 12, 2024 16:40 | GOgo1.21.7 | Success | 274,171 | ||
| Feb 12, 2024 16:36 | GOgo1.21.7 | Success | 275,455 | ||
| Feb 12, 2024 16:34 | CPPg++9.4.0 | Error | |||
| Feb 12, 2024 16:33 | CPPg++9.4.0 | Error | |||
| Feb 12, 2024 16:32 | CPPg++9.4.0 | Success | 38,323 | ||
| Feb 12, 2024 16:31 | CPPg++9.4.0 | Error | |||
| Feb 12, 2024 16:29 | GOgo1.21.7 | Error | |||
| Feb 12, 2024 16:29 | CPPg++9.4.0 | Error | |||
| Feb 12, 2024 16:28 | CPPg++9.4.0 | Success | 37,690+14.96 RP | ||
| Feb 12, 2024 16:28 | CPPg++9.4.0 | Error | |||
| Feb 12, 2024 16:27 | CPPg++9.4.0 | Error | |||
| Feb 12, 2024 16:26 | CPPg++9.4.0 | Success | 40,125 | ||
| Feb 12, 2024 16:24 | CPPg++9.4.0 | Error | |||
| Feb 12, 2024 16:19 | CPPg++9.4.0 | Error | |||
| Feb 12, 2024 16:19 | CPPclang++10.0.0 | Success | 46,827 | ||
| Feb 12, 2024 16:18 | CPPclang++10.0.0 | Error | |||
| Feb 12, 2024 12:58 | RUSTrust-1.76.0 | Error | |||
| Feb 12, 2024 12:22 | RUSTrust-1.76.0 | Error | |||
| Feb 12, 2024 12:21 | CPPg++9.4.0 | Error | |||
| Feb 12, 2024 12:20 | RUSTrust-1.76.0 | Error | |||
| Feb 12, 2024 12:19 | CPPg++9.4.0 | Error | |||
| Feb 12, 2024 12:18 | CPPg++9.4.0 | Error | |||
| Feb 12, 2024 12:16 | CPPg++9.4.0 | Error | |||
| Feb 12, 2024 12:01 | RUSTrust-1.76.0 | Error | |||
| Feb 12, 2024 11:15 | RUSTrust-1.76.0 | Error | |||
| Feb 12, 2024 11:08 | RUSTrust-1.76.0 | Error | |||
| Feb 12, 2024 11:04 | RUSTrust-1.76.0 | Error | |||
| Feb 12, 2024 11:00 | RUSTrust-1.76.0 | Error | |||
| Feb 12, 2024 03:37 | GOgo1.21.7 | Error | |||
| Feb 12, 2024 03:36 | GOgo1.21.7 | Error | |||
| Feb 12, 2024 03:29 | GOgo1.21.7 | Error | |||
| Feb 11, 2024 23:41 | GOgo1.21.7 | Success | 273,416 | ||
| Feb 11, 2024 23:29 | GOgo1.19.3 | Success | 593,798 | ||
| Feb 11, 2024 23:28 | GOgo1.19.3 | Success | 630,312 |