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 25, 2025 18:21 | 11,884 | 183,574,873 | 144,458,000 | 10,031,000 | 2,416,640 | ||
| 2 | Dec 25, 2025 19:21 | 12,374 | 187,070,691 | 153,868,000 | 6,994,000 | 2,473,984 | ||
| 3 | Dec 25, 2025 18:21 | 12,406 | 191,265,053 | 149,253,000 | 12,020,000 | 2,494,464 | ||
| 4 | Dec 25, 2025 19:21 | 12,886 | 193,553,547 | 160,492,000 | 7,021,000 | 2,457,600 | ||
| 5 | Dec 25, 2025 19:21 | 12,886 | 197,061,057 | 159,492,000 | 8,024,000 | 2,383,872 | ||
| 6 | Dec 25, 2025 18:21 | 12,950 | 194,911,425 | 164,346,000 | 4,008,000 | 2,478,080 | ||
| 7 | Dec 25, 2025 18:27 | 13,000 | 196,730,105 | 157,998,000 | 10,999,000 | 2,281,472 | ||
| 8 | Dec 25, 2025 18:27 | 13,078 | 198,174,523 | 167,015,000 | 3,000,000 | 2,441,216 | ||
| 9 | Dec 25, 2025 19:21 | 13,081 | 201,629,307 | 165,055,000 | 5,001,000 | 2,392,064 | ||
| 10 | Dec 25, 2025 19:21 | 13,130 | 202,212,489 | 160,708,000 | 9,981,000 | 2,383,872 | ||
| 11 | Dec 25, 2025 18:21 | 13,419 | 201,520,769 | 166,423,000 | 8,020,000 | 2,523,136 | ||
| 12 | Dec 25, 2025 19:21 | 13,474 | 201,964,586 | 166,151,000 | 9,008,000 | 2,387,968 | ||
| 13 | Dec 25, 2025 19:21 | 13,523 | 209,572,255 | 164,816,000 | 10,987,000 | 2,510,848 | ||
| 14 | Dec 25, 2025 18:23 | 13,524 | 205,516,014 | 168,776,000 | 7,032,000 | 2,387,968 | ||
| 15 | Dec 25, 2025 18:22 | 13,533 | 207,331,481 | 165,931,000 | 9,995,000 | 2,400,256 | ||
| 16 | Dec 25, 2025 18:22 | 13,614 | 203,783,728 | 168,980,000 | 7,999,000 | 2,433,024 | ||
| 17 | Dec 25, 2025 19:21 | 13,627 | 204,058,718 | 173,152,000 | 4,003,000 | 2,457,600 | ||
| 18 | Dec 25, 2025 18:21 | 13,645 | 205,022,673 | 169,368,000 | 8,017,000 | 2,424,832 | ||
| 19 | Dec 25, 2025 19:21 | 13,709 | 206,422,762 | 171,207,000 | 7,008,000 | 2,461,696 | ||
| 20 | Dec 25, 2025 18:21 | 13,725 | 203,222,069 | 167,398,000 | 11,026,000 | 2,465,792 | ||
| 21 | Dec 25, 2025 18:21 | 13,942 | 208,784,715 | 175,235,000 | 6,008,000 | 2,445,312 | ||
| 22 | Dec 25, 2025 18:23 | 13,984 | 210,573,365 | 173,803,000 | 7,990,000 | 2,289,664 | ||
| 23 | Dec 25, 2025 18:22 | 14,145 | 215,485,348 | 175,891,000 | 7,995,000 | 2,392,064 | ||
| 24 | Dec 25, 2025 19:21 | 14,189 | 209,575,295 | 175,436,000 | 9,022,000 | 2,351,104 | ||
| 25 | Dec 25, 2025 18:21 | 14,394 | 215,147,222 | 179,115,000 | 8,005,000 | 2,363,392 | ||
| 26 | Dec 25, 2025 18:21 | 14,455 | 222,423,808 | 176,919,000 | 10,995,000 | 2,347,008 | ||
| 27 | Dec 25, 2025 18:24 | 14,653 | 221,316,298 | 183,471,000 | 7,018,000 | 2,510,848 | ||
| 28 | Dec 25, 2025 18:24 | 14,719 | 215,725,384 | 182,329,000 | 9,016,000 | 2,400,256 | ||
| 29 | Dec 25, 2025 18:27 | 14,943 | 224,105,331 | 187,251,000 | 7,009,000 | 2,510,848 | ||
| 30 | Dec 25, 2025 18:23 | 14,995 | 222,306,320 | 186,938,000 | 7,997,000 | 2,416,640 | ||
| 31 | Dec 25, 2025 18:21 | 15,444 | 228,400,182 | 193,782,000 | 6,992,000 | 2,306,048 | ||
| 32 | Dec 25, 2025 19:21 | 15,799 | 234,212,070 | 197,372,000 | 8,015,000 | 2,347,008 | ||
| 33 | Dec 25, 2025 18:24 | 16,289 | 248,378,632 | 199,767,000 | 11,986,000 | 2,387,968 | ||
| 34 | Dec 25, 2025 18:21 | 16,373 | 238,023,672 | 202,861,000 | 9,993,000 | 2,379,776 | ||
| 35 | Dec 25, 2025 18:21 | 16,904 | 250,021,966 | 213,754,000 | 5,993,000 | 2,334,720 | ||
| 36 | Dec 25, 2025 19:21 | 17,029 | 252,388,207 | 217,369,000 | 4,006,000 | 2,347,008 |