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 25, 2025 16:28 | 11,157 | 171,099,000 | 141,041,000 | 4,001,000 | 2,482,176 | ||
| 2 | Dec 25, 2025 16:30 | 11,933 | 179,709,845 | 148,122,000 | 7,005,000 | 2,396,160 | ||
| 3 | Dec 25, 2025 16:29 | 12,123 | 189,144,774 | 153,578,000 | 4,015,000 | 2,277,376 | ||
| 4 | Dec 25, 2025 16:28 | 12,276 | 189,284,632 | 154,564,000 | 5,018,000 | 2,297,856 | ||
| 5 | Dec 25, 2025 16:28 | 12,277 | 193,225,690 | 153,585,000 | 6,022,000 | 2,502,656 | ||
| 6 | Dec 25, 2025 16:30 | 12,433 | 191,143,038 | 157,638,000 | 3,990,000 | 2,269,184 | ||
| 7 | Dec 25, 2025 16:29 | 12,453 | 188,411,640 | 157,886,000 | 3,997,000 | 2,494,464 | ||
| 8 | Dec 25, 2025 16:30 | 12,496 | 189,332,603 | 162,444,000 | 0 | 2,355,200 | ||
| 9 | Dec 25, 2025 16:30 | 12,738 | 193,544,858 | 164,594,000 | 1,003,000 | 2,277,376 | ||
| 10 | Dec 25, 2025 16:29 | 12,782 | 196,188,320 | 164,170,000 | 2,002,000 | 2,510,848 | ||
| 11 | Dec 25, 2025 16:30 | 12,913 | 191,614,447 | 164,876,000 | 2,997,000 | 2,490,368 | ||
| 12 | Dec 25, 2025 16:28 | 13,081 | 198,757,638 | 166,047,000 | 4,001,000 | 2,371,584 | ||
| 13 | Dec 25, 2025 16:29 | 13,409 | 199,895,307 | 173,321,000 | 1,001,000 | 2,355,200 | ||
| 14 | Dec 25, 2025 16:29 | 13,444 | 201,330,009 | 171,777,000 | 2,996,000 | 2,326,528 | ||
| 15 | Dec 25, 2025 16:30 | 13,482 | 204,532,536 | 172,258,000 | 3,004,000 | 2,523,136 | ||
| 16 | Dec 25, 2025 16:29 | 13,587 | 206,206,951 | 175,625,000 | 1,003,000 | 2,457,600 | ||
| 17 | Dec 25, 2025 16:30 | 13,612 | 205,461,982 | 173,954,000 | 2,999,000 | 2,514,944 | ||
| 18 | Dec 25, 2025 16:28 | 14,102 | 209,839,788 | 182,321,000 | 1,001,000 | 2,293,760 | ||
| 19 | Dec 25, 2025 16:30 | 14,521 | 216,509,014 | 184,774,000 | 3,995,000 | 2,297,856 | ||
| 20 | Dec 25, 2025 16:29 | 14,646 | 219,566,857 | 184,380,000 | 6,012,000 | 2,281,472 | ||
| 21 | Dec 25, 2025 16:29 | 14,799 | 221,165,757 | 190,383,000 | 2,004,000 | 2,482,176 | ||
| 22 | Dec 25, 2025 16:28 | 14,801 | 227,454,370 | 191,409,000 | 1,002,000 | 2,306,048 | ||
| 23 | Dec 25, 2025 16:30 | 14,963 | 228,279,618 | 191,517,000 | 3,008,000 | 2,486,272 | ||
| 24 | Dec 25, 2025 16:29 | 15,136 | 224,034,081 | 190,774,000 | 5,992,000 | 2,293,760 | ||
| 25 | Dec 25, 2025 16:29 | 15,256 | 223,915,161 | 195,323,000 | 3,004,000 | 2,301,952 | ||
| 26 | Dec 25, 2025 16:29 | 15,374 | 227,219,400 | 192,869,000 | 6,995,000 | 2,301,952 | ||
| 27 | Dec 25, 2025 16:28 | 15,615 | 229,496,423 | 201,001,000 | 2,000,000 | 2,306,048 | ||
| 28 | Dec 25, 2025 16:28 | 16,006 | 237,390,137 | 206,079,000 | 2,000,000 | 2,453,504 | ||
| 29 | Dec 25, 2025 16:29 | 16,318 | 241,620,739 | 207,127,000 | 5,003,000 | 2,510,848 | ||
| 30 | Dec 25, 2025 16:28 | 16,802 | 246,145,885 | 214,419,000 | 4,007,000 | 2,306,048 |