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:30 | 4,989 | 90,151,092 | 59,874,000 | 4,989,000 | 2,527,232 | ||
| 2 | Dec 26, 2025 22:30 | 5,029 | 93,663,635 | 62,354,000 | 3,017,000 | 2,510,848 | ||
| 3 | Dec 26, 2025 22:26 | 5,102 | 98,062,397 | 63,308,000 | 3,014,000 | 2,482,176 | ||
| 4 | Dec 26, 2025 22:30 | 5,250 | 94,056,836 | 64,241,000 | 4,015,000 | 2,449,408 | ||
| 5 | Dec 26, 2025 22:30 | 5,373 | 98,893,063 | 65,803,000 | 4,049,000 | 2,490,368 | ||
| 6 | Dec 26, 2025 22:26 | 5,454 | 94,362,267 | 68,910,000 | 1,997,000 | 2,318,336 | ||
| 7 | Dec 26, 2025 22:30 | 5,489 | 96,308,988 | 70,354,000 | 1,005,000 | 2,281,472 | ||
| 8 | Dec 26, 2025 22:26 | 5,496 | 99,474,719 | 69,440,000 | 2,012,000 | 2,486,272 | ||
| 9 | Dec 26, 2025 22:30 | 5,762 | 102,455,562 | 70,912,000 | 3,995,000 | 2,498,560 | ||
| 10 | Dec 26, 2025 22:30 | 5,792 | 101,848,392 | 70,282,000 | 5,020,000 | 2,387,968 | ||
| 11 | Dec 26, 2025 22:26 | 5,841 | 102,885,102 | 70,939,000 | 4,995,000 | 2,334,720 | ||
| 12 | Dec 26, 2025 22:30 | 5,850 | 105,318,642 | 70,049,000 | 6,004,000 | 2,510,848 | ||
| 13 | Dec 26, 2025 22:30 | 5,879 | 102,987,896 | 73,407,000 | 3,016,000 | 2,359,296 | ||
| 14 | Dec 26, 2025 22:30 | 5,907 | 104,659,643 | 70,802,000 | 5,983,000 | 2,404,352 | ||
| 15 | Dec 26, 2025 22:30 | 5,912 | 103,999,519 | 72,859,000 | 3,992,000 | 2,412,544 | ||
| 16 | Dec 26, 2025 22:30 | 5,931 | 105,640,363 | 73,092,000 | 4,005,000 | 2,301,952 | ||
| 17 | Dec 26, 2025 22:30 | 6,001 | 98,473,920 | 75,018,000 | 3,000,000 | 2,387,968 | ||
| 18 | Dec 26, 2025 22:26 | 6,064 | 110,714,261 | 75,838,000 | 2,993,000 | 2,412,544 | ||
| 19 | Dec 26, 2025 22:30 | 6,090 | 107,980,223 | 76,160,000 | 3,006,000 | 2,473,984 | ||
| 20 | Dec 26, 2025 22:33 | 6,108 | 106,675,155 | 75,389,000 | 4,020,000 | 2,461,696 | ||
| 21 | Dec 26, 2025 22:33 | 6,124 | 108,137,762 | 72,553,000 | 7,053,000 | 2,420,736 | ||
| 22 | Dec 26, 2025 22:30 | 6,140 | 108,016,155 | 73,838,000 | 5,986,000 | 2,289,664 | ||
| 23 | Dec 26, 2025 22:30 | 6,142 | 110,865,729 | 76,815,000 | 3,032,000 | 2,408,448 | ||
| 24 | Dec 26, 2025 22:26 | 6,178 | 106,856,136 | 75,297,000 | 5,019,000 | 2,347,008 | ||
| 25 | Dec 26, 2025 22:30 | 6,219 | 107,803,845 | 76,850,000 | 3,992,000 | 2,465,792 | ||
| 26 | Dec 26, 2025 22:30 | 6,240 | 104,473,617 | 78,113,000 | 3,004,000 | 2,420,736 | ||
| 27 | Dec 26, 2025 22:30 | 6,259 | 107,590,107 | 76,342,000 | 5,022,000 | 2,461,696 | ||
| 28 | Dec 26, 2025 22:32 | 6,273 | 109,353,208 | 78,532,000 | 3,020,000 | 2,490,368 | ||
| 29 | Dec 26, 2025 22:30 | 6,321 | 107,217,633 | 77,166,000 | 5,010,000 | 2,318,336 | ||
| 30 | Dec 26, 2025 22:26 | 6,352 | 110,037,240 | 79,555,000 | 3,021,000 | 2,281,472 | ||
| 31 | Dec 26, 2025 22:26 | 6,375 | 114,899,099 | 78,886,000 | 3,994,000 | 2,469,888 | ||
| 32 | Dec 26, 2025 22:30 | 6,450 | 104,267,213 | 77,860,000 | 5,989,000 | 2,400,256 | ||
| 33 | Dec 26, 2025 22:33 | 6,507 | 112,809,534 | 80,563,000 | 4,028,000 | 2,510,848 | ||
| 34 | Dec 26, 2025 22:32 | 6,563 | 113,643,794 | 81,302,000 | 4,014,000 | 2,424,832 | ||
| 35 | Dec 26, 2025 22:30 | 6,589 | 117,987,062 | 79,609,000 | 6,046,000 | 2,396,160 | ||
| 36 | Dec 26, 2025 22:26 | 6,602 | 111,742,975 | 79,833,000 | 5,987,000 | 2,461,696 | ||
| 37 | Dec 26, 2025 22:32 | 6,836 | 120,463,984 | 84,829,000 | 4,039,000 | 2,527,232 | ||
| 38 | Dec 26, 2025 22:30 | 7,450 | 124,897,673 | 93,858,000 | 2,995,000 | 2,277,376 | ||
| 39 | Dec 26, 2025 22:30 | 7,564 | 123,349,348 | 97,326,000 | 1,003,000 | 2,347,008 |