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 27, 2025 15:48 | 4,787 | 88,505,636 | 61,224,000 | 1,003,000 | 2,269,184 | ||
| 2 | Dec 27, 2025 15:49 | 5,026 | 89,430,788 | 61,322,000 | 4,021,000 | 2,363,392 | ||
| 3 | Dec 27, 2025 15:48 | 5,093 | 92,236,892 | 61,193,000 | 5,015,000 | 2,502,656 | ||
| 4 | Dec 27, 2025 15:48 | 5,115 | 99,027,357 | 62,464,000 | 4,029,000 | 2,334,720 | ||
| 5 | Dec 27, 2025 15:49 | 5,131 | 98,542,126 | 61,656,000 | 5,053,000 | 2,519,040 | ||
| 6 | Dec 27, 2025 15:48 | 5,280 | 92,016,070 | 64,598,000 | 4,037,000 | 2,318,336 | ||
| 7 | Dec 27, 2025 15:49 | 5,315 | 92,979,232 | 65,095,000 | 4,005,000 | 2,498,560 | ||
| 8 | Dec 27, 2025 15:48 | 5,317 | 98,824,603 | 64,114,000 | 5,008,000 | 2,478,080 | ||
| 9 | Dec 27, 2025 15:49 | 5,354 | 97,235,294 | 66,577,000 | 3,026,000 | 2,473,984 | ||
| 10 | Dec 27, 2025 15:49 | 5,402 | 100,068,479 | 65,206,000 | 5,015,000 | 2,273,280 | ||
| 11 | Dec 27, 2025 15:49 | 5,437 | 103,433,900 | 65,637,000 | 5,049,000 | 2,494,464 | ||
| 12 | Dec 27, 2025 15:49 | 5,473 | 101,134,371 | 67,147,000 | 4,008,000 | 2,449,408 | ||
| 13 | Dec 27, 2025 15:49 | 5,494 | 94,533,165 | 69,412,000 | 2,011,000 | 2,473,984 | ||
| 14 | Dec 27, 2025 15:49 | 5,528 | 105,436,294 | 66,871,000 | 4,990,000 | 2,449,408 | ||
| 15 | Dec 27, 2025 15:50 | 5,570 | 97,707,802 | 68,386,000 | 4,022,000 | 2,420,736 | ||
| 16 | Dec 27, 2025 15:49 | 5,603 | 100,782,910 | 67,850,000 | 4,989,000 | 2,428,928 | ||
| 17 | Dec 27, 2025 15:20 | 5,605 | 102,002,204 | 65,883,000 | 6,987,000 | 2,383,872 | ||
| 18 | Dec 27, 2025 15:20 | 5,622 | 96,324,987 | 71,087,000 | 2,002,000 | 2,478,080 | ||
| 19 | Dec 27, 2025 15:48 | 5,797 | 108,053,454 | 72,344,000 | 3,014,000 | 2,519,040 | ||
| 20 | Dec 27, 2025 15:49 | 5,797 | 105,204,681 | 72,342,000 | 3,014,000 | 2,297,856 | ||
| 21 | Dec 27, 2025 15:50 | 5,841 | 98,638,106 | 72,938,000 | 2,997,000 | 2,469,888 | ||
| 22 | Dec 27, 2025 15:49 | 5,872 | 107,981,759 | 71,317,000 | 5,022,000 | 2,519,040 | ||
| 23 | Dec 27, 2025 15:19 | 5,879 | 105,116,361 | 74,417,000 | 2,011,000 | 2,289,664 | ||
| 24 | Dec 27, 2025 15:20 | 5,940 | 105,106,402 | 73,212,000 | 4,011,000 | 2,273,280 | ||
| 25 | Dec 27, 2025 15:50 | 5,964 | 101,465,799 | 72,499,000 | 5,034,000 | 2,359,296 | ||
| 26 | Dec 27, 2025 15:19 | 5,978 | 107,980,165 | 75,690,000 | 2,018,000 | 2,342,912 | ||
| 27 | Dec 27, 2025 15:48 | 5,980 | 106,381,342 | 73,701,000 | 4,038,000 | 2,445,312 | ||
| 28 | Dec 27, 2025 15:48 | 6,087 | 107,047,247 | 74,125,000 | 5,008,000 | 2,465,792 | ||
| 29 | Dec 27, 2025 15:19 | 6,373 | 111,371,642 | 80,829,000 | 2,020,000 | 2,461,696 | ||
| 30 | Dec 27, 2025 15:49 | 6,486 | 113,014,071 | 79,294,000 | 5,018,000 | 2,506,752 | ||
| 31 | Dec 27, 2025 15:48 | 6,542 | 118,411,347 | 82,043,000 | 3,001,000 | 2,473,984 | ||
| 32 | Dec 27, 2025 15:49 | 6,627 | 115,287,968 | 80,142,000 | 6,010,000 | 2,265,088 | ||
| 33 | Dec 27, 2025 15:49 | 6,744 | 116,571,710 | 83,636,000 | 4,030,000 | 2,269,184 |