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 14:30 | 3,191 | 68,010,359 | 39,458,000 | 2,023,000 | 2,523,136 | ||
| 2 | Dec 29, 2025 14:30 | 3,243 | 72,220,851 | 40,151,000 | 2,007,000 | 2,355,200 | ||
| 3 | Dec 29, 2025 14:30 | 3,283 | 68,926,136 | 40,641,000 | 2,032,000 | 2,502,656 | ||
| 4 | Dec 29, 2025 14:28 | 3,393 | 72,247,135 | 43,106,000 | 1,002,000 | 2,301,952 | ||
| 5 | Dec 29, 2025 14:26 | 3,451 | 69,156,283 | 42,867,000 | 1,993,000 | 2,490,368 | ||
| 6 | Dec 29, 2025 14:26 | 3,483 | 72,402,204 | 40,245,000 | 5,030,000 | 2,363,392 | ||
| 7 | Dec 29, 2025 14:30 | 3,490 | 73,979,640 | 40,325,000 | 5,040,000 | 2,433,024 | ||
| 8 | Dec 29, 2025 14:29 | 3,492 | 67,641,819 | 43,374,000 | 2,017,000 | 2,412,544 | ||
| 9 | Dec 29, 2025 14:25 | 3,529 | 76,753,817 | 39,892,000 | 5,983,000 | 2,293,760 | ||
| 10 | Dec 29, 2025 14:29 | 3,570 | 73,940,532 | 42,380,000 | 4,036,000 | 2,359,296 | ||
| 11 | Dec 29, 2025 14:30 | 3,608 | 80,760,085 | 42,913,000 | 3,991,000 | 2,269,184 | ||
| 12 | Dec 29, 2025 14:26 | 3,648 | 72,907,226 | 41,374,000 | 6,054,000 | 2,510,848 | ||
| 13 | Dec 29, 2025 14:29 | 3,683 | 77,376,799 | 44,893,000 | 2,992,000 | 2,465,792 | ||
| 14 | Dec 29, 2025 14:30 | 3,690 | 76,015,882 | 44,978,000 | 2,998,000 | 2,383,872 | ||
| 15 | Dec 29, 2025 14:30 | 3,713 | 73,755,154 | 45,257,000 | 3,017,000 | 2,306,048 | ||
| 16 | Dec 29, 2025 14:25 | 3,720 | 72,758,024 | 46,349,000 | 2,015,000 | 2,449,408 | ||
| 17 | Dec 29, 2025 14:28 | 3,759 | 80,942,592 | 47,872,000 | 997,000 | 2,330,624 | ||
| 18 | Dec 29, 2025 14:27 | 3,765 | 74,052,614 | 45,952,000 | 2,996,000 | 2,322,432 | ||
| 19 | Dec 29, 2025 14:30 | 3,779 | 79,481,433 | 47,124,000 | 2,005,000 | 2,359,296 | ||
| 20 | Dec 29, 2025 14:28 | 3,805 | 71,936,338 | 44,421,000 | 5,047,000 | 2,445,312 | ||
| 21 | Dec 29, 2025 14:27 | 3,817 | 75,852,289 | 46,579,000 | 3,037,000 | 2,396,160 | ||
| 22 | Dec 29, 2025 14:27 | 3,841 | 80,294,237 | 48,936,000 | 998,000 | 2,400,256 | ||
| 23 | Dec 29, 2025 14:26 | 3,880 | 78,524,329 | 47,413,000 | 3,026,000 | 2,306,048 | ||
| 24 | Dec 29, 2025 14:28 | 3,987 | 80,614,151 | 47,843,000 | 3,986,000 | 2,322,432 | ||
| 25 | Dec 29, 2025 14:26 | 4,003 | 75,631,215 | 48,032,000 | 4,002,000 | 2,445,312 | ||
| 26 | Dec 29, 2025 14:27 | 4,008 | 82,100,763 | 46,091,000 | 6,011,000 | 2,306,048 | ||
| 27 | Dec 29, 2025 14:26 | 4,086 | 83,651,173 | 51,111,000 | 2,004,000 | 2,273,280 | ||
| 28 | Dec 29, 2025 14:28 | 4,152 | 83,323,799 | 51,974,000 | 1,999,000 | 2,363,392 | ||
| 29 | Dec 29, 2025 14:25 | 4,165 | 76,832,206 | 52,136,000 | 2,005,000 | 2,351,104 | ||
| 30 | Dec 29, 2025 14:30 | 4,166 | 81,277,196 | 50,150,000 | 4,012,000 | 2,351,104 | ||
| 31 | Dec 29, 2025 14:27 | 4,184 | 77,415,401 | 52,373,000 | 2,014,000 | 2,285,568 | ||
| 32 | Dec 29, 2025 14:28 | 4,418 | 79,578,419 | 52,400,000 | 5,038,000 | 2,433,024 | ||
| 33 | Dec 29, 2025 14:27 | 4,515 | 85,201,087 | 55,662,000 | 3,036,000 | 2,306,048 |