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 | Mar 20, 2026 05:22 | 2,996 | 62,256,095 | 32,956,000 | 5,992,000 | 2,408,448 | ||
| 2 | Mar 20, 2026 05:22 | 3,109 | 66,489,891 | 35,360,000 | 5,051,000 | 2,367,488 | ||
| 3 | Mar 20, 2026 05:22 | 3,133 | 70,878,661 | 36,662,000 | 4,073,000 | 2,359,296 | ||
| 4 | Mar 20, 2026 05:11 | 3,166 | 67,495,031 | 38,147,000 | 3,011,000 | 2,453,504 | ||
| 5 | Mar 20, 2026 05:11 | 3,201 | 71,289,876 | 37,553,000 | 4,059,000 | 2,416,640 | ||
| 6 | Mar 20, 2026 05:11 | 3,260 | 66,847,537 | 38,349,000 | 4,036,000 | 2,441,216 | ||
| 7 | Mar 20, 2026 05:22 | 3,321 | 69,330,273 | 38,149,000 | 5,019,000 | 2,387,968 | ||
| 8 | Mar 20, 2026 05:22 | 3,335 | 69,565,032 | 40,335,000 | 3,025,000 | 2,379,776 | ||
| 9 | Mar 20, 2026 05:22 | 3,348 | 67,145,816 | 38,461,000 | 5,060,000 | 2,301,952 | ||
| 10 | Mar 20, 2026 05:22 | 3,380 | 67,438,779 | 38,942,000 | 4,992,000 | 2,531,328 | ||
| 11 | Mar 20, 2026 05:22 | 3,381 | 69,074,041 | 40,882,000 | 3,066,000 | 2,441,216 | ||
| 12 | Mar 20, 2026 05:11 | 3,403 | 66,299,962 | 38,208,000 | 6,032,000 | 2,297,856 | ||
| 13 | Mar 20, 2026 05:11 | 3,407 | 72,094,949 | 39,257,000 | 5,033,000 | 2,314,240 | ||
| 14 | Mar 20, 2026 05:22 | 3,439 | 74,045,570 | 40,640,000 | 4,064,000 | 2,342,912 | ||
| 15 | Mar 20, 2026 05:22 | 3,455 | 72,065,615 | 39,924,000 | 4,990,000 | 2,371,584 | ||
| 16 | Mar 20, 2026 05:22 | 3,460 | 66,933,871 | 42,986,000 | 1,999,000 | 2,318,336 | ||
| 17 | Mar 20, 2026 05:22 | 3,461 | 69,204,364 | 39,991,000 | 4,998,000 | 2,330,624 | ||
| 18 | Mar 20, 2026 05:22 | 3,466 | 74,018,124 | 41,049,000 | 4,004,000 | 2,351,104 | ||
| 19 | Mar 20, 2026 05:22 | 3,500 | 83,088,125 | 39,567,000 | 5,935,000 | 2,318,336 | ||
| 20 | Mar 20, 2026 05:22 | 3,526 | 70,614,946 | 40,853,000 | 4,982,000 | 2,498,560 | ||
| 21 | Mar 20, 2026 05:11 | 3,533 | 75,608,551 | 42,932,000 | 2,995,000 | 2,310,144 | ||
| 22 | Mar 20, 2026 05:22 | 3,566 | 72,631,549 | 41,324,000 | 5,039,000 | 2,437,120 | ||
| 23 | Mar 20, 2026 05:11 | 3,570 | 72,066,017 | 42,372,000 | 4,035,000 | 2,379,776 | ||
| 24 | Mar 20, 2026 05:22 | 3,812 | 73,976,012 | 46,520,000 | 3,033,000 | 2,453,504 | ||
| 25 | Mar 20, 2026 05:11 | 3,916 | 76,548,292 | 46,910,000 | 3,992,000 | 2,301,952 | ||
| 26 | Mar 20, 2026 05:11 | 3,931 | 79,454,534 | 45,095,000 | 6,012,000 | 2,379,776 | ||
| 27 | Mar 20, 2026 05:22 | 3,933 | 80,172,666 | 47,117,000 | 4,009,000 | 2,420,736 |