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 25, 2025 21:10 | 11,243 | 178,497,562 | 139,149,000 | 7,007,000 | 2,281,472 | ||
| 2 | Dec 25, 2025 21:10 | 11,271 | 178,349,603 | 138,494,000 | 8,028,000 | 2,322,432 | ||
| 3 | Dec 25, 2025 21:10 | 12,152 | 189,308,120 | 147,973,000 | 9,998,000 | 2,482,176 | ||
| 4 | Dec 25, 2025 21:10 | 12,604 | 191,599,228 | 154,866,000 | 8,992,000 | 2,351,104 | ||
| 5 | Dec 25, 2025 21:10 | 12,860 | 198,496,559 | 159,170,000 | 8,008,000 | 2,301,952 | ||
| 6 | Dec 25, 2025 21:09 | 13,173 | 199,477,695 | 165,238,000 | 6,008,000 | 2,408,448 | ||
| 7 | Dec 25, 2025 21:09 | 13,399 | 202,421,962 | 166,183,000 | 8,008,000 | 2,420,736 | ||
| 8 | Dec 25, 2025 21:10 | 13,494 | 207,860,947 | 168,400,000 | 7,016,000 | 2,510,848 | ||
| 9 | Dec 25, 2025 21:09 | 13,844 | 206,379,541 | 169,978,000 | 9,998,000 | 2,293,760 | ||
| 10 | Dec 25, 2025 21:10 | 13,861 | 209,054,746 | 172,184,000 | 8,008,000 | 2,449,408 | ||
| 11 | Dec 25, 2025 21:10 | 13,989 | 214,879,665 | 174,864,000 | 6,994,000 | 2,445,312 | ||
| 12 | Dec 25, 2025 21:10 | 14,039 | 211,648,157 | 175,493,000 | 7,019,000 | 2,428,928 | ||
| 13 | Dec 25, 2025 21:10 | 14,250 | 211,611,126 | 178,240,000 | 7,009,000 | 2,306,048 | ||
| 14 | Dec 25, 2025 21:09 | 14,303 | 212,787,001 | 174,937,000 | 10,996,000 | 2,322,432 | ||
| 15 | Dec 25, 2025 21:10 | 14,315 | 219,041,922 | 175,092,000 | 11,005,000 | 2,510,848 | ||
| 16 | Dec 25, 2025 21:10 | 14,424 | 216,150,106 | 180,490,000 | 7,019,000 | 2,363,392 | ||
| 17 | Dec 25, 2025 21:10 | 14,519 | 218,214,952 | 177,767,000 | 10,985,000 | 2,510,848 | ||
| 18 | Dec 25, 2025 21:10 | 14,594 | 223,699,770 | 178,741,000 | 10,984,000 | 2,404,352 | ||
| 19 | Dec 25, 2025 21:10 | 14,651 | 213,874,278 | 181,438,000 | 9,021,000 | 2,404,352 | ||
| 20 | Dec 25, 2025 21:09 | 14,873 | 221,006,889 | 186,339,000 | 7,012,000 | 2,498,560 | ||
| 21 | Dec 25, 2025 21:09 | 15,040 | 230,996,945 | 184,489,000 | 11,029,000 | 2,416,640 | ||
| 22 | Dec 25, 2025 21:10 | 15,230 | 226,281,107 | 193,990,000 | 3,999,000 | 2,351,104 | ||
| 23 | Dec 25, 2025 21:10 | 15,521 | 229,781,259 | 192,788,000 | 8,990,000 | 2,404,352 | ||
| 24 | Dec 25, 2025 21:10 | 15,832 | 234,168,297 | 192,826,000 | 12,988,000 | 2,428,928 | ||
| 25 | Dec 25, 2025 21:10 | 16,349 | 240,511,115 | 205,525,000 | 7,017,000 | 2,510,848 | ||
| 26 | Dec 25, 2025 21:10 | 16,367 | 244,638,418 | 205,773,000 | 6,992,000 | 2,445,312 | ||
| 27 | Dec 25, 2025 21:10 | 16,589 | 243,122,931 | 205,674,000 | 9,984,000 | 2,387,968 |