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 | |
|---|---|---|---|---|---|
| Apr 17, 2024 19:29 | CPPclang++10.0.0 | Error | |||
| Apr 17, 2024 19:23 | CPPclang++10.0.0 | Error | |||
| Apr 17, 2024 19:21 | CPPclang++10.0.0 | Error | |||
| Apr 17, 2024 19:20 | CPPclang++10.0.0 | Success | 77,391 | ||
| Apr 17, 2024 19:18 | CPPclang++10.0.0 | Error | |||
| Apr 17, 2024 19:18 | CPPclang++10.0.0 | Error | |||
| Apr 17, 2024 19:17 | CPPclang++10.0.0 | Error | |||
| Apr 17, 2024 19:15 | CPPclang++10.0.0 | Success | 77,390 | ||
| Apr 17, 2024 19:14 | CPPclang++10.0.0 | Error | |||
| Apr 17, 2024 19:12 | CPPclang++10.0.0 | Success | 77,509 | ||
| Apr 17, 2024 19:10 | CPPclang++10.0.0 | Success | 76,462 | ||
| Apr 17, 2024 15:14 | CPPg++9.4.0 | Error | |||
| Apr 15, 2024 01:55 | RUSTrust-1.77.2 | Error | |||
| Apr 14, 2024 19:08 | RUSTrust-1.77.2 | Success | 1,835,046 | ||
| Apr 14, 2024 10:17 | CPPclang++10.0.0 | Success | 79,585 | ||
| Apr 14, 2024 06:56 | RUSTrust-1.77.2 | Success | 132,701+4.23 RP | ||
| Apr 14, 2024 05:47 | RUSTrust-1.77.2 | Error | |||
| Apr 14, 2024 04:36 | CPPclang++10.0.0 | Error | |||
| Apr 14, 2024 04:30 | CPPclang++10.0.0 | Error | |||
| Apr 14, 2024 04:27 | CPPclang++10.0.0 | Error | |||
| Apr 14, 2024 04:25 | CPPclang++10.0.0 | Error | |||
| Apr 14, 2024 04:11 | CPPclang++10.0.0 | Error | |||
| Apr 13, 2024 16:22 | CPPclang++10.0.0 | Error | |||
| Apr 13, 2024 15:55 | CPPclang++10.0.0 | Error | |||
| Apr 13, 2024 15:55 | CPPclang++10.0.0 | Error | |||
| Apr 13, 2024 15:53 | CPPclang++10.0.0 | Error | |||
| Apr 13, 2024 15:52 | CPPclang++10.0.0 | Success | 91,226 | ||
| Apr 13, 2024 15:50 | CPPclang++10.0.0 | Success | 88,606 | ||
| Apr 13, 2024 15:48 | CPPclang++10.0.0 | Success | 88,028 | ||
| Apr 13, 2024 15:46 | CPPclang++10.0.0 | Success | 87,910 | ||
| Apr 13, 2024 15:45 | CPPclang++10.0.0 | Error | |||
| Apr 13, 2024 15:41 | CPPclang++10.0.0 | Error | |||
| Apr 13, 2024 15:39 | CPPclang++10.0.0 | Error | |||
| Apr 13, 2024 15:38 | CPPclang++10.0.0 | Error | |||
| Apr 13, 2024 15:37 | CPPclang++10.0.0 | Error | |||
| Apr 13, 2024 15:36 | CPPclang++10.0.0 | Error | |||
| Apr 13, 2024 15:35 | CPPclang++10.0.0 | Error | |||
| Apr 13, 2024 15:33 | CPPclang++10.0.0 | Error | |||
| Apr 13, 2024 15:32 | CPPclang++10.0.0 | Success | 78,805 | ||
| Apr 13, 2024 15:30 | CPPclang++10.0.0 | Error | |||
| Apr 13, 2024 15:11 | CPPclang++10.0.0 | Error | |||
| Apr 13, 2024 15:10 | CPPclang++10.0.0 | Error | |||
| Apr 13, 2024 13:51 | CPPclang++10.0.0 | Success | 77,390 | ||
| Apr 13, 2024 13:43 | CPPclang++10.0.0 | Success | 77,395 | ||
| Apr 13, 2024 13:42 | CPPclang++10.0.0 | Success | 79,090 | ||
| Apr 13, 2024 13:40 | CPPclang++10.0.0 | Success | 78,831 | ||
| Apr 13, 2024 13:28 | CPPclang++10.0.0 | Success | 77,431 | ||
| Apr 13, 2024 13:27 | CPPclang++10.0.0 | Success | 76,733 | ||
| Apr 13, 2024 13:27 | CPPg++9.4.0 | Success | 91,534 | ||
| Apr 13, 2024 13:14 | CPPg++9.4.0 | Error | |||
| Apr 13, 2024 13:12 | CPPg++9.4.0 | Success | 468,571 | ||
| Apr 13, 2024 05:16 | CPPg++9.4.0 | Error | |||
| Apr 13, 2024 05:15 | CPPg++9.4.0 | Error | |||
| Apr 13, 2024 05:14 | CPPg++9.4.0 | Error | |||
| Apr 13, 2024 03:28 | CPPg++9.4.0 | Success | 35,369+17.41 RP | ||
| Apr 13, 2024 03:27 | CPPg++9.4.0 | Error | |||
| Apr 13, 2024 00:41 | RUSTrust-1.77.2 | Error | |||
| Apr 12, 2024 23:46 | RUSTrust-1.77.2 | Success | 140,586+12.22 RP | ||
| Apr 12, 2024 23:32 | RUSTrust-1.77.2 | Success | 2,701,797 | ||
| Apr 12, 2024 22:37 | RUSTrust-1.77.2 | Error | |||
| Apr 12, 2024 22:08 | RUSTrust-1.77.2 | Success | 169,747+1.49 RP | ||
| Apr 12, 2024 22:07 | RUSTrust-1.77.2 | Success | 177,817 | ||
| Apr 12, 2024 21:54 | RUSTrust-1.77.2 | Success | 174,162+20.23 RP | ||
| Apr 10, 2024 01:32 | RUSTrust-1.77.1 | Success | 112,704 | ||
| Apr 9, 2024 13:11 | CPPg++9.4.0 | Success | 2,397,856+4.17 RP | ||
| Apr 9, 2024 08:37 | RUSTrust-1.77.1 | Success | 111,241 | ||
| Apr 9, 2024 08:03 | RUSTrust-1.77.1 | Success | 112,385 | ||
| Apr 9, 2024 07:59 | RUSTrust-1.77.1 | Success | 112,112 | ||
| Apr 9, 2024 06:03 | RUSTrust-1.77.1 | Success | 128,676 | ||
| Apr 9, 2024 05:26 | RUSTrust-1.77.1 | Success | 112,846 | ||
| Apr 9, 2024 05:17 | RUSTrust-1.77.1 | Error | |||
| Apr 9, 2024 05:16 | RUSTrust-1.77.1 | Success | 107,936 | ||
| Apr 7, 2024 11:07 | CPPclang++10.0.0 | Error | |||
| Apr 7, 2024 08:59 | CPPclang++10.0.0 | Success | 91,623 | ||
| Apr 7, 2024 08:55 | RUSTrust-1.77.1 | Error | |||
| Apr 6, 2024 14:34 | CPPg++9.4.0 | Success | 102,916 | ||
| Apr 6, 2024 14:16 | CPPg++9.4.0 | Success | 102,409 | ||
| Apr 6, 2024 08:04 | CPPg++9.4.0 | Error | |||
| Apr 6, 2024 07:44 | CPPg++9.4.0 | Error | |||
| Apr 6, 2024 07:43 | CPPg++9.4.0 | Error | |||
| Apr 6, 2024 07:42 | CPPg++9.4.0 | Error | |||
| Apr 6, 2024 07:41 | CPPg++9.4.0 | Error | |||
| Apr 6, 2024 07:38 | CPPg++9.4.0 | Error | |||
| Apr 6, 2024 07:36 | CPPg++9.4.0 | Error | |||
| Apr 6, 2024 07:35 | CPPg++9.4.0 | Error | |||
| Apr 6, 2024 07:33 | CPPg++9.4.0 | Error | |||
| Apr 6, 2024 07:28 | CPPg++9.4.0 | Error | |||
| Apr 6, 2024 07:25 | CPPg++9.4.0 | Error | |||
| Apr 6, 2024 07:25 | CPPg++9.4.0 | Error | |||
| Apr 6, 2024 07:23 | CPPg++9.4.0 | Error | |||
| Apr 6, 2024 07:20 | CPPg++9.4.0 | Error | |||
| Apr 6, 2024 07:18 | CPPg++9.4.0 | Error | |||
| Apr 6, 2024 07:17 | CPPg++9.4.0 | Error | |||
| Apr 6, 2024 07:16 | CPPg++9.4.0 | Error | |||
| Apr 6, 2024 07:14 | CPPg++9.4.0 | Error | |||
| Mar 31, 2024 14:09 | CPPclang++10.0.0 | Success | 77,395 | ||
| Mar 31, 2024 14:07 | CPPclang++10.0.0 | Success | 77,498 | ||
| Mar 31, 2024 14:06 | CPPclang++10.0.0 | Success | 77,153 | ||
| Mar 31, 2024 14:05 | CPPclang++10.0.0 | Success | 76,940 | ||
| Mar 31, 2024 14:00 | CPPclang++10.0.0 | Error |