Supply Warehouse Cleanup
Time limit1sMemory limit1024 MB
Split N boxes into at most M consecutive groups, assign each group to a distinct squad, and minimize the largest per-soldier share of supplies.
- Level
Medium7 of 10
- Topics
- Binary search, Greedy, Prefix sum, Brute force
- Solved
- No attempts yet
Problem
The supply warehouse has supply boxes numbered from to , lined up in numerical order. Box holds supplies. The unit in charge of cleanup has squads numbered from to , and squad has soldiers.
The commander told the deputy to use the following method. Split the boxes into at most groups of consecutive boxes. Pick as many squads as there are groups, and assign each group to one squad. The soldiers of that squad clean up all supplies in the group. Each group must contain at least one box.
To keep the work from being pushed onto others, the deputy assigns each soldier a fixed number of supplies to clean up. To make the split as fair as possible, the deputy wants to minimize the number of supplies handled by the soldier with the largest share, while still following the commander's method.
When every soldier is assigned according to the deputy's plan, find the number of supplies handled by the soldier who cleans up the most.
Input
The first line contains the number of boxes and the number of squads , separated by a space. (; )
The second line contains the supply counts in each box, separated by spaces. ()
The third line contains the number of soldiers in each squad, separated by spaces. ()
Output
Print the number of supplies handled by the soldier who cleans up the most.