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 23:27 | 4,709 | 88,599,713 | 53,185,000 | 8,027,000 | 2,277,376 | ||
| 2 | Dec 26, 2025 23:27 | 4,989 | 89,283,188 | 59,869,000 | 4,989,000 | 2,396,160 | ||
| 3 | Dec 26, 2025 23:27 | 5,029 | 93,784,081 | 63,361,000 | 2,011,000 | 2,469,888 | ||
| 4 | Dec 26, 2025 23:26 | 5,063 | 91,896,932 | 61,835,000 | 3,989,000 | 2,465,792 | ||
| 5 | Dec 26, 2025 23:27 | 5,129 | 93,656,158 | 59,605,000 | 7,071,000 | 2,502,656 | ||
| 6 | Dec 26, 2025 23:25 | 5,188 | 94,460,690 | 64,428,000 | 3,020,000 | 2,314,240 | ||
| 7 | Dec 26, 2025 23:27 | 5,219 | 97,653,021 | 65,852,000 | 1,995,000 | 2,461,696 | ||
| 8 | Dec 26, 2025 23:26 | 5,307 | 93,893,153 | 60,987,000 | 7,998,000 | 2,281,472 | ||
| 9 | Dec 26, 2025 23:27 | 5,367 | 105,778,738 | 64,790,000 | 4,983,000 | 2,416,640 | ||
| 10 | Dec 26, 2025 23:27 | 5,374 | 104,264,595 | 65,869,000 | 3,992,000 | 2,375,680 | ||
| 11 | Dec 26, 2025 23:27 | 5,427 | 97,349,466 | 66,515,000 | 4,031,000 | 2,510,848 | ||
| 12 | Dec 26, 2025 23:25 | 5,436 | 98,924,926 | 66,630,000 | 4,038,000 | 2,506,752 | ||
| 13 | Dec 26, 2025 23:27 | 5,449 | 101,018,757 | 65,844,000 | 4,988,000 | 2,396,160 | ||
| 14 | Dec 26, 2025 23:27 | 5,462 | 97,384,131 | 65,001,000 | 6,000,000 | 2,465,792 | ||
| 15 | Dec 26, 2025 23:27 | 5,562 | 104,305,889 | 66,281,000 | 6,025,000 | 2,383,872 | ||
| 16 | Dec 26, 2025 23:27 | 5,578 | 101,372,249 | 68,483,000 | 4,028,000 | 2,465,792 | ||
| 17 | Dec 26, 2025 23:25 | 5,627 | 106,410,004 | 66,141,000 | 7,014,000 | 2,469,888 | ||
| 18 | Dec 26, 2025 23:27 | 5,628 | 100,600,315 | 72,166,000 | 1,002,000 | 2,510,848 | ||
| 19 | Dec 26, 2025 23:25 | 5,785 | 105,083,562 | 69,189,000 | 6,016,000 | 2,523,136 | ||
| 20 | Dec 26, 2025 23:27 | 5,841 | 103,130,991 | 74,937,000 | 999,000 | 2,371,584 | ||
| 21 | Dec 26, 2025 23:25 | 5,884 | 106,892,205 | 75,490,000 | 1,006,000 | 2,330,624 | ||
| 22 | Dec 26, 2025 23:25 | 5,905 | 113,027,464 | 70,779,000 | 5,981,000 | 2,379,776 | ||
| 23 | Dec 26, 2025 23:27 | 6,142 | 108,918,753 | 75,851,000 | 3,992,000 | 2,473,984 | ||
| 24 | Dec 26, 2025 23:27 | 6,152 | 109,482,218 | 75,979,000 | 3,998,000 | 2,514,944 | ||
| 25 | Dec 26, 2025 23:27 | 6,194 | 108,341,513 | 74,489,000 | 6,039,000 | 2,314,240 | ||
| 26 | Dec 26, 2025 23:26 | 6,204 | 108,308,356 | 78,634,000 | 2,016,000 | 2,494,464 | ||
| 27 | Dec 26, 2025 23:27 | 6,602 | 112,987,456 | 83,825,000 | 1,995,000 | 2,506,752 |