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 | |
|---|---|---|---|---|---|
| Oct 15, 2024 21:35 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 21:34 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 21:31 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 21:30 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 21:26 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 21:25 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 21:24 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 21:14 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 20:40 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 20:38 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 20:37 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 20:26 | CPPclang++18.1.3 | Success | 71,891 | ||
| Oct 15, 2024 20:24 | CPPclang++18.1.3 | Success | 68,005 | ||
| Oct 15, 2024 20:19 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 20:09 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 20:09 | CPPclang++18.1.3 | Success | 67,278+148.39 RP | ||
| Oct 15, 2024 20:08 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 20:07 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 20:06 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 20:00 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 19:56 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 19:54 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 19:52 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 19:50 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 19:50 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 19:49 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 19:47 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 19:46 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 19:44 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 19:43 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 19:42 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 19:39 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 19:37 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 19:32 | CPPclang++18.1.3 | Success | 40,213,452+0.25 RP | ||
| Oct 15, 2024 19:30 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 19:29 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 19:29 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 18:43 | RUSTrust-1.76.0 | Error | |||
| Oct 15, 2024 18:42 | RUSTrust-1.76.0 | Error | |||
| Oct 15, 2024 18:41 | RUSTrust-1.76.0 | Error | |||
| Oct 15, 2024 18:40 | RUSTrust-1.76.0 | Error | |||
| Oct 15, 2024 18:39 | RUSTrust-1.76.0 | Error | |||
| Oct 15, 2024 18:36 | RUSTrust-1.76.0 | Error | |||
| Oct 15, 2024 18:36 | RUSTrust-1.76.0 | Error | |||
| Oct 15, 2024 18:35 | RUSTrust-1.76.0 | Error | |||
| Oct 15, 2024 18:33 | RUSTrust-1.76.0 | Error | |||
| Oct 15, 2024 18:32 | RUSTrust-1.76.0 | Error | |||
| Oct 15, 2024 18:31 | RUSTrust-1.76.0 | Error | |||
| Oct 15, 2024 18:30 | RUSTrust-1.76.0 | Error | |||
| Oct 15, 2024 18:29 | RUSTrust-1.76.0 | Error | |||
| Oct 15, 2024 18:28 | RUSTrust-1.76.0 | Error | |||
| Oct 15, 2024 16:29 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 16:28 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 16:28 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 16:26 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 16:26 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 16:24 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 16:23 | CPPclang++18.1.3 | Error | |||
| Oct 15, 2024 16:23 | CPPclang++18.1.3 | Error | |||
| Oct 13, 2024 22:05 | RUSTrust-1.81.0 | Success | 136,943 | ||
| Oct 4, 2024 08:11 | RUSTrust-1.76.0 | Error | |||
| Sep 12, 2024 12:22 | CPPclang++18.1.3 | Error | |||
| Sep 12, 2024 12:22 | CPPclang++18.1.3 | Error | |||
| Sep 12, 2024 12:20 | CPPclang++18.1.3 | Error | |||
| Sep 12, 2024 12:19 | CPPclang++18.1.3 | Error | |||
| Sep 10, 2024 17:00 | CPPclang++18.1.3 | Error | |||
| Sep 10, 2024 16:58 | CPPclang++18.1.3 | Error | |||
| Sep 10, 2024 16:57 | CPPclang++18.1.3 | Error | |||
| Sep 4, 2024 13:34 | CPPg++13.2.0 | Error | |||
| Sep 4, 2024 13:33 | CPPg++13.2.0 | Error | |||
| Sep 4, 2024 13:27 | CPPg++13.2.0 | Error | |||
| Sep 4, 2024 13:25 | CPPg++13.2.0 | Error | |||
| Sep 4, 2024 13:22 | CPPg++13.2.0 | Error | |||
| Sep 4, 2024 13:19 | CPPg++13.2.0 | Error | |||
| Sep 4, 2024 13:17 | CPPclang++18.1.3 | Error | |||
| Sep 4, 2024 13:16 | CPPg++13.2.0 | Success | 39,014 | ||
| Sep 3, 2024 16:46 | CPPclang++18.1.3 | Success | 2,371,024 | ||
| Sep 3, 2024 16:45 | CPPg++13.2.0 | Success | 2,437,757 | ||
| Aug 31, 2024 22:08 | CPPg++13.2.0 | Error | |||
| Aug 31, 2024 22:08 | CPPclang++18.1.3 | Error | |||
| Aug 31, 2024 22:07 | CPPg++13.2.0 | Error | |||
| Aug 31, 2024 22:06 | CPPg++13.2.0 | Error | |||
| Aug 3, 2024 00:12 | CPPg++9.4.0 | Success | 2,243,969+4.46 RP | ||
| Jul 24, 2024 22:07 | RUSTrust-1.79.0 | Error | |||
| Jul 24, 2024 22:05 | RUSTrust-1.79.0 | Error | |||
| Jul 24, 2024 22:04 | RUSTrust-1.79.0 | Error | |||
| Jul 24, 2024 22:03 | RUSTrust-1.79.0 | Error | |||
| Jul 24, 2024 22:02 | RUSTrust-1.79.0 | Error | |||
| Jul 24, 2024 22:02 | RUSTrust-1.79.0 | Error | |||
| Jul 24, 2024 21:58 | RUSTrust-1.79.0 | Error | |||
| Jul 24, 2024 21:57 | RUSTrust-1.79.0 | Error | |||
| Jul 24, 2024 20:33 | RUSTrust-1.79.0 | Success | 112,553 | ||
| Jul 3, 2024 17:15 | CPPclang++10.0.0 | Error | |||
| Jul 3, 2024 15:44 | CPPclang++10.0.0 | Error | |||
| Jul 3, 2024 15:38 | CPPclang++10.0.0 | Error | |||
| Jul 3, 2024 15:13 | CPPclang++10.0.0 | Success | 77,847 | ||
| Jul 3, 2024 11:35 | GOgo1.22.5 | Success | 1,368,127 | ||
| Jun 24, 2024 16:34 | CPPclang++10.0.0 | Error | |||
| Jun 24, 2024 16:01 | CPPclang++10.0.0 | Error | |||
| Jun 24, 2024 15:28 | CPPclang++10.0.0 | Success | 140,423+2.51 RP |