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 03:26 | 4,393 | 83,774,436 | 52,099,000 | 5,009,000 | 2,387,968 | ||
| 2 | Dec 29, 2025 00:35 | 4,792 | 90,183,453 | 54,254,000 | 8,037,000 | 2,347,008 | ||
| 3 | Dec 29, 2025 00:34 | 4,864 | 93,199,728 | 58,216,000 | 5,018,000 | 2,461,696 | ||
| 4 | Dec 29, 2025 00:33 | 4,885 | 89,647,107 | 59,476,000 | 4,032,000 | 2,519,040 | ||
| 5 | Dec 29, 2025 03:26 | 4,889 | 92,175,337 | 56,500,000 | 7,062,000 | 2,416,640 | ||
| 6 | Dec 29, 2025 00:36 | 4,997 | 90,285,584 | 60,969,000 | 3,998,000 | 2,428,928 | ||
| 7 | Dec 29, 2025 00:37 | 5,023 | 94,367,034 | 61,275,000 | 4,018,000 | 2,342,912 | ||
| 8 | Dec 29, 2025 00:37 | 5,103 | 93,559,801 | 63,324,000 | 3,015,000 | 2,404,352 | ||
| 9 | Dec 29, 2025 00:35 | 5,109 | 99,121,456 | 62,391,000 | 4,025,000 | 2,514,944 | ||
| 10 | Dec 29, 2025 00:33 | 5,190 | 94,086,076 | 63,438,000 | 4,027,000 | 2,412,544 | ||
| 11 | Dec 29, 2025 03:26 | 5,220 | 97,225,528 | 64,869,000 | 2,993,000 | 2,310,144 | ||
| 12 | Dec 29, 2025 00:37 | 5,243 | 100,024,442 | 65,147,000 | 3,006,000 | 2,273,280 | ||
| 13 | Dec 29, 2025 00:33 | 5,248 | 87,347,343 | 67,222,000 | 1,003,000 | 2,461,696 | ||
| 14 | Dec 29, 2025 00:33 | 5,295 | 96,155,600 | 65,838,000 | 2,992,000 | 2,392,064 | ||
| 15 | Dec 29, 2025 00:33 | 5,297 | 102,104,452 | 67,858,000 | 997,000 | 2,502,656 | ||
| 16 | Dec 29, 2025 00:35 | 5,306 | 93,430,170 | 61,982,000 | 6,998,000 | 2,469,888 | ||
| 17 | Dec 29, 2025 00:34 | 5,310 | 101,138,377 | 63,026,000 | 6,002,000 | 2,392,064 | ||
| 18 | Dec 29, 2025 00:35 | 5,314 | 90,315,454 | 66,084,000 | 3,003,000 | 2,277,376 | ||
| 19 | Dec 29, 2025 00:36 | 5,334 | 97,075,519 | 63,309,000 | 6,029,000 | 2,347,008 | ||
| 20 | Dec 29, 2025 00:35 | 5,381 | 99,330,853 | 66,960,000 | 2,998,000 | 2,449,408 | ||
| 21 | Dec 29, 2025 00:36 | 5,548 | 100,749,369 | 65,118,000 | 7,012,000 | 2,310,144 | ||
| 22 | Dec 29, 2025 00:36 | 5,574 | 98,772,516 | 70,444,000 | 2,012,000 | 2,510,848 | ||
| 23 | Dec 29, 2025 00:36 | 5,791 | 97,858,175 | 70,265,000 | 5,018,000 | 2,486,272 | ||
| 24 | Dec 29, 2025 00:33 | 6,011 | 102,237,707 | 74,133,000 | 4,007,000 | 2,473,984 | ||
| 25 | Dec 29, 2025 00:35 | 6,029 | 98,362,349 | 74,358,000 | 4,019,000 | 2,498,560 | ||
| 26 | Dec 29, 2025 00:36 | 6,329 | 108,369,678 | 80,277,000 | 2,006,000 | 2,367,488 | ||
| 27 | Dec 29, 2025 00:34 | 6,583 | 118,592,027 | 80,544,000 | 5,034,000 | 2,519,040 |