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 | Mar 20, 2026 20:11 | 2,161 | 52,607,356 | 25,086,000 | 3,010,000 | 2,338,816 | ||
| 2 | Mar 20, 2026 20:11 | 2,170 | 49,906,249 | 23,177,000 | 5,038,000 | 2,359,296 | ||
| 3 | Mar 21, 2026 19:35 | 2,191 | 52,533,909 | 22,383,000 | 6,104,000 | 2,416,640 | ||
| 4 | Mar 21, 2026 19:35 | 2,282 | 52,233,904 | 26,599,000 | 3,069,000 | 2,506,752 | ||
| 5 | Mar 21, 2026 19:35 | 2,300 | 52,794,942 | 25,918,000 | 3,987,000 | 2,523,136 | ||
| 6 | Mar 20, 2026 20:11 | 2,318 | 52,770,144 | 25,114,000 | 5,022,000 | 2,539,520 | ||
| 7 | Mar 20, 2026 20:11 | 2,327 | 55,797,907 | 26,221,000 | 4,034,000 | 2,387,968 | ||
| 8 | Mar 21, 2026 19:35 | 2,331 | 57,483,362 | 26,266,000 | 4,041,000 | 2,527,232 | ||
| 9 | Mar 21, 2026 19:35 | 2,338 | 54,245,463 | 26,347,000 | 4,053,000 | 2,387,968 | ||
| 10 | Mar 21, 2026 19:32 | 2,344 | 64,760,504 | 26,406,000 | 4,062,000 | 2,289,664 | ||
| 11 | Mar 21, 2026 19:35 | 2,352 | 61,255,084 | 28,544,000 | 2,038,000 | 2,379,776 | ||
| 12 | Mar 21, 2026 19:32 | 2,376 | 57,452,880 | 25,911,000 | 4,982,000 | 2,510,848 | ||
| 13 | Mar 20, 2026 20:11 | 2,392 | 59,417,187 | 28,092,000 | 3,009,000 | 2,510,848 | ||
| 14 | Mar 21, 2026 19:35 | 2,394 | 55,251,003 | 28,107,000 | 3,011,000 | 2,437,120 | ||
| 15 | Mar 20, 2026 20:11 | 2,397 | 61,982,915 | 26,134,000 | 5,025,000 | 2,490,368 | ||
| 16 | Mar 21, 2026 19:35 | 2,400 | 58,552,157 | 29,182,000 | 2,012,000 | 2,461,696 | ||
| 17 | Mar 20, 2026 20:11 | 2,402 | 53,463,167 | 27,202,000 | 4,029,000 | 2,338,816 | ||
| 18 | Mar 20, 2026 20:11 | 2,419 | 58,518,828 | 28,399,000 | 3,042,000 | 2,539,520 | ||
| 19 | Mar 20, 2026 20:10 | 2,434 | 58,845,361 | 26,699,000 | 4,944,000 | 2,404,352 | ||
| 20 | Mar 20, 2026 20:11 | 2,459 | 63,438,347 | 27,966,000 | 3,995,000 | 2,371,584 | ||
| 21 | Mar 20, 2026 20:10 | 2,482 | 62,140,994 | 28,228,000 | 4,032,000 | 2,392,064 | ||
| 22 | Mar 21, 2026 19:35 | 2,508 | 56,691,309 | 28,531,000 | 4,075,000 | 2,408,448 | ||
| 23 | Mar 21, 2026 19:32 | 2,513 | 57,192,885 | 28,590,000 | 4,084,000 | 2,379,776 | ||
| 24 | Mar 20, 2026 20:11 | 2,537 | 59,237,546 | 28,984,000 | 3,997,000 | 2,428,928 | ||
| 25 | Mar 20, 2026 20:11 | 2,624 | 64,704,158 | 28,094,000 | 6,020,000 | 2,453,504 | ||
| 26 | Mar 20, 2026 20:11 | 2,653 | 56,368,193 | 28,405,000 | 6,086,000 | 2,347,008 | ||
| 27 | Mar 20, 2026 20:10 | 2,712 | 65,479,337 | 30,220,000 | 5,036,000 | 2,277,376 |