ExpertSimulation & Finance50 points

Reorder point simulation for a Lagos pharmacy chain

A pharmacy chain in Lagos manages one critical medicine with a classic (R, Q) policy: when the inventory position drops to the reorder point R or lower, order Q units. Suppliers need a fixed lead time. Sales that cannot be served are lost (no back-orders). The order of events inside a day matters, so follow it exactly.

Task: line 1 is S R Q L: starting stock, reorder point, order quantity, lead time in days (L is at least 1). Line 2 is the daily demand for days 1..n (non-negative integers). Each day, in this order: (1) every order due that day arrives and is added to stock; (2) demand is served from stock, sold = min(stock, demand), the rest is lost; (3) at the end of the day, if stock + units still on order <= R, place one order of Q units that arrives at the start of day d + L (orders arriving after day n are never received but still count as placed). At most one order is placed per day. Print five lines: Orders placed: a, Lost units: b, Stockout days: c (days with lost units above 0), Fill rate: p% (sold units divided by total demand times 100, 2 decimals, or 100.00% if total demand is 0) and Ending stock: e (stock after day n).

Sample tests

Input

50 30 100 3
12 15 9 20 11 14 8 17 13 10 16 12

Expected output

Orders placed: 2
Lost units: 7
Stockout days: 2
Fill rate: 95.54%
Ending stock: 0

Input

10 5 20 2
4 4 4 4 4 4 4 4

Expected output

Orders placed: 2
Lost units: 2
Stockout days: 1
Fill rate: 93.75%
Ending stock: 0

Your answer is also checked against 4 hidden tests.

Need a hint?

Keep a dictionary from arrival day to quantity; the units still on order are the values left in it.