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 | Oct 12, 2025 18:49 | 34,169 | 469,599,351 | 439,191,000 | 5,002,000 | 2,437,120 | ||
| 2 | Oct 12, 2025 18:05 | 36,006 | 495,835,406 | 466,077,000 | 2,000,000 | 2,375,680 | ||
| 3 | Oct 12, 2025 18:49 | 36,841 | 506,365,002 | 474,928,000 | 3,999,000 | 2,449,408 | ||
| 4 | Oct 12, 2025 18:32 | 36,936 | 510,574,131 | 477,172,000 | 3,001,000 | 2,371,584 | ||
| 5 | Oct 12, 2025 18:49 | 37,967 | 518,808,483 | 489,572,000 | 3,996,000 | 2,498,560 | ||
| 6 | Oct 12, 2025 18:49 | 38,647 | 526,632,188 | 499,413,000 | 3,002,000 | 2,478,080 | ||
| 7 | Oct 12, 2025 18:48 | 39,187 | 538,421,862 | 507,435,000 | 1,997,000 | 2,441,216 | ||
| 8 | Oct 12, 2025 18:49 | 40,375 | 552,160,053 | 521,878,000 | 2,999,000 | 2,453,504 | ||
| 9 | Oct 12, 2025 19:35 | 40,531 | 553,057,499 | 521,903,000 | 4,999,000 | 2,289,664 | ||
| 10 | Oct 12, 2025 18:32 | 40,571 | 555,630,318 | 524,421,000 | 2,996,000 | 2,437,120 | ||
| 11 | Oct 12, 2025 18:05 | 41,079 | 567,557,794 | 528,029,000 | 6,000,000 | 2,404,352 | ||
| 12 | Oct 12, 2025 18:05 | 41,135 | 561,516,394 | 530,755,000 | 3,998,000 | 2,301,952 | ||
| 13 | Oct 12, 2025 18:05 | 42,076 | 570,015,385 | 544,990,000 | 1,999,000 | 2,494,464 | ||
| 14 | Oct 12, 2025 18:49 | 42,261 | 573,476,342 | 546,395,000 | 3,002,000 | 2,269,184 | ||
| 15 | Oct 12, 2025 18:05 | 42,371 | 581,060,385 | 547,826,000 | 2,999,000 | 2,445,312 | ||
| 16 | Oct 12, 2025 18:05 | 42,585 | 578,507,716 | 549,611,000 | 3,997,000 | 2,445,312 | ||
| 17 | Oct 12, 2025 18:34 | 42,965 | 587,349,103 | 555,552,000 | 2,997,000 | 2,433,024 | ||
| 18 | Oct 12, 2025 18:05 | 43,081 | 588,319,661 | 558,050,000 | 2,000,000 | 2,334,720 | ||
| 19 | Oct 12, 2025 18:49 | 43,251 | 590,984,458 | 558,269,000 | 3,994,000 | 2,465,792 | ||
| 20 | Oct 12, 2025 19:35 | 43,698 | 594,570,728 | 567,069,000 | 1,000,000 | 2,416,640 | ||
| 21 | Oct 12, 2025 18:47 | 43,790 | 595,344,706 | 566,268,000 | 2,996,000 | 2,306,048 | ||
| 22 | Oct 12, 2025 19:18 | 43,824 | 595,724,932 | 566,713,000 | 2,998,000 | 2,445,312 | ||
| 23 | Oct 12, 2025 18:33 | 44,414 | 606,341,215 | 575,389,000 | 1,997,000 | 2,473,984 | ||
| 24 | Oct 12, 2025 18:34 | 44,524 | 610,068,839 | 576,816,000 | 1,999,000 | 2,445,312 | ||
| 25 | Oct 12, 2025 19:18 | 44,532 | 603,900,065 | 574,915,000 | 3,999,000 | 2,387,968 | ||
| 26 | Oct 12, 2025 18:48 | 44,690 | 607,518,059 | 577,974,000 | 2,999,000 | 2,297,856 | ||
| 27 | Oct 12, 2025 18:33 | 44,697 | 608,743,180 | 581,057,000 | 0 | 2,293,760 | ||
| 28 | Oct 12, 2025 18:05 | 44,833 | 610,576,132 | 577,832,000 | 4,998,000 | 2,486,272 | ||
| 29 | Oct 12, 2025 18:49 | 44,918 | 612,839,800 | 581,929,000 | 1,999,000 | 2,297,856 | ||
| 30 | Oct 12, 2025 18:59 | 45,459 | 616,348,202 | 588,967,000 | 1,999,000 | 2,306,048 | ||
| 31 | Oct 12, 2025 19:38 | 47,097 | 640,545,470 | 609,266,000 | 3,001,000 | 2,428,928 | ||
| 32 | Oct 12, 2025 18:05 | 47,125 | 638,491,941 | 607,624,000 | 4,996,000 | 2,478,080 | ||
| 33 | Oct 12, 2025 18:47 | 47,884 | 648,783,914 | 618,490,000 | 3,996,000 | 2,441,216 | ||
| 34 | Oct 12, 2025 18:59 | 48,128 | 653,554,338 | 618,662,000 | 6,996,000 | 2,433,024 | ||
| 35 | Oct 12, 2025 18:34 | 48,341 | 662,084,822 | 624,439,000 | 3,996,000 | 2,322,432 | ||
| 36 | Oct 12, 2025 19:18 | 48,836 | 663,087,392 | 634,872,000 | 0 | 2,428,928 | ||
| 37 | Oct 12, 2025 18:32 | 49,067 | 668,062,718 | 634,868,000 | 2,999,000 | 2,408,448 | ||
| 38 | Oct 12, 2025 18:59 | 49,118 | 666,196,746 | 634,534,000 | 3,997,000 | 2,424,832 | ||
| 39 | Oct 12, 2025 19:38 | 49,656 | 671,432,193 | 640,532,000 | 4,996,000 | 2,387,968 | ||
| 40 | Oct 12, 2025 18:48 | 50,123 | 677,885,228 | 645,600,000 | 5,996,000 | 2,478,080 | ||
| 41 | Oct 12, 2025 19:38 | 50,487 | 679,719,836 | 653,333,000 | 2,996,000 | 2,424,832 | ||
| 42 | Oct 12, 2025 18:33 | 51,343 | 691,501,341 | 663,464,000 | 3,996,000 | 2,457,600 | ||
| 43 | Oct 12, 2025 19:35 | 52,118 | 702,483,446 | 672,537,000 | 4,996,000 | 2,453,504 | ||
| 44 | Oct 12, 2025 18:49 | 53,237 | 717,492,375 | 689,081,000 | 3,000,000 | 2,416,640 | ||
| 45 | Oct 12, 2025 18:47 | 54,497 | 739,356,939 | 704,468,000 | 3,996,000 | 2,420,736 |