A portfolio risk team at Two Sigma must liquidate an inventory of order packages, specified by size array weights, over exactly consecutive trading days. The packages must be executed in the exact sequential order given.
Each day, the execution algorithm can liquidate packages up to a maximum daily capacity . Once adding the next package would exceed capacity , trading for that day ceases and the remaining packages carry over to the next day.
Your Task
Implement ship_within_days(weights: list[int], d: int) -> int that determines the least daily capacity necessary to liquidate all packages within days in time.
Constraints
Examples
weights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
d = 5
# Minimum capacity is 15:
# Day 1: 1, 2, 3, 4, 5 (sum 15)
# Day 2: 6, 7 (sum 13)
# Day 3: 8 (sum 8)
# Day 4: 9 (sum 9)
# Day 5: 10 (sum 10)
# Output: 15