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 | |
|---|---|---|---|---|---|
| Sep 19, 2026 13:55 | CPPg++14.2.0 | Success | 400,077 | ||
| Sep 19, 2026 13:28 | CPPg++14.2.0 | Success | 39,724 | ||
| Sep 17, 2026 14:14 | CPPg++14.2.0 | Success | 6,217 | ||
| Sep 17, 2026 14:08 | CPPg++14.2.0 | Success | 4,717 | ||
| Sep 17, 2026 14:08 | CPPg++14.2.0 | Success | 4,175+2'148.08 RP | ||
| Sep 17, 2026 13:37 | CPPg++14.2.0 | Success | 40,775 | ||
| Sep 17, 2026 13:35 | CPPg++14.2.0 | Success | 46,700 | ||
| Sep 17, 2026 13:22 | CPPg++14.2.0 | Success | 1,504,072 | ||
| Sep 17, 2026 13:04 | CPPg++14.2.0 | Success | 401,051 | ||
| Sep 17, 2026 05:01 | CPPg++13.3.0 | Success | 80,179 | ||
| Sep 17, 2026 05:00 | CPPg++10.5.0 | Success | 79,405+5.10 RP | ||
| Sep 16, 2026 00:20 | CPPg++13.3.0 | Error | |||
| Sep 15, 2026 23:33 | CPPg++14.2.0 | Success | 40,465+0.71 RP | ||
| Sep 15, 2026 23:30 | CPPg++14.2.0 | Success | 501,722 | ||
| Sep 15, 2026 23:29 | CPPg++14.2.0 | Success | 40,581+4.66 RP | ||
| Sep 15, 2026 23:28 | CPPclang++20.1.2 | Success | 43,436 | ||
| Sep 15, 2026 23:27 | CPPg++14.2.0 | Success | 41,363+11.87 RP | ||
| Sep 15, 2026 23:25 | CPPg++14.2.0 | Success | 45,044 | ||
| Sep 15, 2026 23:23 | CPPg++14.2.0 | Success | 46,543 | ||
| Sep 15, 2026 23:22 | CPPg++14.2.0 | Success | 43,498+3.08 RP | ||
| Sep 15, 2026 23:19 | CPPg++14.2.0 | Success | 64,763 | ||
| Sep 15, 2026 23:15 | CPPg++14.2.0 | Success | 46,462 | ||
| Sep 15, 2026 23:11 | CPPg++14.2.0 | Success | 53,689 | ||
| Sep 15, 2026 22:42 | CPPg++13.3.0 | Error | |||
| Sep 15, 2026 22:33 | CPPg++13.3.0 | Error | |||
| Sep 15, 2026 22:27 | CPPg++13.3.0 | Error | |||
| Sep 15, 2026 22:24 | CPPg++13.3.0 | Error | |||
| Sep 15, 2026 22:19 | CPPg++13.3.0 | Error | |||
| Sep 15, 2026 21:54 | CPPg++13.3.0 | Error | |||
| Sep 15, 2026 21:12 | CPPg++13.3.0 | Success | 4,341+1'038.59 RP | ||
| Sep 15, 2026 21:11 | CPPg++13.3.0 | Error | |||
| Sep 15, 2026 20:56 | CPPg++13.3.0 | Error | |||
| Sep 15, 2026 20:45 | CPPg++13.3.0 | Error | +113.06 RP | ||
| Sep 15, 2026 20:43 | CPPg++13.3.0 | Error | |||
| Sep 15, 2026 20:42 | CPPg++13.3.0 | Error | |||
| Sep 15, 2026 20:40 | CPPg++13.3.0 | Error | +340.55 RP | ||
| Sep 15, 2026 19:18 | CPPg++13.3.0 | Error | +7.48 RP | ||
| Sep 15, 2026 19:14 | CPPg++13.3.0 | Error | |||
| Sep 15, 2026 19:13 | CPPg++13.3.0 | Error | +497.09 RP | ||
| Sep 15, 2026 19:10 | CPPg++13.3.0 | Error | |||
| Sep 15, 2026 16:38 | CPPg++13.3.0 | Error | |||
| Sep 15, 2026 02:11 | CPPg++14.2.0 | Error | |||
| Sep 15, 2026 02:05 | CPPg++14.2.0 | Error | |||
| Sep 15, 2026 01:24 | CPPg++14.2.0 | Error | |||
| Sep 15, 2026 00:46 | CPPg++14.2.0 | Error | |||
| Sep 15, 2026 00:22 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 23:25 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 22:50 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 22:30 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 22:22 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 21:23 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 20:52 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 20:12 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 18:54 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 18:21 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 18:12 | CPPg++13.3.0 | Error | |||
| Sep 14, 2026 18:00 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 17:46 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 17:32 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 16:38 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 16:13 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 15:21 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 15:13 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 14:29 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 13:16 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 12:53 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 12:15 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 11:41 | CPPg++14.2.0 | Success | 326,663 | ||
| Sep 14, 2026 11:27 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 10:25 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 10:05 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 09:03 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 08:34 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 08:11 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 07:44 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 06:55 | CPPg++14.2.0 | Error | |||
| Sep 12, 2026 16:34 | CPPg++14.2.0 | Success | 98,401 | ||
| Sep 12, 2026 16:18 | CPPg++14.2.0 | Success | 82,753+8.62 RP | ||
| Sep 12, 2026 16:14 | CPPg++14.2.0 | Error | |||
| Sep 12, 2026 16:11 | CPPg++14.2.0 | Success | 89,106+16.00 RP | ||
| Sep 12, 2026 16:06 | CPPg++14.2.0 | Success | 103,925+9.58 RP | ||
| Sep 12, 2026 15:29 | CPPg++14.2.0 | Error | |||
| Sep 12, 2026 11:16 | CPPg++14.2.0 | Success | 117,191 | ||
| Sep 12, 2026 11:08 | CPPg++14.2.0 | Success | 144,667 | ||
| Sep 12, 2026 10:46 | CPPg++14.2.0 | Error | +51.67 RP | ||
| Sep 11, 2026 13:30 | CPPg++14.2.0 | Success | 44,153 | ||
| Sep 11, 2026 12:47 | CPPg++14.2.0 | Success | 45,055+5.00 RP | ||
| Sep 11, 2026 05:05 | CSHARP10.0.11 | Success | 302,263+5.00 RP | ||
| Sep 10, 2026 18:19 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 17:59 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 17:00 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 16:21 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 16:04 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 13:57 | CPPg++10.5.0 | Error | +50.54 RP | ||
| Sep 10, 2026 09:54 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 03:32 | CPPg++14.2.0 | Success | 44,089+28.72 RP | ||
| Sep 9, 2026 14:00 | CPPg++14.2.0 | Success | 5,589 | ||
| Sep 9, 2026 13:49 | CPPg++14.2.0 | Error | |||
| Sep 9, 2026 13:29 | CPPg++14.2.0 | Error | |||
| Sep 8, 2026 21:29 | CPPg++14.2.0 | Error |