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 19:01 | 3,066 | 65,806,088 | 36,871,000 | 2,989,000 | 2,318,336 | ||
| 2 | Dec 30, 2025 19:01 | 3,110 | 61,669,219 | 37,398,000 | 3,032,000 | 2,510,848 | ||
| 3 | Dec 30, 2025 19:11 | 3,114 | 63,352,432 | 39,469,000 | 1,012,000 | 2,400,256 | ||
| 4 | Dec 30, 2025 19:22 | 3,185 | 66,072,056 | 36,354,000 | 5,049,000 | 2,482,176 | ||
| 5 | Dec 30, 2025 19:12 | 3,186 | 70,973,896 | 37,377,000 | 4,040,000 | 2,465,792 | ||
| 6 | Dec 30, 2025 19:13 | 3,238 | 67,396,662 | 41,089,000 | 1,002,000 | 2,355,200 | ||
| 7 | Dec 30, 2025 19:11 | 3,373 | 73,915,206 | 41,851,000 | 1,992,000 | 2,387,968 | ||
| 8 | Dec 30, 2025 19:28 | 3,375 | 68,796,625 | 41,880,000 | 1,994,000 | 2,412,544 | ||
| 9 | Dec 30, 2025 19:16 | 3,388 | 68,628,491 | 42,042,000 | 2,002,000 | 2,387,968 | ||
| 10 | Dec 30, 2025 19:13 | 3,437 | 69,936,279 | 40,619,000 | 4,061,000 | 2,355,200 | ||
| 11 | Dec 30, 2025 19:12 | 3,459 | 71,633,353 | 41,968,000 | 2,997,000 | 2,408,448 | ||
| 12 | Dec 30, 2025 19:12 | 3,471 | 74,371,006 | 41,117,000 | 4,011,000 | 2,473,984 | ||
| 13 | Dec 30, 2025 19:11 | 3,490 | 73,115,136 | 44,358,000 | 1,008,000 | 2,301,952 | ||
| 14 | Dec 30, 2025 19:38 | 3,551 | 70,574,787 | 42,152,000 | 4,014,000 | 2,301,952 | ||
| 15 | Dec 30, 2025 19:11 | 3,575 | 73,147,001 | 41,429,000 | 5,052,000 | 2,482,176 | ||
| 16 | Dec 30, 2025 19:28 | 3,581 | 72,157,754 | 44,528,000 | 2,024,000 | 2,367,488 | ||
| 17 | Dec 30, 2025 19:01 | 3,591 | 73,073,379 | 44,655,000 | 2,029,000 | 2,437,120 | ||
| 18 | Dec 30, 2025 19:13 | 3,606 | 74,480,011 | 43,886,000 | 2,992,000 | 2,396,160 | ||
| 19 | Dec 30, 2025 19:22 | 3,683 | 75,906,499 | 45,883,000 | 1,994,000 | 2,342,912 | ||
| 20 | Dec 30, 2025 19:16 | 3,701 | 73,140,277 | 47,113,000 | 1,002,000 | 2,494,464 | ||
| 21 | Dec 30, 2025 19:38 | 3,723 | 79,769,689 | 43,362,000 | 5,042,000 | 2,404,352 | ||
| 22 | Dec 30, 2025 19:22 | 3,767 | 73,595,528 | 45,969,000 | 2,998,000 | 2,437,120 | ||
| 23 | Dec 30, 2025 19:38 | 3,778 | 77,840,109 | 45,105,000 | 4,009,000 | 2,310,144 | ||
| 24 | Dec 30, 2025 19:28 | 3,834 | 78,480,547 | 46,858,000 | 2,990,000 | 2,379,776 | ||
| 25 | Dec 30, 2025 19:11 | 3,849 | 78,194,614 | 46,036,000 | 4,003,000 | 2,473,984 | ||
| 26 | Dec 30, 2025 19:16 | 3,951 | 78,639,131 | 48,336,000 | 3,021,000 | 2,359,296 | ||
| 27 | Dec 30, 2025 19:11 | 3,964 | 73,801,019 | 48,498,000 | 3,031,000 | 2,342,912 |