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 29, 2025 14:58 | 3,130 | 68,825,103 | 38,659,000 | 2,034,000 | 2,416,640 | ||
| 2 | Dec 29, 2025 14:55 | 3,180 | 63,707,296 | 37,303,000 | 4,032,000 | 2,400,256 | ||
| 3 | Dec 29, 2025 14:58 | 3,299 | 71,442,138 | 41,885,000 | 997,000 | 2,404,352 | ||
| 4 | Dec 29, 2025 14:58 | 3,299 | 73,181,059 | 38,893,000 | 3,989,000 | 2,519,040 | ||
| 5 | Dec 29, 2025 14:57 | 3,375 | 68,798,005 | 40,881,000 | 2,991,000 | 2,490,368 | ||
| 6 | Dec 29, 2025 14:58 | 3,441 | 75,687,994 | 41,686,000 | 3,050,000 | 2,433,024 | ||
| 7 | Dec 29, 2025 14:58 | 3,461 | 76,445,488 | 41,988,000 | 2,999,000 | 2,269,184 | ||
| 8 | Dec 29, 2025 14:58 | 3,505 | 67,723,832 | 39,487,000 | 6,074,000 | 2,506,752 | ||
| 9 | Dec 29, 2025 14:57 | 3,518 | 76,932,158 | 40,651,000 | 5,081,000 | 2,285,568 | ||
| 10 | Dec 29, 2025 14:54 | 3,549 | 71,514,689 | 43,130,000 | 3,009,000 | 2,408,448 | ||
| 11 | Dec 29, 2025 14:57 | 3,566 | 78,635,402 | 43,332,000 | 3,023,000 | 2,330,624 | ||
| 12 | Dec 29, 2025 14:54 | 3,593 | 74,461,233 | 45,691,000 | 1,015,000 | 2,428,928 | ||
| 13 | Dec 29, 2025 14:55 | 3,606 | 83,794,382 | 44,883,000 | 1,994,000 | 2,449,408 | ||
| 14 | Dec 29, 2025 15:00 | 3,607 | 78,962,461 | 44,893,000 | 1,995,000 | 2,355,200 | ||
| 15 | Dec 29, 2025 14:52 | 3,612 | 72,792,059 | 42,960,000 | 3,996,000 | 2,351,104 | ||
| 16 | Dec 29, 2025 14:55 | 3,624 | 74,053,805 | 44,110,000 | 3,007,000 | 2,510,848 | ||
| 17 | Dec 29, 2025 14:58 | 3,627 | 74,184,472 | 43,133,000 | 4,012,000 | 2,420,736 | ||
| 18 | Dec 29, 2025 14:50 | 3,628 | 74,406,517 | 44,155,000 | 3,010,000 | 2,396,160 | ||
| 19 | Dec 29, 2025 14:58 | 3,634 | 72,898,490 | 41,216,000 | 6,031,000 | 2,363,392 | ||
| 20 | Dec 29, 2025 15:01 | 3,714 | 77,092,845 | 45,259,000 | 3,017,000 | 2,510,848 | ||
| 21 | Dec 29, 2025 15:00 | 3,720 | 73,793,772 | 46,341,000 | 2,014,000 | 2,379,776 | ||
| 22 | Dec 29, 2025 14:58 | 3,720 | 79,531,983 | 42,316,000 | 6,045,000 | 2,469,888 | ||
| 23 | Dec 29, 2025 15:00 | 3,823 | 81,128,330 | 47,677,000 | 2,028,000 | 2,330,624 | ||
| 24 | Dec 29, 2025 14:52 | 3,825 | 79,892,198 | 47,699,000 | 2,029,000 | 2,367,488 | ||
| 25 | Dec 29, 2025 14:50 | 3,837 | 75,951,111 | 45,892,000 | 3,990,000 | 2,379,776 | ||
| 26 | Dec 29, 2025 14:52 | 3,861 | 77,245,166 | 46,179,000 | 4,015,000 | 2,494,464 | ||
| 27 | Dec 29, 2025 14:50 | 3,866 | 81,562,789 | 48,249,000 | 2,010,000 | 2,412,544 | ||
| 28 | Dec 29, 2025 15:01 | 3,928 | 85,239,281 | 48,061,000 | 3,003,000 | 2,301,952 | ||
| 29 | Dec 29, 2025 15:01 | 3,935 | 77,240,448 | 46,135,000 | 5,014,000 | 2,412,544 | ||
| 30 | Dec 29, 2025 14:54 | 3,999 | 76,898,295 | 48,983,000 | 2,998,000 | 2,387,968 |