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 26, 2025 17:20 | 5,297 | 91,550,023 | 64,869,000 | 3,991,000 | 2,297,856 | ||
| 2 | Dec 26, 2025 17:20 | 5,481 | 101,030,060 | 67,243,000 | 4,014,000 | 2,383,872 | ||
| 3 | Dec 26, 2025 17:20 | 5,533 | 102,423,663 | 65,930,000 | 5,993,000 | 2,449,408 | ||
| 4 | Dec 26, 2025 17:17 | 5,627 | 104,116,993 | 70,142,000 | 3,006,000 | 2,310,144 | ||
| 5 | Dec 26, 2025 17:20 | 5,686 | 105,329,209 | 67,924,000 | 5,993,000 | 2,514,944 | ||
| 6 | Dec 26, 2025 17:17 | 5,770 | 102,909,448 | 67,005,000 | 8,000,000 | 2,297,856 | ||
| 7 | Dec 26, 2025 17:17 | 5,809 | 98,538,940 | 72,503,000 | 3,020,000 | 2,445,312 | ||
| 8 | Dec 26, 2025 17:32 | 5,867 | 100,838,665 | 70,251,000 | 6,021,000 | 2,482,176 | ||
| 9 | Dec 26, 2025 17:17 | 5,883 | 111,636,584 | 74,465,000 | 2,012,000 | 2,322,432 | ||
| 10 | Dec 26, 2025 17:17 | 5,911 | 100,541,052 | 72,852,000 | 3,991,000 | 2,387,968 | ||
| 11 | Dec 26, 2025 17:17 | 5,921 | 101,154,158 | 74,980,000 | 1,999,000 | 2,478,080 | ||
| 12 | Dec 26, 2025 17:17 | 5,931 | 102,085,732 | 71,101,000 | 6,008,000 | 2,314,240 | ||
| 13 | Dec 26, 2025 17:20 | 5,942 | 112,389,038 | 72,236,000 | 5,016,000 | 2,351,104 | ||
| 14 | Dec 26, 2025 17:17 | 6,108 | 101,708,773 | 76,394,000 | 3,015,000 | 2,465,792 | ||
| 15 | Dec 26, 2025 17:20 | 6,221 | 106,471,646 | 75,878,000 | 4,992,000 | 2,289,664 | ||
| 16 | Dec 26, 2025 17:17 | 6,245 | 109,116,415 | 74,166,000 | 7,015,000 | 2,494,464 | ||
| 17 | Dec 26, 2025 17:17 | 6,294 | 109,518,200 | 74,835,000 | 6,984,000 | 2,412,544 | ||
| 18 | Dec 26, 2025 17:20 | 6,295 | 113,863,830 | 77,843,000 | 3,991,000 | 2,490,368 | ||
| 19 | Dec 26, 2025 17:17 | 6,348 | 111,723,897 | 76,487,000 | 6,038,000 | 2,363,392 | ||
| 20 | Dec 26, 2025 17:17 | 6,355 | 115,110,615 | 81,607,000 | 1,007,000 | 2,334,720 | ||
| 21 | Dec 26, 2025 17:17 | 6,357 | 116,396,522 | 81,640,000 | 1,007,000 | 2,396,160 | ||
| 22 | Dec 26, 2025 17:17 | 6,494 | 113,715,017 | 81,405,000 | 3,015,000 | 2,453,504 | ||
| 23 | Dec 26, 2025 17:20 | 6,516 | 118,991,780 | 79,669,000 | 5,042,000 | 2,392,064 | ||
| 24 | Dec 26, 2025 17:20 | 6,660 | 112,643,672 | 80,543,000 | 6,040,000 | 2,277,376 | ||
| 25 | Dec 26, 2025 17:20 | 6,701 | 119,091,373 | 82,106,000 | 5,006,000 | 2,281,472 | ||
| 26 | Dec 26, 2025 17:20 | 6,888 | 115,236,223 | 86,531,000 | 3,018,000 | 2,314,240 | ||
| 27 | Dec 26, 2025 17:17 | 6,917 | 114,921,425 | 86,929,000 | 2,997,000 | 2,482,176 | ||
| 28 | Dec 26, 2025 17:32 | 6,918 | 112,520,861 | 84,938,000 | 4,996,000 | 2,310,144 | ||
| 29 | Dec 26, 2025 17:17 | 6,959 | 116,490,429 | 89,467,000 | 1,005,000 | 2,445,312 | ||
| 30 | Dec 26, 2025 17:17 | 7,003 | 116,595,383 | 87,035,000 | 4,001,000 | 2,281,472 | ||
| 31 | Dec 26, 2025 17:17 | 7,077 | 118,511,289 | 86,003,000 | 6,000,000 | 2,473,984 | ||
| 32 | Dec 26, 2025 17:32 | 7,174 | 124,978,638 | 88,243,000 | 5,013,000 | 2,457,600 | ||
| 33 | Dec 26, 2025 17:20 | 7,276 | 123,050,894 | 92,571,000 | 2,012,000 | 2,412,544 |