Cross-Margin Liquidation Engine 
Simulate a cross-margin derivatives engine: process trades, track account equity, and liquidate undercollateralized accounts as fast as possible.
Accounts are funded with a USD deposit and trade instruments whose prices change over time. When a price update causes an account’s equity to fall below 1% of its total position notional, the account must be liquidated.
Definitions
- Account equity =
balance + Σ(size_i * price_i) - Σ(total_paid_i) - Total position notional =
Σ(|size_i| * price_i) - Total paid for instrument
i= signed sum oftrade_size * price_at_trade_timeacross all trades - Margin rule: liquidate if
equity < total_notional / 100after any price update
Input
One command per line on STDIN:
a <balance>– create account with USD balance (IDs start at0, incrementing)p <instrument_idx> <price>– set/update instrument price (0-indexed)t <account_idx> <instrument_idx> <size>– tradesize(signed) at current price- Final line:
<account_idx>– query this account and terminate
Output
On each price update, liquidate all accounts violating the margin rule. For each liquidation, print:
liquidate <account_id> <equity> <position_notional>
Liquidation order: largest total position notional first, then account ID descending as tie-breaker. Liquidated accounts have their balance and positions cleared.
For the final query, print <equity> <notional> for the requested account.
Constraints
- Accounts: <= 100,000
- Instruments: <= 1,000
- Price range: 100 to 1,000,000
- Trade size range: 1 to 10,000
Example
a 100
p 0 100
t 0 0 10
p 0 90
0
Output:
liquidate 0 0 900
0 0
Source code access is restricted. Log in to request access.
No challenges yet.
| # | Date | Score | Wall Time | CPU User | CPU System | Memory | Error | |
|---|---|---|---|---|---|---|---|---|
| 1 | Dec 22, 2025 16:53 | 53,222 | 716,352,295 | 681,884,000 | 9,998,000 | 2,506,752 | ||
| 2 | Dec 22, 2025 19:39 | 54,662 | 742,694,531 | 702,613,000 | 7,995,000 | 2,465,792 | ||
| 3 | Dec 22, 2025 16:53 | 56,946 | 771,412,889 | 731,293,000 | 9,003,000 | 2,363,392 | ||
| 4 | Dec 22, 2025 16:10 | 57,417 | 770,268,215 | 739,422,000 | 6,994,000 | 2,531,328 | ||
| 5 | Dec 22, 2025 22:50 | 57,909 | 780,770,039 | 746,823,000 | 5,998,000 | 2,428,928 | ||
| 6 | Dec 22, 2025 19:39 | 58,041 | 785,376,480 | 746,543,000 | 7,995,000 | 2,359,296 | ||
| 7 | Dec 22, 2025 16:53 | 58,569 | 785,672,565 | 754,404,000 | 6,994,000 | 2,342,912 | ||
| 8 | Dec 22, 2025 16:53 | 58,816 | 794,217,940 | 756,612,000 | 7,995,000 | 2,404,352 | ||
| 9 | Dec 22, 2025 22:50 | 59,152 | 794,839,566 | 761,976,000 | 6,999,000 | 2,498,560 | ||
| 10 | Dec 22, 2025 22:50 | 60,439 | 810,758,143 | 777,716,000 | 7,997,000 | 2,482,176 | ||
| 11 | Dec 22, 2025 16:10 | 60,533 | 818,636,130 | 778,931,000 | 7,999,000 | 2,531,328 | ||
| 12 | Dec 22, 2025 16:53 | 61,268 | 821,564,899 | 792,482,000 | 3,997,000 | 2,416,640 | ||
| 13 | Dec 22, 2025 16:53 | 61,570 | 829,791,337 | 796,417,000 | 3,997,000 | 2,465,792 | ||
| 14 | Dec 23, 2025 03:58 | 61,584 | 829,194,534 | 794,599,000 | 5,996,000 | 2,342,912 | ||
| 15 | Dec 23, 2025 03:58 | 63,033 | 846,320,382 | 814,433,000 | 4,996,000 | 2,367,488 | ||
| 16 | Dec 22, 2025 16:53 | 63,698 | 854,656,524 | 822,073,000 | 6,000,000 | 2,342,912 | ||
| 17 | Dec 22, 2025 22:50 | 64,508 | 865,845,433 | 832,612,000 | 5,997,000 | 2,293,760 | ||
| 18 | Dec 22, 2025 22:50 | 65,952 | 887,592,884 | 849,386,000 | 7,994,000 | 2,473,984 | ||
| 19 | Dec 23, 2025 03:58 | 66,043 | 881,191,144 | 851,566,000 | 6,996,000 | 2,404,352 | ||
| 20 | Dec 22, 2025 22:50 | 66,066 | 885,803,150 | 852,856,000 | 5,998,000 | 2,301,952 | ||
| 21 | Dec 22, 2025 22:50 | 66,342 | 889,872,725 | 855,445,000 | 6,995,000 | 2,326,528 | ||
| 22 | Dec 22, 2025 16:53 | 66,752 | 896,550,927 | 863,779,000 | 3,998,000 | 2,412,544 | ||
| 23 | Dec 22, 2025 16:53 | 67,665 | 909,480,090 | 870,643,000 | 8,996,000 | 2,379,776 | ||
| 24 | Dec 22, 2025 19:39 | 68,876 | 919,981,188 | 890,387,000 | 4,996,000 | 2,400,256 | ||
| 25 | Dec 22, 2025 16:10 | 69,307 | 926,893,522 | 896,988,000 | 3,999,000 | 2,445,312 | ||
| 26 | Dec 22, 2025 22:50 | 75,591 | 1,007,411,368 | 976,687,000 | 5,998,000 | 2,330,624 | ||
| 27 | Dec 22, 2025 22:50 | 79,269 | 1,060,332,611 | 1,020,508,000 | 9,995,000 | 2,519,040 |