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
| Date | Author | Language | Status | Score | |
|---|---|---|---|---|---|
| Sep 15, 2026 19:33 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 19:21 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 19:16 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 18:38 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 18:19 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 18:01 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 17:55 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 17:33 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 17:31 | CPPclang++18.1.3 | Error | +109.27 RP | ||
| Sep 15, 2026 17:21 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 17:03 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 16:20 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 16:05 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 15:55 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 15:24 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 02:04 | CPPclang++18.1.3 | Error | +254.46 RP | ||
| Sep 14, 2026 11:23 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 10:58 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 09:34 | CPPg++14.2.0 | Error | |||
| Sep 13, 2026 16:32 | CPPg++14.2.0 | Error | |||
| Sep 13, 2026 16:22 | CPPg++14.2.0 | Error | |||
| Sep 13, 2026 16:14 | CPPg++14.2.0 | Error | |||
| Sep 13, 2026 15:37 | CPPg++14.2.0 | Error | |||
| Sep 11, 2026 16:59 | CPPg++14.2.0 | Error | |||
| Sep 11, 2026 16:27 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 18:06 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 18:00 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 17:05 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 16:06 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 15:59 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 15:50 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 15:13 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 15:03 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 14:44 | RUSTrust-1.98.1 | Success | 275,176+5.00 RP | ||
| Sep 10, 2026 14:39 | RUSTrust-1.98.1 | Error | |||
| Sep 10, 2026 14:36 | CPPclang++20.1.2 | Error | |||
| Sep 10, 2026 13:56 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 13:36 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 13:32 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 10:54 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 10:49 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 10:45 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 10:35 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 09:09 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 09:02 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 08:53 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 08:43 | CPPg++14.2.0 | Error | +5.00 RP | ||
| Sep 9, 2026 17:14 | CSHARP10.0.7 | Error | |||
| Sep 9, 2026 15:59 | CPPg++14.2.0 | Error | +300.41 RP | ||
| Sep 9, 2026 14:17 | CPPg++14.2.0 | Error | |||
| Sep 9, 2026 14:12 | CPPg++14.2.0 | Error | |||
| Sep 9, 2026 14:07 | CPPg++14.2.0 | Error | |||
| Sep 9, 2026 13:43 | CPPg++14.2.0 | Error | +101.74 RP | ||
| Sep 9, 2026 13:33 | CPPg++14.2.0 | Error | |||
| Sep 8, 2026 23:57 | CPPg++14.2.0 | Error | |||
| Sep 8, 2026 23:20 | CPPg++14.2.0 | Error | |||
| Sep 8, 2026 23:16 | CPPg++14.2.0 | Error | |||
| Sep 8, 2026 22:45 | CPPg++14.2.0 | Error | |||
| Sep 8, 2026 21:57 | CPPg++14.2.0 | Error | |||
| Sep 8, 2026 21:24 | CPPg++14.2.0 | Error | |||
| Sep 8, 2026 21:11 | CPPg++14.2.0 | Error | +14.39 RP | ||
| Sep 8, 2026 20:28 | CPPg++14.2.0 | Error | |||
| Sep 8, 2026 20:12 | CPPg++14.2.0 | Error | |||
| Sep 8, 2026 19:50 | CPPg++14.2.0 | Error | +294.50 RP | ||
| Sep 8, 2026 19:03 | CPPg++14.2.0 | Error | +135.21 RP | ||
| Sep 8, 2026 17:12 | CPPg++14.2.0 | Error | |||
| Sep 8, 2026 15:44 | RUSTrust-1.95.0 | Error | |||
| Sep 8, 2026 15:41 | RUSTrust-1.95.0 | Error | |||
| Sep 8, 2026 15:38 | RUSTrust-1.95.0 | Error | |||
| Sep 8, 2026 15:03 | ZIG0.16.0 | Error | |||
| Sep 8, 2026 14:55 | ZIG0.16.0 | Error | +53.21 RP | ||
| Sep 8, 2026 14:45 | ZIG0.16.0 | Error | |||
| Sep 8, 2026 14:42 | ZIG0.16.0 | Error | |||
| Sep 8, 2026 14:38 | ZIG0.16.0 | Error | +143.84 RP | ||
| Sep 8, 2026 13:31 | GOgo1.26.2 | Error | |||
| Sep 8, 2026 13:19 | GOgo1.26.2 | Error | |||
| Sep 8, 2026 13:06 | GOgo1.26.2 | Error | |||
| Sep 8, 2026 12:50 | GOgo1.26.2 | Error | |||
| Sep 8, 2026 12:09 | CPPg++14.2.0 | Error | |||
| Sep 7, 2026 14:02 | CSHARP10.0.7 | Error | |||
| Sep 7, 2026 13:57 | CSHARP10.0.7 | Error | |||
| Sep 7, 2026 13:50 | CSHARP10.0.7 | Error | |||
| Sep 7, 2026 13:44 | CSHARP10.0.7 | Error | |||
| Sep 7, 2026 13:39 | CSHARP10.0.7 | Error | |||
| Sep 7, 2026 13:32 | CSHARP10.0.7 | Error | |||
| Sep 7, 2026 13:21 | CSHARP10.0.7 | Error | |||
| Sep 7, 2026 13:15 | CSHARP10.0.7 | Error | |||
| Sep 7, 2026 12:32 | CSHARP10.0.7 | Error | |||
| Sep 7, 2026 10:28 | CSHARP10.0.7 | Error | |||
| Sep 6, 2026 17:31 | CPPg++14.2.0 | Error | +12.90 RP | ||
| Sep 4, 2026 20:39 | CPPclang++20.1.2 | Error | +93.66 RP | ||
| Sep 4, 2026 19:00 | RUSTrust-1.98.1 | Success | 2,291 | ||
| Sep 4, 2026 18:31 | CPPclang++20.1.2 | Error | |||
| Sep 4, 2026 18:02 | CPPclang++20.1.2 | Error | |||
| Sep 4, 2026 17:54 | CPPclang++20.1.2 | Error | |||
| Sep 4, 2026 17:04 | CPPclang++20.1.2 | Error | |||
| Sep 4, 2026 15:42 | CPPg++14.2.0 | Error | +52.73 RP | ||
| Sep 4, 2026 10:32 | CSHARP10.0.7 | Error | |||
| Sep 4, 2026 10:21 | CSHARP10.0.7 | Error | |||
| Sep 4, 2026 10:18 | GOgo1.26.2 | Error |