Order a fix's rollout to cut user exposure

Agent buildHard40 min

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:

  1. The rollout starts at hour 0 and does one region at a time, back to back, with no gaps.
  2. Each customer's regions go in that customer's order. Regions of different customers can be interleaved in any way.
  3. 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.
  4. The total exposure is the sum over all regions. Return the smallest total over every allowed order.
  5. 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]]]) -> int
Example 1
Inputleast_exposure([[[2, 10], [3, 5]]])
Output45
Example 2
Inputleast_exposure([[[3, 1]], [[1, 10]]])
Output14
Example 3
Inputleast_exposure([[[1, 5], [2, 5]], [[1, 3]]])
Output31