Industry Improvements
InterviewTime limit2sMemory limit1024 MB
Find the smallest machine capacity that lets all boxes, in their given order, be split into at most k contiguous groups whose weight sums each stay within the capacity.
- Level
Medium4 of 10
- Topics
- Binary search, Greedy, Array
- Solved
- No attempts yet
Problem
As a member of the Factory Planning Committee, you oversee the production process and make sure everything runs smoothly.
The committee wants the machines on the production line to process boxes without breakdowns. A machine is more likely to break down when it handles heavier objects, so the committee proposes a maximum weight capacity for each machine. Because of budget constraints, the committee also limits the number of times a machine can be started to at most .
Your task is to find the minimum weight capacity that lets the machine line process all boxes, with the line started at most times and the boxes processed in the given order.
For example, the boxes can be split into these three contiguous subsequences:
With this split, the capacity of the machine needs to be 8 units of weight.
Input
The input consists of:
- One line with two integers and (, ), the number of boxes and the number of times the machine can be started.
- One line with integers (), the weights of the boxes, in the order in which they need to be processed.
Output
Output the minimum weight capacity required by the machine to process all boxes within runs or fewer.