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:01 | 6,078 | 104,432,397 | 74,014,000 | 5,000,000 | 2,314,240 | ||
| 2 | Oct 9, 2025 15:01 | 6,382 | 115,399,761 | 79,969,000 | 2,998,000 | 2,473,984 | ||
| 3 | Oct 9, 2025 15:00 | 6,409 | 113,234,678 | 78,299,000 | 5,019,000 | 2,277,376 | ||
| 4 | Oct 9, 2025 15:00 | 6,469 | 110,145,797 | 79,088,000 | 5,005,000 | 2,289,664 | ||
| 5 | Oct 8, 2025 20:29 | 6,596 | 114,825,030 | 80,757,000 | 4,985,000 | 2,379,776 | ||
| 6 | Oct 8, 2025 20:29 | 6,681 | 113,333,345 | 84,851,000 | 1,996,000 | 2,265,088 | ||
| 7 | Oct 9, 2025 15:01 | 6,774 | 114,412,820 | 84,056,000 | 4,002,000 | 2,437,120 | ||
| 8 | Oct 9, 2025 15:01 | 6,854 | 114,746,716 | 85,098,000 | 4,004,000 | 2,502,656 | ||
| 9 | Oct 9, 2025 14:58 | 6,904 | 115,613,037 | 84,762,000 | 4,986,000 | 2,301,952 | ||
| 10 | Oct 8, 2025 20:29 | 7,024 | 117,508,646 | 87,299,000 | 4,013,000 | 2,486,272 | ||
| 11 | Oct 9, 2025 15:00 | 7,096 | 119,997,718 | 88,233,000 | 4,010,000 | 2,482,176 | ||
| 12 | Oct 9, 2025 15:00 | 7,112 | 117,292,186 | 86,426,000 | 6,029,000 | 2,351,104 | ||
| 13 | Oct 8, 2025 20:29 | 7,137 | 125,016,110 | 85,801,000 | 6,983,000 | 2,498,560 | ||
| 14 | Oct 9, 2025 15:00 | 7,229 | 120,046,100 | 89,983,000 | 3,999,000 | 2,269,184 | ||
| 15 | Oct 9, 2025 15:00 | 7,238 | 125,782,170 | 90,087,000 | 4,003,000 | 2,510,848 | ||
| 16 | Oct 9, 2025 15:01 | 7,248 | 126,079,704 | 89,216,000 | 5,012,000 | 2,449,408 | ||
| 17 | Oct 9, 2025 15:00 | 7,373 | 125,560,338 | 90,858,000 | 4,992,000 | 2,457,600 | ||
| 18 | Oct 8, 2025 20:29 | 7,375 | 125,021,258 | 91,883,000 | 3,994,000 | 2,514,944 | ||
| 19 | Oct 9, 2025 14:58 | 7,381 | 127,412,337 | 90,956,000 | 4,997,000 | 2,510,848 | ||
| 20 | Oct 9, 2025 15:01 | 7,396 | 120,803,917 | 91,139,000 | 5,007,000 | 2,338,816 | ||
| 21 | Oct 9, 2025 15:01 | 7,399 | 121,196,470 | 94,185,000 | 2,003,000 | 2,494,464 | ||
| 22 | Oct 9, 2025 15:00 | 7,889 | 129,270,906 | 98,539,000 | 4,022,000 | 2,465,792 | ||
| 23 | Oct 9, 2025 15:01 | 7,952 | 130,160,813 | 98,354,000 | 5,018,000 | 2,416,640 | ||
| 24 | Oct 9, 2025 15:00 | 7,990 | 137,139,747 | 99,877,000 | 3,995,000 | 2,490,368 | ||
| 25 | Oct 8, 2025 20:29 | 8,076 | 131,880,855 | 99,983,000 | 4,999,000 | 2,396,160 | ||
| 26 | Oct 9, 2025 14:58 | 8,077 | 129,536,585 | 101,996,000 | 2,999,000 | 2,392,064 | ||
| 27 | Oct 8, 2025 20:29 | 8,098 | 133,822,589 | 100,263,000 | 5,013,000 | 2,392,064 | ||
| 28 | Oct 9, 2025 15:01 | 8,236 | 132,796,749 | 104,063,000 | 3,001,000 | 2,461,696 | ||
| 29 | Oct 8, 2025 20:29 | 8,662 | 138,765,297 | 107,585,000 | 5,027,000 | 2,437,120 | ||
| 30 | Oct 8, 2025 20:29 | 9,663 | 156,715,696 | 121,594,000 | 4,019,000 | 2,433,024 |