Cross-Margin Liquidation Engine yenw0d

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 of trade_size * price_at_trade_time across all trades
  • Margin rule: liquidate if equity < total_notional / 100 after any price update

Input

One command per line on STDIN:

  • a <balance> – create account with USD balance (IDs start at 0, incrementing)
  • p <instrument_idx> <price> – set/update instrument price (0-indexed)
  • t <account_idx> <instrument_idx> <size> – trade size (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
Back to listAug 16, 2026 23:03marko1597marko1597Error
Source Code

Source code access is restricted. Log in to request access.

Challenge History
DateChallengerCostTypeStatus
Sep 11, 2026 17:19Andrew Epstein37.28CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 11, 2026 17:310679,519,993668,365,0002,623,0004,210,688line 7: expected liquidate 8 -1152921504623980833 246914 got liquidate 8 -46116860201407736 246914
2Sep 11, 2026 17:310682,854,158671,669,0002,640,0004,210,688line 7: expected liquidate 8 -1152921504637459521 246914 got liquidate 8 -46116860214886424 246914
3Sep 11, 2026 17:310695,503,678684,459,0002,578,0004,210,688line 7: expected liquidate 8 -1152921504634492705 246914 got liquidate 8 -46116860211919608 246914
4Aug 17, 2026 01:131,13924,313,33613,775,0001,041,0002,113,536
5Aug 17, 2026 01:131,17523,403,31814,192,0001,084,0002,113,536
6Aug 17, 2026 01:131,19723,681,88614,450,0001,111,0002,113,536
7Aug 17, 2026 01:131,22224,111,10014,853,0001,036,0002,113,536
8Aug 17, 2026 01:131,25925,862,07015,199,0001,180,0002,113,536
9Aug 17, 2026 01:131,27834,325,18215,383,0001,236,0002,113,536
10Aug 17, 2026 01:131,28624,890,20115,621,0001,104,0002,113,536
11Aug 17, 2026 01:131,29225,982,67115,576,0001,221,0002,113,536
12Aug 17, 2026 01:131,38732,851,81816,857,0001,180,0002,113,536