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 29, 2025 06:13 | 3,092 | 65,215,020 | 38,192,000 | 2,010,000 | 2,523,136 | ||
| 2 | Dec 29, 2025 06:13 | 3,107 | 66,120,320 | 38,367,000 | 2,019,000 | 2,293,760 | ||
| 3 | Dec 29, 2025 06:13 | 3,461 | 78,680,874 | 41,999,000 | 2,999,000 | 2,498,560 | ||
| 4 | Dec 29, 2025 06:15 | 3,482 | 74,044,003 | 42,251,000 | 3,017,000 | 2,375,680 | ||
| 5 | Dec 29, 2025 06:15 | 3,514 | 71,480,256 | 41,626,000 | 4,061,000 | 2,334,720 | ||
| 6 | Dec 29, 2025 06:10 | 3,555 | 71,692,333 | 42,199,000 | 4,019,000 | 2,445,312 | ||
| 7 | Dec 29, 2025 06:14 | 3,565 | 70,302,913 | 44,333,000 | 2,015,000 | 2,428,928 | ||
| 8 | Dec 29, 2025 06:14 | 3,592 | 72,518,177 | 42,635,000 | 4,060,000 | 2,441,216 | ||
| 9 | Dec 29, 2025 06:13 | 3,660 | 74,414,762 | 46,565,000 | 1,012,000 | 2,334,720 | ||
| 10 | Dec 29, 2025 06:10 | 3,668 | 72,972,812 | 46,667,000 | 1,014,000 | 2,400,256 | ||
| 11 | Dec 29, 2025 06:14 | 3,695 | 77,132,822 | 45,036,000 | 3,002,000 | 2,453,504 | ||
| 12 | Dec 29, 2025 06:11 | 3,707 | 76,930,857 | 46,178,000 | 2,007,000 | 2,334,720 | ||
| 13 | Dec 29, 2025 06:12 | 3,729 | 69,769,038 | 43,429,000 | 5,049,000 | 2,269,184 | ||
| 14 | Dec 29, 2025 06:13 | 3,741 | 73,621,406 | 45,595,000 | 3,039,000 | 2,326,528 | ||
| 15 | Dec 29, 2025 06:15 | 3,794 | 77,147,811 | 44,284,000 | 5,032,000 | 2,445,312 | ||
| 16 | Dec 29, 2025 06:12 | 3,798 | 77,049,878 | 45,347,000 | 4,030,000 | 2,363,392 | ||
| 17 | Dec 29, 2025 06:11 | 3,800 | 74,757,831 | 44,355,000 | 5,040,000 | 2,301,952 | ||
| 18 | Dec 29, 2025 06:11 | 3,814 | 71,457,386 | 46,552,000 | 3,036,000 | 2,408,448 | ||
| 19 | Dec 29, 2025 06:10 | 3,837 | 80,644,415 | 47,884,000 | 1,995,000 | 2,318,336 | ||
| 20 | Dec 29, 2025 06:13 | 3,842 | 79,505,825 | 46,944,000 | 2,996,000 | 2,355,200 | ||
| 21 | Dec 29, 2025 06:13 | 3,874 | 77,558,886 | 46,334,000 | 4,029,000 | 2,416,640 | ||
| 22 | Dec 29, 2025 06:11 | 3,878 | 72,715,485 | 46,379,000 | 4,033,000 | 2,375,680 | ||
| 23 | Dec 29, 2025 06:12 | 3,913 | 76,870,952 | 45,884,000 | 4,987,000 | 2,473,984 | ||
| 24 | Dec 29, 2025 06:11 | 3,945 | 74,310,989 | 49,269,000 | 2,011,000 | 2,289,664 | ||
| 25 | Dec 29, 2025 06:13 | 3,978 | 77,199,066 | 50,696,000 | 1,013,000 | 2,424,832 | ||
| 26 | Dec 29, 2025 06:12 | 3,990 | 75,392,301 | 48,873,000 | 2,992,000 | 2,330,624 | ||
| 27 | Dec 29, 2025 06:11 | 4,017 | 81,920,266 | 48,208,000 | 4,017,000 | 2,416,640 | ||
| 28 | Dec 29, 2025 06:13 | 4,033 | 75,763,913 | 47,384,000 | 5,040,000 | 2,273,280 | ||
| 29 | Dec 29, 2025 06:13 | 4,066 | 83,539,231 | 48,866,000 | 3,989,000 | 2,473,984 | ||
| 30 | Dec 29, 2025 06:12 | 4,227 | 82,078,496 | 51,952,000 | 2,997,000 | 2,404,352 | ||
| 31 | Dec 29, 2025 06:13 | 4,257 | 84,680,765 | 51,314,000 | 4,024,000 | 2,326,528 | ||
| 32 | Dec 29, 2025 06:13 | 4,272 | 83,086,778 | 51,492,000 | 4,038,000 | 2,510,848 | ||
| 33 | Dec 29, 2025 06:12 | 4,390 | 82,705,634 | 53,064,000 | 4,004,000 | 2,273,280 |