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 17:27 | 5,466 | 106,654,571 | 66,053,000 | 5,004,000 | 2,342,912 | ||
| 2 | Dec 26, 2025 17:27 | 5,635 | 99,660,846 | 69,243,000 | 4,014,000 | 2,408,448 | ||
| 3 | Dec 26, 2025 17:35 | 5,682 | 98,917,523 | 64,883,000 | 8,983,000 | 2,379,776 | ||
| 4 | Dec 26, 2025 17:26 | 5,987 | 106,947,079 | 72,847,000 | 4,989,000 | 2,412,544 | ||
| 5 | Dec 26, 2025 17:27 | 6,106 | 111,937,681 | 73,352,000 | 6,028,000 | 2,527,232 | ||
| 6 | Dec 26, 2025 17:27 | 6,156 | 113,072,180 | 73,021,000 | 7,002,000 | 2,363,392 | ||
| 7 | Dec 26, 2025 17:27 | 6,224 | 107,138,428 | 74,923,000 | 5,993,000 | 2,342,912 | ||
| 8 | Dec 26, 2025 17:35 | 6,234 | 106,900,431 | 79,043,000 | 2,001,000 | 2,342,912 | ||
| 9 | Dec 26, 2025 17:27 | 6,246 | 106,835,428 | 74,179,000 | 7,017,000 | 2,510,848 | ||
| 10 | Dec 26, 2025 17:35 | 6,272 | 106,796,138 | 78,512,000 | 3,019,000 | 2,310,144 | ||
| 11 | Dec 26, 2025 22:04 | 6,276 | 108,267,381 | 78,567,000 | 3,021,000 | 2,502,656 | ||
| 12 | Dec 26, 2025 17:35 | 6,294 | 108,393,762 | 73,835,000 | 7,982,000 | 2,465,792 | ||
| 13 | Dec 26, 2025 17:35 | 6,358 | 110,268,115 | 78,626,000 | 4,032,000 | 2,441,216 | ||
| 14 | Dec 26, 2025 17:27 | 6,474 | 113,907,433 | 77,147,000 | 7,013,000 | 2,473,984 | ||
| 15 | Dec 26, 2025 17:27 | 6,476 | 121,556,578 | 79,174,000 | 5,011,000 | 2,383,872 | ||
| 16 | Dec 26, 2025 17:27 | 6,557 | 113,599,973 | 80,232,000 | 5,014,000 | 2,301,952 | ||
| 17 | Dec 26, 2025 17:26 | 6,684 | 111,361,979 | 77,908,000 | 8,989,000 | 2,351,104 | ||
| 18 | Dec 26, 2025 17:27 | 6,708 | 117,188,377 | 83,190,000 | 4,009,000 | 2,506,752 | ||
| 19 | Dec 26, 2025 17:35 | 6,712 | 119,139,217 | 85,248,000 | 2,005,000 | 2,301,952 | ||
| 20 | Dec 26, 2025 17:27 | 6,762 | 113,270,267 | 84,910,000 | 2,996,000 | 2,404,352 | ||
| 21 | Dec 26, 2025 17:27 | 6,795 | 121,446,979 | 84,326,000 | 4,015,000 | 2,441,216 | ||
| 22 | Dec 26, 2025 22:04 | 6,800 | 119,285,231 | 83,381,000 | 5,023,000 | 2,506,752 | ||
| 23 | Dec 26, 2025 17:26 | 6,837 | 112,550,972 | 82,890,000 | 5,992,000 | 2,379,776 | ||
| 24 | Dec 26, 2025 22:04 | 6,844 | 119,569,608 | 84,974,000 | 3,998,000 | 2,338,816 | ||
| 25 | Dec 26, 2025 17:26 | 6,852 | 117,389,998 | 84,074,000 | 5,004,000 | 2,281,472 | ||
| 26 | Dec 26, 2025 17:35 | 7,087 | 117,892,318 | 87,128,000 | 5,007,000 | 2,445,312 | ||
| 27 | Dec 26, 2025 17:35 | 7,327 | 119,913,281 | 92,240,000 | 3,007,000 | 2,293,760 | ||
| 28 | Dec 26, 2025 17:35 | 7,428 | 124,703,792 | 89,525,000 | 7,041,000 | 2,400,256 | ||
| 29 | Dec 26, 2025 17:35 | 7,530 | 123,979,446 | 88,900,000 | 8,989,000 | 2,326,528 | ||
| 30 | Dec 26, 2025 17:35 | 7,779 | 127,424,617 | 95,116,000 | 6,007,000 | 2,433,024 | ||
| 31 | Dec 26, 2025 17:26 | 7,801 | 131,865,762 | 94,383,000 | 7,028,000 | 2,375,680 | ||
| 32 | Dec 26, 2025 17:26 | 7,812 | 132,248,677 | 98,534,000 | 3,016,000 | 2,494,464 | ||
| 33 | Dec 26, 2025 17:35 | 8,225 | 132,344,682 | 99,926,000 | 6,994,000 | 2,310,144 |