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 19, 2026 01:08 | CPPg++13.3.0 | Error | |||
| Feb 19, 2026 01:07 | CPPg++13.3.0 | Error | |||
| Feb 19, 2026 01:06 | CPPg++13.3.0 | Error | |||
| Feb 19, 2026 01:03 | CPPg++13.3.0 | Error | |||
| Feb 19, 2026 01:02 | CPPg++13.3.0 | Success | 3,779+56.87 RP | ||
| Feb 19, 2026 00:57 | CPPg++13.3.0 | Error | |||
| Feb 19, 2026 00:53 | CPPg++13.3.0 | Error | |||
| Feb 19, 2026 00:38 | CPPg++13.3.0 | Error | |||
| Feb 19, 2026 00:37 | CPPg++13.3.0 | Error | |||
| Feb 19, 2026 00:36 | CPPg++13.3.0 | Error | |||
| Feb 19, 2026 00:33 | CPPg++13.3.0 | Error | |||
| Feb 19, 2026 00:32 | CPPg++13.3.0 | Error | |||
| Feb 19, 2026 00:29 | CPPg++13.3.0 | Error | |||
| Feb 19, 2026 00:28 | CPPg++13.3.0 | Error | |||
| Feb 19, 2026 00:26 | CPPg++13.3.0 | Success | 3,862+123.24 RP | ||
| Feb 19, 2026 00:15 | CPPg++13.3.0 | Error | |||
| Feb 19, 2026 00:13 | CPPg++13.3.0 | Error | |||
| Feb 19, 2026 00:12 | CPPg++13.3.0 | Error | |||
| Feb 19, 2026 00:06 | CPPg++13.3.0 | Error | |||
| Feb 19, 2026 00:03 | CPPg++13.3.0 | Success | 4,055+104.26 RP | ||
| Feb 19, 2026 00:01 | CPPg++13.3.0 | Error | |||
| Feb 19, 2026 00:00 | CPPg++13.3.0 | Success | 4,259 | ||
| Feb 18, 2026 23:59 | CPPg++13.3.0 | Error | |||
| Feb 18, 2026 23:57 | CPPg++13.3.0 | Success | 4,266 | ||
| Feb 18, 2026 23:52 | CPPg++13.3.0 | Error | |||
| Feb 18, 2026 23:47 | CPPg++13.3.0 | Success | 4,341 | ||
| Feb 18, 2026 23:46 | CPPg++13.3.0 | Success | 4,234+179.86 RP | ||
| Feb 18, 2026 23:43 | CPPg++13.3.0 | Error | |||
| Feb 18, 2026 23:37 | CPPg++13.3.0 | Success | 4,583+72.72 RP | ||
| Feb 18, 2026 23:26 | CPPg++13.3.0 | Error | |||
| Feb 18, 2026 23:25 | CPPg++13.3.0 | Error | |||
| Feb 18, 2026 23:24 | CPPg++13.3.0 | Success | 4,741+378.86 RP | ||
| Feb 18, 2026 23:23 | CPPg++13.3.0 | Error | |||
| Feb 18, 2026 23:14 | CPPg++13.3.0 | Success | 5,779+9.23 RP | ||
| Feb 18, 2026 23:11 | CPPg++13.3.0 | Error | |||
| Feb 18, 2026 23:09 | CPPg++13.3.0 | Error | |||
| Feb 17, 2026 13:30 | CPPg++13.3.0 | Success | 126,241 | ||
| Feb 14, 2026 11:06 | RUSTrust-1.93.1 | Success | 37,003 | ||
| Feb 14, 2026 11:04 | RUSTrust-1.93.1 | Error | |||
| Feb 14, 2026 09:25 | RUSTrust-1.91.1 | Success | 36,622+28.78 RP | ||
| Feb 14, 2026 09:06 | RUSTrust-1.91.1 | Error | |||
| Feb 13, 2026 22:06 | RUSTrust-1.91.1 | Success | 41,593 | ||
| Feb 13, 2026 01:10 | GOgo1.26.0 | Success | 51,495 | ||
| Feb 13, 2026 01:03 | CPPg++13.3.0 | Success | 39,848 | ||
| Feb 13, 2026 01:02 | CSHARP9.0.13 | Success | 52,786+11.63 RP | ||
| Feb 13, 2026 00:59 | CSHARP9.0.13 | Success | 56,364 | ||
| Feb 13, 2026 00:44 | CPPg++13.3.0 | Success | 45,416 | ||
| Feb 13, 2026 00:43 | RUSTrust-1.93.1 | Success | 94,612 | ||
| Feb 13, 2026 00:33 | RUSTrust-1.93.1 | Success | 40,000 | ||
| Feb 13, 2026 00:31 | RUSTrust-1.93.1 | Error | |||
| Feb 13, 2026 00:20 | RUSTrust-1.93.1 | Success | 61,402 | ||
| Feb 13, 2026 00:09 | RUSTrust-1.93.1 | Success | 54,167 | ||
| Feb 12, 2026 23:55 | RUSTrust-1.93.1 | Success | 88,221 | ||
| Feb 12, 2026 23:49 | RUSTrust-1.93.1 | Success | 41,960 | ||
| Feb 12, 2026 23:45 | RUSTrust-1.92.0 | Success | 39,484 | ||
| Feb 12, 2026 23:40 | RUSTrust-1.93.1 | Success | 39,759 | ||
| Feb 12, 2026 23:38 | RUSTrust-1.93.1 | Success | 39,126 | ||
| Feb 12, 2026 23:31 | RUSTrust-1.93.1 | Success | 38,867 | ||
| Feb 12, 2026 23:31 | RUSTrust-1.93.1 | Success | 37,764+1.91 RP | ||
| Feb 12, 2026 23:26 | RUSTrust-1.93.0 | Error | |||
| Feb 12, 2026 23:19 | RUSTrust-1.93.0 | Error | |||
| Feb 12, 2026 23:19 | RUSTrust-1.93.0 | Success | 38,928 | ||
| Feb 12, 2026 23:11 | RUSTrust-1.93.1 | Success | 49,138 | ||
| Feb 12, 2026 23:09 | RUSTrust-1.93.1 | Success | 38,038+4.10 RP | ||
| Feb 12, 2026 23:06 | RUSTrust-1.93.1 | Success | 112,041 | ||
| Feb 12, 2026 23:00 | RUSTrust-1.93.1 | Success | 63,041 | ||
| Feb 12, 2026 22:56 | RUSTrust-1.93.1 | Success | 39,755 | ||
| Feb 12, 2026 22:54 | RUSTrust-1.93.1 | Success | 40,160 | ||
| Feb 12, 2026 22:45 | RUSTrust-1.93.1 | Success | 38,641+17.29 RP | ||
| Feb 12, 2026 22:37 | RUSTrust-1.93.1 | Error | |||
| Feb 12, 2026 22:14 | RUSTrust-1.91.1 | Success | 40,936+22.02 RP | ||
| Feb 12, 2026 22:10 | RUSTrust-1.91.1 | Success | 103,205 | ||
| Feb 12, 2026 21:55 | RUSTrust-1.93.1 | Success | 42,364 | ||
| Feb 12, 2026 21:51 | RUSTrust-1.93.1 | Success | 42,012 | ||
| Feb 12, 2026 21:46 | RUSTrust-1.93.1 | Success | 41,922 | ||
| Feb 12, 2026 21:37 | RUSTrust-1.93.1 | Success | 41,483 | ||
| Feb 12, 2026 21:36 | RUSTrust-1.93.1 | Success | 43,072 | ||
| Feb 12, 2026 21:34 | RUSTrust-1.93.1 | Success | 42,084 | ||
| Feb 12, 2026 21:32 | RUSTrust-1.93.1 | Success | 43,219 | ||
| Feb 12, 2026 21:17 | RUSTrust-1.93.1 | Success | 43,066 | ||
| Feb 12, 2026 21:15 | RUSTrust-1.93.1 | Success | 42,557 | ||
| Feb 12, 2026 21:14 | RUSTrust-1.93.1 | Success | 47,733 | ||
| Feb 12, 2026 21:07 | RUSTrust-1.93.1 | Error | |||
| Feb 12, 2026 21:05 | RUSTrust-1.93.1 | Success | 42,143 | ||
| Feb 12, 2026 21:02 | RUSTrust-1.93.1 | Success | 41,407+5.50 RP | ||
| Feb 12, 2026 20:54 | RUSTrust-1.93.1 | Success | 64,319 | ||
| Feb 12, 2026 20:06 | RUSTrust-1.91.1 | Success | 44,991+59.19 RP | ||
| Feb 12, 2026 07:11 | RUSTrust-1.91.1 | Success | 61,322+69.37 RP | ||
| Feb 11, 2026 18:23 | CPPg++13.3.0 | Error | |||
| Feb 11, 2026 15:20 | RUSTrust-1.93.0 | Success | 42,372+5.86 RP | ||
| Feb 11, 2026 14:57 | RUSTrust-1.93.0 | Success | 45,384 | ||
| Feb 11, 2026 13:17 | RUSTrust-1.93.0 | Success | 43,997 | ||
| Feb 11, 2026 13:15 | RUSTrust-1.93.0 | Success | 45,457 | ||
| Feb 11, 2026 13:10 | RUSTrust-1.93.0 | Success | 43,450+16.43 RP | ||
| Feb 11, 2026 13:09 | RUSTrust-1.93.0 | Success | 65,933 | ||
| Feb 11, 2026 13:06 | RUSTrust-1.93.0 | Success | 66,648 | ||
| Feb 11, 2026 12:49 | RUSTrust-1.93.0 | Success | 67,479 | ||
| Feb 11, 2026 12:14 | RUSTrust-1.93.0 | Success | 59,003 | ||
| Feb 11, 2026 11:53 | RUSTrust-1.93.0 | Error | |||
| Feb 11, 2026 11:43 | RUSTrust-1.93.0 | Success | 54,336 |