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 26, 2025 22:29 | 5,846 | 103,647,555 | 70,997,000 | 4,999,000 | 2,379,776 | ||
| 2 | Dec 26, 2025 22:29 | 5,974 | 107,719,727 | 73,628,000 | 4,034,000 | 2,510,848 | ||
| 3 | Dec 26, 2025 22:36 | 6,032 | 106,796,134 | 76,406,000 | 2,010,000 | 2,445,312 | ||
| 4 | Dec 26, 2025 22:28 | 6,064 | 108,585,336 | 76,833,000 | 1,995,000 | 2,306,048 | ||
| 5 | Dec 26, 2025 22:28 | 6,353 | 112,767,676 | 79,573,000 | 3,021,000 | 2,424,832 | ||
| 6 | Dec 26, 2025 22:29 | 6,359 | 112,274,551 | 79,647,000 | 3,024,000 | 2,506,752 | ||
| 7 | Dec 26, 2025 22:29 | 6,387 | 107,549,967 | 76,023,000 | 7,002,000 | 2,424,832 | ||
| 8 | Dec 26, 2025 22:28 | 6,437 | 113,678,559 | 79,648,000 | 4,032,000 | 2,392,064 | ||
| 9 | Dec 26, 2025 22:36 | 6,453 | 115,312,208 | 77,895,000 | 5,991,000 | 2,338,816 | ||
| 10 | Dec 26, 2025 22:29 | 6,514 | 113,692,492 | 81,654,000 | 3,024,000 | 2,412,544 | ||
| 11 | Dec 26, 2025 22:36 | 6,578 | 111,881,797 | 80,490,000 | 5,030,000 | 2,514,944 | ||
| 12 | Dec 26, 2025 22:36 | 6,591 | 110,920,022 | 84,675,000 | 1,008,000 | 2,375,680 | ||
| 13 | Dec 26, 2025 22:27 | 6,606 | 113,589,070 | 77,888,000 | 7,988,000 | 2,420,736 | ||
| 14 | Dec 26, 2025 22:27 | 6,689 | 112,788,684 | 76,965,000 | 9,995,000 | 2,297,856 | ||
| 15 | Dec 26, 2025 22:29 | 6,756 | 112,846,082 | 81,835,000 | 5,987,000 | 2,408,448 | ||
| 16 | Dec 26, 2025 22:29 | 6,764 | 111,583,231 | 82,935,000 | 4,996,000 | 2,428,928 | ||
| 17 | Dec 26, 2025 22:36 | 6,832 | 121,767,727 | 84,822,000 | 3,991,000 | 2,318,336 | ||
| 18 | Dec 26, 2025 22:28 | 6,854 | 126,705,739 | 86,097,000 | 3,003,000 | 2,433,024 | ||
| 19 | Dec 26, 2025 22:28 | 6,886 | 115,465,089 | 87,508,000 | 2,011,000 | 2,449,408 | ||
| 20 | Dec 26, 2025 22:36 | 6,938 | 112,615,566 | 83,180,000 | 7,015,000 | 2,502,656 | ||
| 21 | Dec 26, 2025 22:29 | 7,020 | 118,710,461 | 87,243,000 | 4,011,000 | 2,383,872 | ||
| 22 | Dec 26, 2025 22:29 | 7,030 | 118,085,085 | 87,368,000 | 4,016,000 | 2,506,752 | ||
| 23 | Dec 26, 2025 22:28 | 7,108 | 123,754,891 | 89,396,000 | 3,013,000 | 2,433,024 | ||
| 24 | Dec 26, 2025 22:29 | 7,190 | 124,025,468 | 91,463,000 | 2,010,000 | 2,322,432 | ||
| 25 | Dec 26, 2025 22:29 | 7,203 | 122,543,593 | 88,599,000 | 5,034,000 | 2,318,336 | ||
| 26 | Dec 26, 2025 22:27 | 7,255 | 121,608,261 | 89,302,000 | 5,016,000 | 2,441,216 | ||
| 27 | Dec 26, 2025 22:36 | 7,402 | 122,674,074 | 90,216,000 | 6,014,000 | 2,433,024 | ||
| 28 | Dec 26, 2025 22:36 | 7,590 | 125,518,090 | 90,610,000 | 8,054,000 | 2,441,216 | ||
| 29 | Dec 26, 2025 22:29 | 7,928 | 134,244,401 | 90,052,000 | 13,007,000 | 2,461,696 | ||
| 30 | Dec 26, 2025 22:36 | 8,222 | 141,703,676 | 101,894,000 | 4,994,000 | 2,420,736 |