Order a fix's rollout to cut user exposure
Your task
Your support agent has a bug that leaks internal notes into customer replies. The fix ships one region at a time, and each customer's regions must get it in the order that customer agreed to, staging before production. Every hour a region waits, its users stay exposed.
Write least_exposure(customers) that returns the smallest total exposure the rollout can achieve.
customers: a list of customers. Each customer is a list of regions, possibly empty, in the order they must get the fix. Each region is[hours, users]: how many hours its rollout takes, at least 1, and how many users it has, 0 or more.- Return the total exposure, a whole number.
Rules:
- The rollout starts at hour 0 and does one region at a time, back to back, with no gaps.
- Each customer's regions go in that customer's order. Regions of different customers can be interleaved in any way.
- A region's users are exposed from hour 0 until its rollout finishes, so its exposure is its users times the hour its rollout finishes.
- The total exposure is the sum over all regions. Return the smallest total over every allowed order.
- There are at most 40 customers, each with at most 25 regions, and every number is at most 10,000.
Examples
least_exposure(customers: list[list[list[int]]]) -> intExample 1
Input
least_exposure([[[2, 10], [3, 5]]])Output
45Example 2
Input
least_exposure([[[3, 1]], [[1, 10]]])Output
14Example 3
Input
least_exposure([[[1, 5], [2, 5]], [[1, 3]]])Output
31