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 27, 2025 15:44 | 4,422 | 86,382,248 | 55,471,000 | 2,017,000 | 2,318,336 | ||
| 2 | Dec 27, 2025 15:44 | 4,616 | 85,510,375 | 56,013,000 | 4,000,000 | 2,392,064 | ||
| 3 | Dec 27, 2025 15:44 | 4,631 | 91,739,523 | 54,186,000 | 6,020,000 | 2,478,080 | ||
| 4 | Dec 27, 2025 15:44 | 4,816 | 91,057,586 | 59,582,000 | 3,029,000 | 2,404,352 | ||
| 5 | Dec 27, 2025 15:24 | 5,038 | 94,058,716 | 62,470,000 | 3,022,000 | 2,367,488 | ||
| 6 | Dec 27, 2025 15:45 | 5,089 | 90,775,889 | 61,141,000 | 5,011,000 | 2,412,544 | ||
| 7 | Dec 27, 2025 15:23 | 5,105 | 96,395,983 | 63,343,000 | 3,016,000 | 2,396,160 | ||
| 8 | Dec 27, 2025 15:23 | 5,146 | 96,738,704 | 63,909,000 | 2,995,000 | 2,301,952 | ||
| 9 | Dec 27, 2025 15:44 | 5,149 | 93,020,959 | 60,948,000 | 5,994,000 | 2,306,048 | ||
| 10 | Dec 27, 2025 15:44 | 5,246 | 99,622,479 | 63,187,000 | 5,014,000 | 2,351,104 | ||
| 11 | Dec 27, 2025 15:23 | 5,398 | 95,150,290 | 64,165,000 | 6,015,000 | 2,449,408 | ||
| 12 | Dec 27, 2025 15:44 | 5,401 | 103,422,809 | 68,206,000 | 2,006,000 | 2,351,104 | ||
| 13 | Dec 27, 2025 15:45 | 5,557 | 103,713,305 | 67,230,000 | 5,017,000 | 2,347,008 | ||
| 14 | Dec 27, 2025 15:23 | 5,641 | 102,137,762 | 70,315,000 | 3,013,000 | 2,367,488 | ||
| 15 | Dec 27, 2025 15:44 | 5,644 | 105,424,648 | 69,352,000 | 4,020,000 | 2,310,144 | ||
| 16 | Dec 27, 2025 15:23 | 5,724 | 98,545,837 | 67,376,000 | 7,039,000 | 2,338,816 | ||
| 17 | Dec 27, 2025 15:23 | 5,758 | 103,813,796 | 69,868,000 | 4,990,000 | 2,449,408 | ||
| 18 | Dec 27, 2025 15:23 | 5,797 | 101,277,654 | 72,353,000 | 3,014,000 | 2,367,488 | ||
| 19 | Dec 27, 2025 15:23 | 5,822 | 103,654,106 | 74,678,000 | 1,009,000 | 2,379,776 | ||
| 20 | Dec 27, 2025 15:23 | 5,863 | 99,123,194 | 69,197,000 | 7,020,000 | 2,461,696 | ||
| 21 | Dec 27, 2025 15:23 | 5,920 | 101,521,092 | 73,962,000 | 2,998,000 | 2,314,240 | ||
| 22 | Dec 27, 2025 15:44 | 5,960 | 106,194,305 | 75,474,000 | 2,012,000 | 2,297,856 | ||
| 23 | Dec 27, 2025 15:45 | 6,264 | 109,534,813 | 77,409,000 | 4,021,000 | 2,506,752 | ||
| 24 | Dec 27, 2025 15:24 | 6,341 | 107,650,339 | 80,428,000 | 2,010,000 | 2,375,680 | ||
| 25 | Dec 27, 2025 15:23 | 6,460 | 114,164,474 | 81,975,000 | 1,999,000 | 2,330,624 | ||
| 26 | Dec 27, 2025 15:23 | 6,488 | 117,389,060 | 81,338,000 | 3,012,000 | 2,338,816 | ||
| 27 | Dec 27, 2025 15:24 | 6,824 | 115,236,479 | 87,701,000 | 1,008,000 | 2,363,392 |