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 | Feb 21, 2026 02:59 | 8,960 | 142,821,191 | 111,462,000 | 5,020,000 | 2,281,472 | ||
| 2 | Feb 21, 2026 07:26 | 9,112 | 150,533,803 | 109,427,000 | 9,035,000 | 2,416,640 | ||
| 3 | Feb 21, 2026 07:26 | 9,677 | 159,970,225 | 120,806,000 | 4,991,000 | 2,449,408 | ||
| 4 | Feb 21, 2026 02:59 | 9,908 | 166,733,697 | 123,812,000 | 4,992,000 | 2,510,848 | ||
| 5 | Feb 21, 2026 02:59 | 9,989 | 160,969,543 | 125,863,000 | 3,995,000 | 2,367,488 | ||
| 6 | Feb 21, 2026 07:26 | 10,048 | 155,820,768 | 127,610,000 | 3,014,000 | 2,306,048 | ||
| 7 | Feb 21, 2026 02:59 | 10,073 | 160,209,720 | 126,950,000 | 3,998,000 | 2,457,600 | ||
| 8 | Feb 21, 2026 02:59 | 10,539 | 162,514,292 | 133,005,000 | 4,000,000 | 2,506,752 | ||
| 9 | Feb 21, 2026 02:59 | 10,625 | 170,273,851 | 134,117,000 | 4,003,000 | 2,514,944 | ||
| 10 | Feb 21, 2026 06:17 | 10,662 | 164,307,575 | 134,588,000 | 4,017,000 | 2,465,792 | ||
| 11 | Feb 21, 2026 07:26 | 10,775 | 167,797,273 | 135,067,000 | 5,002,000 | 2,433,024 | ||
| 12 | Feb 21, 2026 07:26 | 10,886 | 167,146,621 | 135,500,000 | 6,022,000 | 2,510,848 | ||
| 13 | Feb 21, 2026 15:00 | 10,912 | 165,484,512 | 135,868,000 | 5,994,000 | 2,527,232 | ||
| 14 | Feb 21, 2026 07:26 | 11,146 | 170,668,573 | 141,897,000 | 2,997,000 | 2,506,752 | ||
| 15 | Feb 21, 2026 02:59 | 11,198 | 178,015,945 | 140,550,000 | 5,019,000 | 2,453,504 | ||
| 16 | Feb 21, 2026 03:29 | 11,296 | 175,238,277 | 144,853,000 | 1,997,000 | 2,375,680 | ||
| 17 | Feb 21, 2026 14:49 | 11,355 | 174,142,229 | 144,608,000 | 3,012,000 | 2,510,848 | ||
| 18 | Feb 21, 2026 03:29 | 11,358 | 171,761,494 | 143,639,000 | 4,017,000 | 2,322,432 | ||
| 19 | Feb 21, 2026 06:17 | 11,596 | 179,655,315 | 146,753,000 | 3,993,000 | 2,428,928 | ||
| 20 | Feb 21, 2026 07:26 | 11,603 | 179,636,276 | 143,853,000 | 6,992,000 | 2,314,240 | ||
| 21 | Feb 21, 2026 14:49 | 11,669 | 181,639,449 | 146,711,000 | 4,990,000 | 2,408,448 | ||
| 22 | Feb 21, 2026 14:49 | 11,691 | 177,046,075 | 148,984,000 | 2,999,000 | 2,330,624 | ||
| 23 | Feb 21, 2026 07:26 | 11,770 | 182,596,617 | 149,013,000 | 4,000,000 | 2,297,856 | ||
| 24 | Feb 21, 2026 15:00 | 11,844 | 185,875,300 | 147,969,000 | 5,998,000 | 2,486,272 | ||
| 25 | Feb 21, 2026 02:59 | 11,861 | 184,014,153 | 151,185,000 | 3,003,000 | 2,502,656 | ||
| 26 | Feb 21, 2026 07:26 | 12,178 | 190,572,186 | 155,313,000 | 3,006,000 | 2,367,488 | ||
| 27 | Feb 21, 2026 06:17 | 12,182 | 181,901,554 | 154,356,000 | 4,009,000 | 2,363,392 | ||
| 28 | Feb 21, 2026 02:59 | 12,409 | 189,208,280 | 155,307,000 | 6,011,000 | 2,461,696 | ||
| 29 | Feb 21, 2026 03:29 | 12,547 | 189,782,459 | 159,103,000 | 4,002,000 | 2,293,760 | ||
| 30 | Feb 21, 2026 15:00 | 13,108 | 196,668,651 | 168,397,000 | 2,004,000 | 2,486,272 |