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 30, 2025 05:03 | 2,882 | 59,573,088 | 34,429,000 | 3,037,000 | 2,367,488 | ||
| 2 | Dec 30, 2025 05:02 | 3,054 | 65,879,390 | 36,652,000 | 3,054,000 | 2,310,144 | ||
| 3 | Dec 30, 2025 05:19 | 3,084 | 70,839,768 | 36,089,000 | 4,009,000 | 2,428,928 | ||
| 4 | Dec 30, 2025 05:19 | 3,101 | 64,126,274 | 36,284,000 | 4,031,000 | 2,314,240 | ||
| 5 | Dec 30, 2025 05:27 | 3,118 | 65,575,656 | 38,506,000 | 2,026,000 | 2,400,256 | ||
| 6 | Dec 30, 2025 05:18 | 3,174 | 69,915,798 | 39,247,000 | 2,012,000 | 2,478,080 | ||
| 7 | Dec 30, 2025 15:59 | 3,206 | 70,142,030 | 40,662,000 | 1,016,000 | 2,424,832 | ||
| 8 | Dec 30, 2025 05:27 | 3,226 | 70,620,005 | 40,934,000 | 998,000 | 2,367,488 | ||
| 9 | Dec 30, 2025 05:27 | 3,298 | 72,620,650 | 39,887,000 | 2,991,000 | 2,334,720 | ||
| 10 | Dec 30, 2025 05:03 | 3,299 | 67,941,521 | 40,888,000 | 1,994,000 | 2,506,752 | ||
| 11 | Dec 30, 2025 05:18 | 3,300 | 69,100,803 | 39,910,000 | 2,993,000 | 2,371,584 | ||
| 12 | Dec 30, 2025 05:19 | 3,308 | 73,124,629 | 39,006,000 | 4,000,000 | 2,367,488 | ||
| 13 | Dec 30, 2025 05:22 | 3,309 | 71,219,550 | 39,011,000 | 4,001,000 | 2,367,488 | ||
| 14 | Dec 30, 2025 15:59 | 3,315 | 70,578,001 | 41,092,000 | 2,004,000 | 2,396,160 | ||
| 15 | Dec 30, 2025 05:18 | 3,339 | 64,674,855 | 40,383,000 | 3,028,000 | 2,404,352 | ||
| 16 | Dec 30, 2025 05:27 | 3,344 | 67,441,777 | 42,467,000 | 1,011,000 | 2,269,184 | ||
| 17 | Dec 30, 2025 05:19 | 3,351 | 69,893,833 | 40,528,000 | 3,039,000 | 2,289,664 | ||
| 18 | Dec 30, 2025 05:18 | 3,376 | 71,276,938 | 40,898,000 | 2,992,000 | 2,367,488 | ||
| 19 | Dec 30, 2025 05:19 | 3,381 | 70,176,668 | 40,957,000 | 2,996,000 | 2,326,528 | ||
| 20 | Dec 30, 2025 05:03 | 3,388 | 72,510,436 | 37,041,000 | 7,007,000 | 2,506,752 | ||
| 21 | Dec 30, 2025 05:19 | 3,392 | 69,703,902 | 38,078,000 | 6,012,000 | 2,428,928 | ||
| 22 | Dec 30, 2025 05:27 | 3,407 | 69,086,859 | 41,277,000 | 3,020,000 | 2,281,472 | ||
| 23 | Dec 30, 2025 05:18 | 3,412 | 67,033,479 | 42,344,000 | 2,016,000 | 2,310,144 | ||
| 24 | Dec 30, 2025 05:19 | 3,419 | 66,502,164 | 42,426,000 | 2,020,000 | 2,330,624 | ||
| 25 | Dec 30, 2025 05:27 | 3,437 | 70,144,657 | 40,615,000 | 4,061,000 | 2,412,544 | ||
| 26 | Dec 30, 2025 05:02 | 3,452 | 69,782,572 | 41,884,000 | 2,991,000 | 2,461,696 | ||
| 27 | Dec 30, 2025 05:19 | 3,480 | 77,596,572 | 43,235,000 | 2,010,000 | 2,453,504 | ||
| 28 | Dec 30, 2025 05:20 | 3,502 | 70,021,853 | 42,492,000 | 3,035,000 | 2,375,680 | ||
| 29 | Dec 30, 2025 05:20 | 3,579 | 70,535,306 | 46,530,000 | 0 | 2,424,832 | ||
| 30 | Dec 30, 2025 05:27 | 3,613 | 71,229,871 | 43,977,000 | 2,998,000 | 2,285,568 | ||
| 31 | Dec 30, 2025 05:22 | 3,690 | 72,467,935 | 44,973,000 | 2,998,000 | 2,310,144 | ||
| 32 | Dec 30, 2025 15:59 | 3,732 | 73,736,199 | 41,439,000 | 7,075,000 | 2,482,176 | ||
| 33 | Dec 30, 2025 05:27 | 3,770 | 76,592,115 | 48,006,000 | 1,000,000 | 2,355,200 | ||
| 34 | Dec 30, 2025 05:22 | 3,800 | 72,538,082 | 46,374,000 | 3,024,000 | 2,355,200 | ||
| 35 | Dec 30, 2025 05:02 | 3,820 | 80,076,948 | 45,612,000 | 4,054,000 | 2,453,504 | ||
| 36 | Dec 30, 2025 05:18 | 3,822 | 80,607,682 | 47,655,000 | 2,027,000 | 2,392,064 | ||
| 37 | Dec 30, 2025 05:27 | 3,883 | 72,639,885 | 46,441,000 | 4,038,000 | 2,293,760 | ||
| 38 | Dec 30, 2025 05:20 | 3,977 | 80,323,385 | 49,671,000 | 2,027,000 | 2,314,240 | ||
| 39 | Dec 30, 2025 05:19 | 4,220 | 82,712,519 | 49,877,000 | 4,987,000 | 2,301,952 |