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:08 | 3,256 | 66,752,626 | 37,285,000 | 5,038,000 | 2,424,832 | ||
| 2 | Dec 29, 2025 06:06 | 3,332 | 71,796,269 | 40,296,000 | 3,022,000 | 2,379,776 | ||
| 3 | Dec 29, 2025 06:09 | 3,479 | 70,626,912 | 41,205,000 | 4,020,000 | 2,289,664 | ||
| 4 | Dec 29, 2025 06:07 | 3,502 | 72,361,567 | 43,498,000 | 2,023,000 | 2,420,736 | ||
| 5 | Dec 29, 2025 06:05 | 3,547 | 73,767,729 | 40,092,000 | 6,013,000 | 2,506,752 | ||
| 6 | Dec 29, 2025 06:09 | 3,563 | 66,361,293 | 43,297,000 | 3,020,000 | 2,269,184 | ||
| 7 | Dec 29, 2025 06:07 | 3,620 | 81,582,164 | 43,052,000 | 4,004,000 | 2,428,928 | ||
| 8 | Dec 29, 2025 06:05 | 3,627 | 76,127,302 | 44,142,000 | 3,009,000 | 2,293,760 | ||
| 9 | Dec 29, 2025 06:06 | 3,636 | 75,649,856 | 44,249,000 | 3,017,000 | 2,383,872 | ||
| 10 | Dec 29, 2025 06:09 | 3,656 | 70,012,215 | 45,503,000 | 2,022,000 | 2,424,832 | ||
| 11 | Dec 29, 2025 06:09 | 3,702 | 79,879,407 | 47,126,000 | 1,002,000 | 2,363,392 | ||
| 12 | Dec 29, 2025 06:09 | 3,789 | 76,916,670 | 45,240,000 | 4,021,000 | 2,265,088 | ||
| 13 | Dec 29, 2025 06:08 | 3,795 | 74,805,979 | 45,303,000 | 4,027,000 | 2,347,008 | ||
| 14 | Dec 29, 2025 05:48 | 3,851 | 79,663,296 | 46,056,000 | 4,004,000 | 2,375,680 | ||
| 15 | Dec 29, 2025 06:05 | 3,870 | 78,894,112 | 49,302,000 | 1,006,000 | 2,412,544 | ||
| 16 | Dec 29, 2025 06:06 | 3,893 | 81,055,333 | 47,570,000 | 3,036,000 | 2,473,984 | ||
| 17 | Dec 29, 2025 05:48 | 3,898 | 76,864,898 | 46,624,000 | 4,054,000 | 2,330,624 | ||
| 18 | Dec 29, 2025 05:48 | 3,973 | 73,475,579 | 51,654,000 | 0 | 2,306,048 | ||
| 19 | Dec 29, 2025 05:48 | 3,974 | 77,371,617 | 48,629,000 | 3,039,000 | 2,523,136 | ||
| 20 | Dec 29, 2025 06:06 | 3,997 | 77,454,745 | 46,967,000 | 4,996,000 | 2,289,664 | ||
| 21 | Dec 29, 2025 06:09 | 4,013 | 77,042,263 | 51,171,000 | 1,003,000 | 2,293,760 | ||
| 22 | Dec 29, 2025 06:05 | 4,019 | 83,252,772 | 50,237,000 | 2,009,000 | 2,461,696 | ||
| 23 | Dec 29, 2025 05:48 | 4,023 | 79,416,402 | 48,282,000 | 4,023,000 | 2,494,464 | ||
| 24 | Dec 29, 2025 06:05 | 4,055 | 77,488,288 | 50,690,000 | 2,027,000 | 2,265,088 | ||
| 25 | Dec 29, 2025 06:08 | 4,057 | 86,547,209 | 51,725,000 | 1,014,000 | 2,457,600 | ||
| 26 | Dec 29, 2025 06:07 | 4,082 | 81,310,646 | 51,065,000 | 2,002,000 | 2,408,448 | ||
| 27 | Dec 29, 2025 06:05 | 4,144 | 87,258,669 | 51,874,000 | 1,995,000 | 2,502,656 | ||
| 28 | Dec 29, 2025 06:06 | 4,180 | 74,291,879 | 50,311,000 | 4,024,000 | 2,457,600 | ||
| 29 | Dec 29, 2025 05:47 | 4,228 | 86,053,902 | 51,964,000 | 2,997,000 | 2,330,624 | ||
| 30 | Dec 29, 2025 06:06 | 4,229 | 83,059,254 | 50,983,000 | 3,998,000 | 2,404,352 | ||
| 31 | Dec 29, 2025 06:08 | 4,239 | 81,263,612 | 51,104,000 | 4,008,000 | 2,371,584 | ||
| 32 | Dec 29, 2025 05:47 | 4,258 | 79,862,523 | 51,333,000 | 4,026,000 | 2,326,528 | ||
| 33 | Dec 29, 2025 06:08 | 4,287 | 80,120,631 | 53,705,000 | 2,026,000 | 2,322,432 | ||
| 34 | Dec 29, 2025 05:47 | 4,375 | 88,013,547 | 53,886,000 | 2,993,000 | 2,498,560 | ||
| 35 | Dec 29, 2025 05:48 | 4,417 | 78,859,764 | 55,411,000 | 2,014,000 | 2,318,336 | ||
| 36 | Dec 29, 2025 06:08 | 4,507 | 83,944,687 | 55,555,000 | 3,030,000 | 2,502,656 |