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 | Oct 13, 2025 00:37 | 12,700 | 188,391,602 | 160,096,000 | 5,003,000 | 2,494,464 | ||
| 2 | Oct 13, 2025 00:37 | 12,746 | 191,024,326 | 158,705,000 | 6,987,000 | 2,498,560 | ||
| 3 | Oct 13, 2025 00:36 | 13,084 | 193,336,573 | 166,093,000 | 4,002,000 | 2,490,368 | ||
| 4 | Oct 13, 2025 15:52 | 13,835 | 205,834,773 | 175,858,000 | 3,996,000 | 2,494,464 | ||
| 5 | Oct 13, 2025 00:34 | 13,940 | 209,112,151 | 177,215,000 | 4,004,000 | 2,457,600 | ||
| 6 | Oct 13, 2025 00:37 | 14,072 | 212,355,677 | 177,932,000 | 4,998,000 | 2,306,048 | ||
| 7 | Oct 13, 2025 16:24 | 14,165 | 216,210,200 | 181,145,000 | 3,002,000 | 2,437,120 | ||
| 8 | Oct 13, 2025 00:37 | 14,200 | 208,570,820 | 179,590,000 | 5,016,000 | 2,433,024 | ||
| 9 | Oct 13, 2025 00:34 | 14,409 | 212,179,832 | 185,317,000 | 2,003,000 | 2,420,736 | ||
| 10 | Oct 13, 2025 00:34 | 14,569 | 216,726,425 | 185,392,000 | 4,008,000 | 2,297,856 | ||
| 11 | Oct 13, 2025 00:33 | 14,574 | 214,409,946 | 185,451,000 | 4,009,000 | 2,318,336 | ||
| 12 | Oct 13, 2025 00:37 | 14,627 | 214,631,958 | 184,146,000 | 6,004,000 | 2,387,968 | ||
| 13 | Oct 13, 2025 15:52 | 14,646 | 213,672,822 | 185,390,000 | 5,010,000 | 2,453,504 | ||
| 14 | Oct 13, 2025 16:24 | 14,746 | 216,189,654 | 186,706,000 | 4,992,000 | 2,416,640 | ||
| 15 | Oct 13, 2025 00:37 | 15,059 | 225,268,207 | 192,774,000 | 2,996,000 | 2,494,464 | ||
| 16 | Oct 13, 2025 00:33 | 15,094 | 223,894,671 | 190,211,000 | 6,006,000 | 2,506,752 | ||
| 17 | Oct 13, 2025 00:36 | 15,110 | 221,923,022 | 189,415,000 | 7,015,000 | 2,310,144 | ||
| 18 | Oct 13, 2025 00:34 | 15,170 | 224,036,271 | 193,208,000 | 4,004,000 | 2,457,600 | ||
| 19 | Oct 13, 2025 15:52 | 15,185 | 221,831,520 | 192,399,000 | 5,010,000 | 2,461,696 | ||
| 20 | Oct 13, 2025 15:51 | 15,189 | 224,707,791 | 197,451,000 | 0 | 2,314,240 | ||
| 21 | Oct 13, 2025 00:33 | 15,362 | 224,726,902 | 192,722,000 | 6,989,000 | 2,449,408 | ||
| 22 | Oct 13, 2025 16:24 | 15,384 | 229,609,461 | 194,996,000 | 4,999,000 | 2,482,176 | ||
| 23 | Oct 13, 2025 00:33 | 15,557 | 226,536,103 | 198,235,000 | 4,004,000 | 2,408,448 | ||
| 24 | Oct 13, 2025 15:52 | 15,712 | 231,085,676 | 198,255,000 | 6,007,000 | 2,482,176 | ||
| 25 | Oct 13, 2025 00:34 | 15,731 | 231,756,868 | 200,489,000 | 4,009,000 | 2,420,736 | ||
| 26 | Oct 13, 2025 15:51 | 15,831 | 231,469,673 | 200,812,000 | 4,995,000 | 2,379,776 | ||
| 27 | Oct 13, 2025 00:34 | 15,833 | 230,536,490 | 200,839,000 | 4,996,000 | 2,457,600 | ||
| 28 | Oct 13, 2025 00:37 | 15,840 | 232,648,449 | 201,920,000 | 3,998,000 | 2,494,464 | ||
| 29 | Oct 13, 2025 16:24 | 15,964 | 238,482,591 | 199,517,000 | 8,020,000 | 2,379,776 | ||
| 30 | Oct 13, 2025 00:34 | 16,151 | 237,526,474 | 204,968,000 | 4,999,000 | 2,297,856 | ||
| 31 | Oct 13, 2025 15:51 | 16,167 | 238,198,354 | 207,168,000 | 3,002,000 | 2,433,024 | ||
| 32 | Oct 13, 2025 00:36 | 16,253 | 238,810,504 | 206,277,000 | 5,006,000 | 2,433,024 | ||
| 33 | Oct 13, 2025 15:52 | 16,395 | 239,634,793 | 206,128,000 | 7,004,000 | 2,363,392 | ||
| 34 | Oct 13, 2025 00:33 | 16,462 | 240,397,270 | 208,009,000 | 6,000,000 | 2,519,040 | ||
| 35 | Oct 13, 2025 16:24 | 16,486 | 239,904,408 | 211,320,000 | 3,004,000 | 2,473,984 | ||
| 36 | Oct 13, 2025 00:33 | 16,530 | 241,509,132 | 205,899,000 | 8,995,000 | 2,383,872 | ||
| 37 | Oct 13, 2025 00:33 | 16,617 | 247,286,628 | 212,021,000 | 4,000,000 | 2,469,888 | ||
| 38 | Oct 13, 2025 16:24 | 16,749 | 248,080,677 | 213,740,000 | 3,995,000 | 2,289,664 | ||
| 39 | Oct 13, 2025 16:24 | 17,028 | 247,566,149 | 218,361,000 | 3,004,000 | 2,416,640 | ||
| 40 | Oct 13, 2025 00:34 | 17,043 | 247,035,743 | 216,571,000 | 4,990,000 | 2,310,144 | ||
| 41 | Oct 13, 2025 16:24 | 17,061 | 246,014,109 | 215,804,000 | 5,994,000 | 2,400,256 | ||
| 42 | Oct 13, 2025 00:37 | 17,177 | 253,286,383 | 219,297,000 | 4,005,000 | 2,347,008 | ||
| 43 | Oct 13, 2025 16:24 | 17,191 | 248,724,936 | 219,480,000 | 4,008,000 | 2,445,312 | ||
| 44 | Oct 13, 2025 00:34 | 17,201 | 250,803,595 | 218,627,000 | 4,991,000 | 2,433,024 | ||
| 45 | Oct 13, 2025 15:52 | 17,702 | 259,394,474 | 224,125,000 | 6,003,000 | 2,396,160 | ||
| 46 | Oct 13, 2025 00:33 | 17,790 | 257,849,933 | 227,261,000 | 4,004,000 | 2,457,600 | ||
| 47 | Oct 13, 2025 00:33 | 18,139 | 264,632,426 | 232,813,000 | 2,997,000 | 2,379,776 | ||
| 48 | Oct 13, 2025 00:37 | 18,972 | 272,236,363 | 241,639,000 | 4,992,000 | 2,387,968 |