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:27 | 3,031 | 68,022,290 | 37,382,000 | 2,020,000 | 2,453,504 | ||
| 2 | Dec 30, 2025 05:32 | 3,044 | 62,462,565 | 38,561,000 | 1,014,000 | 2,465,792 | ||
| 3 | Dec 30, 2025 05:27 | 3,170 | 69,584,513 | 38,190,000 | 3,015,000 | 2,334,720 | ||
| 4 | Dec 30, 2025 05:48 | 3,267 | 69,654,925 | 36,409,000 | 6,068,000 | 2,342,912 | ||
| 5 | Dec 30, 2025 05:27 | 3,268 | 63,376,214 | 38,436,000 | 4,045,000 | 2,396,160 | ||
| 6 | Dec 30, 2025 05:31 | 3,349 | 66,243,165 | 41,510,000 | 2,024,000 | 2,473,984 | ||
| 7 | Dec 30, 2025 05:31 | 3,355 | 72,917,595 | 37,531,000 | 6,086,000 | 2,375,680 | ||
| 8 | Dec 30, 2025 05:32 | 3,359 | 74,303,123 | 40,617,000 | 3,046,000 | 2,478,080 | ||
| 9 | Dec 30, 2025 05:27 | 3,409 | 70,891,178 | 41,292,000 | 3,021,000 | 2,355,200 | ||
| 10 | Dec 30, 2025 05:32 | 3,483 | 74,849,911 | 42,256,000 | 3,018,000 | 2,306,048 | ||
| 11 | Dec 30, 2025 05:32 | 3,508 | 74,933,270 | 44,593,000 | 1,013,000 | 2,379,776 | ||
| 12 | Dec 30, 2025 05:27 | 3,530 | 71,739,942 | 43,893,000 | 1,995,000 | 2,367,488 | ||
| 13 | Dec 30, 2025 05:48 | 3,566 | 71,861,543 | 42,333,000 | 4,031,000 | 2,342,912 | ||
| 14 | Dec 30, 2025 05:38 | 3,569 | 69,280,739 | 43,366,000 | 3,025,000 | 2,420,736 | ||
| 15 | Dec 30, 2025 05:38 | 3,580 | 75,885,968 | 42,490,000 | 4,046,000 | 2,260,992 | ||
| 16 | Dec 30, 2025 05:38 | 3,605 | 75,798,800 | 45,863,000 | 997,000 | 2,510,848 | ||
| 17 | Dec 30, 2025 05:31 | 3,648 | 75,180,491 | 43,392,000 | 4,036,000 | 2,314,240 | ||
| 18 | Dec 30, 2025 05:38 | 3,679 | 74,065,246 | 46,831,000 | 996,000 | 2,355,200 | ||
| 19 | Dec 30, 2025 05:48 | 3,687 | 79,203,008 | 43,938,000 | 3,994,000 | 2,473,984 | ||
| 20 | Dec 30, 2025 05:27 | 3,688 | 74,544,934 | 43,955,000 | 3,995,000 | 2,387,968 | ||
| 21 | Dec 30, 2025 05:27 | 3,703 | 83,459,200 | 46,137,000 | 2,005,000 | 2,428,928 | ||
| 22 | Dec 30, 2025 05:38 | 3,719 | 74,635,259 | 44,315,000 | 4,028,000 | 2,314,240 | ||
| 23 | Dec 30, 2025 05:32 | 3,730 | 72,632,711 | 45,458,000 | 3,030,000 | 2,449,408 | ||
| 24 | Dec 30, 2025 05:38 | 3,769 | 81,834,893 | 46,001,000 | 3,000,000 | 2,482,176 | ||
| 25 | Dec 30, 2025 05:32 | 3,836 | 76,627,792 | 46,873,000 | 2,991,000 | 2,297,856 | ||
| 26 | Dec 30, 2025 05:32 | 3,845 | 75,835,590 | 46,990,000 | 2,999,000 | 2,449,408 | ||
| 27 | Dec 30, 2025 05:27 | 3,952 | 72,986,037 | 49,366,000 | 2,014,000 | 2,256,896 | ||
| 28 | Dec 30, 2025 05:32 | 4,027 | 78,241,256 | 50,337,000 | 2,013,000 | 2,301,952 | ||
| 29 | Dec 30, 2025 05:32 | 4,042 | 78,912,563 | 48,508,000 | 4,042,000 | 2,473,984 | ||
| 30 | Dec 30, 2025 05:27 | 4,090 | 83,881,872 | 52,173,000 | 1,003,000 | 2,363,392 |