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 | Oct 9, 2025 15:31 | 4,688 | 86,581,712 | 55,952,000 | 4,995,000 | 2,514,944 | ||
| 2 | Oct 9, 2025 15:30 | 4,913 | 94,330,032 | 59,878,000 | 3,991,000 | 2,486,272 | ||
| 3 | Oct 9, 2025 15:31 | 5,345 | 96,317,481 | 66,467,000 | 3,021,000 | 2,326,528 | ||
| 4 | Oct 9, 2025 15:30 | 5,428 | 100,153,534 | 66,527,000 | 4,031,000 | 2,514,944 | ||
| 5 | Oct 9, 2025 15:30 | 5,430 | 97,571,778 | 66,553,000 | 4,033,000 | 2,494,464 | ||
| 6 | Oct 9, 2025 15:31 | 5,575 | 105,610,545 | 68,443,000 | 4,026,000 | 2,342,912 | ||
| 7 | Oct 9, 2025 15:31 | 5,581 | 102,206,304 | 68,527,000 | 4,031,000 | 2,490,368 | ||
| 8 | Oct 9, 2025 15:30 | 5,587 | 109,753,962 | 69,608,000 | 3,026,000 | 2,473,984 | ||
| 9 | Oct 9, 2025 15:31 | 5,703 | 101,954,214 | 71,132,000 | 3,005,000 | 2,387,968 | ||
| 10 | Oct 9, 2025 15:31 | 5,755 | 103,446,284 | 68,832,000 | 5,985,000 | 2,383,872 | ||
| 11 | Oct 9, 2025 15:30 | 5,880 | 104,082,864 | 72,420,000 | 4,023,000 | 2,297,856 | ||
| 12 | Oct 9, 2025 15:31 | 5,987 | 110,658,186 | 74,833,000 | 2,993,000 | 2,359,296 | ||
| 13 | Oct 9, 2025 15:30 | 6,023 | 103,936,681 | 73,277,000 | 5,018,000 | 2,424,832 | ||
| 14 | Oct 9, 2025 15:30 | 6,054 | 108,291,034 | 75,670,000 | 3,026,000 | 2,514,944 | ||
| 15 | Oct 9, 2025 15:31 | 6,102 | 104,909,875 | 73,298,000 | 6,024,000 | 2,433,024 | ||
| 16 | Oct 9, 2025 15:31 | 6,104 | 109,044,651 | 74,326,000 | 5,022,000 | 2,326,528 | ||
| 17 | Oct 9, 2025 15:31 | 6,248 | 104,875,978 | 77,219,000 | 4,011,000 | 2,338,816 | ||
| 18 | Oct 9, 2025 15:31 | 6,257 | 107,105,100 | 78,335,000 | 3,012,000 | 2,265,088 | ||
| 19 | Oct 9, 2025 15:31 | 6,279 | 116,480,622 | 78,604,000 | 3,023,000 | 2,523,136 | ||
| 20 | Oct 9, 2025 15:31 | 6,314 | 104,888,187 | 75,080,000 | 7,007,000 | 2,473,984 | ||
| 21 | Oct 9, 2025 15:31 | 6,352 | 106,370,760 | 77,543,000 | 5,035,000 | 2,498,560 | ||
| 22 | Oct 9, 2025 15:31 | 6,402 | 117,576,752 | 79,215,000 | 4,010,000 | 2,465,792 | ||
| 23 | Oct 9, 2025 15:30 | 6,450 | 110,929,999 | 78,865,000 | 4,991,000 | 2,506,752 | ||
| 24 | Oct 9, 2025 15:31 | 6,502 | 109,810,745 | 79,499,000 | 5,031,000 | 2,351,104 | ||
| 25 | Oct 9, 2025 15:30 | 6,610 | 112,117,473 | 80,939,000 | 4,996,000 | 2,486,272 | ||
| 26 | Oct 9, 2025 15:31 | 6,642 | 112,369,688 | 81,325,000 | 5,020,000 | 2,482,176 | ||
| 27 | Oct 9, 2025 15:31 | 6,789 | 119,841,626 | 84,240,000 | 4,011,000 | 2,486,272 | ||
| 28 | Oct 9, 2025 15:31 | 6,890 | 116,152,500 | 84,533,000 | 5,031,000 | 2,392,064 | ||
| 29 | Oct 9, 2025 15:31 | 7,211 | 120,786,422 | 88,760,000 | 4,986,000 | 2,514,944 | ||
| 30 | Oct 9, 2025 15:31 | 7,446 | 123,439,850 | 90,814,000 | 5,987,000 | 2,273,280 |