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 24, 2025 22:16 | 12,446 | 187,559,542 | 149,811,000 | 11,984,000 | 2,478,080 | ||
| 2 | Dec 24, 2025 22:16 | 12,657 | 191,727,554 | 160,524,000 | 4,013,000 | 2,498,560 | ||
| 3 | Dec 24, 2025 22:22 | 12,936 | 193,199,612 | 162,167,000 | 6,006,000 | 2,330,624 | ||
| 4 | Dec 24, 2025 22:23 | 12,981 | 195,562,366 | 163,758,000 | 4,992,000 | 2,490,368 | ||
| 5 | Dec 24, 2025 22:22 | 12,987 | 196,073,296 | 162,842,000 | 5,994,000 | 2,379,776 | ||
| 6 | Dec 24, 2025 22:16 | 13,061 | 202,106,821 | 164,798,000 | 4,993,000 | 2,351,104 | ||
| 7 | Dec 24, 2025 22:22 | 13,200 | 199,352,294 | 168,589,000 | 3,010,000 | 2,400,256 | ||
| 8 | Dec 24, 2025 22:16 | 13,292 | 206,449,293 | 168,795,000 | 3,995,000 | 2,535,424 | ||
| 9 | Dec 24, 2025 22:22 | 13,427 | 206,099,662 | 168,530,000 | 6,018,000 | 2,338,816 | ||
| 10 | Dec 24, 2025 22:22 | 13,525 | 204,245,941 | 167,835,000 | 7,992,000 | 2,347,008 | ||
| 11 | Dec 24, 2025 22:16 | 13,736 | 205,345,459 | 171,551,000 | 7,022,000 | 2,342,912 | ||
| 12 | Dec 24, 2025 22:16 | 13,856 | 210,958,728 | 173,123,000 | 7,004,000 | 2,457,600 | ||
| 13 | Dec 24, 2025 22:16 | 13,865 | 202,988,382 | 172,236,000 | 8,011,000 | 2,469,888 | ||
| 14 | Dec 24, 2025 22:22 | 13,914 | 210,331,071 | 171,892,000 | 8,994,000 | 2,416,640 | ||
| 15 | Dec 24, 2025 22:23 | 13,980 | 208,915,468 | 175,750,000 | 5,991,000 | 2,363,392 | ||
| 16 | Dec 24, 2025 22:16 | 14,213 | 218,356,246 | 178,783,000 | 5,992,000 | 2,514,944 | ||
| 17 | Dec 24, 2025 22:22 | 14,338 | 213,516,591 | 176,371,000 | 10,021,000 | 2,461,696 | ||
| 18 | Dec 24, 2025 22:16 | 14,554 | 218,513,773 | 181,197,000 | 8,008,000 | 2,535,424 | ||
| 19 | Dec 24, 2025 22:22 | 14,582 | 216,861,637 | 180,537,000 | 9,026,000 | 2,482,176 | ||
| 20 | Dec 24, 2025 22:16 | 14,624 | 218,699,717 | 182,113,000 | 8,005,000 | 2,510,848 | ||
| 21 | Dec 24, 2025 22:16 | 14,714 | 222,233,445 | 186,270,000 | 5,007,000 | 2,453,504 | ||
| 22 | Dec 24, 2025 22:22 | 14,779 | 221,210,926 | 184,119,000 | 8,005,000 | 2,277,376 | ||
| 23 | Dec 24, 2025 22:22 | 15,134 | 224,781,185 | 193,742,000 | 2,996,000 | 2,363,392 | ||
| 24 | Dec 24, 2025 22:23 | 15,160 | 225,450,753 | 190,080,000 | 7,002,000 | 2,351,104 | ||
| 25 | Dec 24, 2025 22:16 | 15,286 | 226,921,469 | 188,731,000 | 9,985,000 | 2,297,856 | ||
| 26 | Dec 24, 2025 22:16 | 16,058 | 238,422,319 | 202,766,000 | 5,993,000 | 2,301,952 | ||
| 27 | Dec 24, 2025 22:16 | 16,157 | 236,544,373 | 205,043,000 | 5,001,000 | 2,318,336 | ||
| 28 | Dec 24, 2025 22:22 | 16,290 | 243,354,107 | 207,781,000 | 3,995,000 | 2,412,544 | ||
| 29 | Dec 24, 2025 22:16 | 16,613 | 244,038,506 | 208,976,000 | 6,999,000 | 2,359,296 | ||
| 30 | Dec 24, 2025 22:16 | 16,912 | 248,968,524 | 214,866,000 | 4,996,000 | 2,297,856 | ||
| 31 | Dec 24, 2025 22:22 | 17,020 | 253,829,758 | 211,243,000 | 10,011,000 | 2,535,424 | ||
| 32 | Dec 24, 2025 22:22 | 17,072 | 263,279,445 | 217,932,000 | 3,998,000 | 2,486,272 | ||
| 33 | Dec 24, 2025 22:22 | 17,164 | 252,875,087 | 217,133,000 | 6,003,000 | 2,457,600 | ||
| 34 | Dec 24, 2025 22:16 | 17,287 | 254,091,062 | 222,728,000 | 1,997,000 | 2,367,488 | ||
| 35 | Dec 24, 2025 22:16 | 17,310 | 247,721,459 | 220,029,000 | 5,000,000 | 2,478,080 | ||
| 36 | Dec 24, 2025 22:22 | 17,467 | 265,063,349 | 221,068,000 | 6,001,000 | 2,301,952 |