Problem 5: Big Boxes
https://open.kattis.com/problems/bigboxes
Given an integer , we can determine whether it's possible to partition the items into boxes of consecutive items such that each box has a weight of at most . This is possible in time taking a greedy approach. For example, if , :
3 1 1 3 9 5 2 Given
3 1 1 3 9 5 2 Current sum = 3
^
3 1 1 3 9 5 2 Current sum = 4
^
3 1 1 3 9 5 2 Current sum = 5
^
3 1 1 3 9 5 2 Current sum = 8
^
3 1 1 3 | 9 5 2 9 + 8 > 12, add partition
^ Current sum = 9
3 1 1 3 | 9 | 5 2 5 + 9 > 12, add partition
^ Current sum = 5
3 1 1 3 | 9 | 5 2 Current sum = 7
^ 3 groups -> impossible
We want to find the smallest such that it's possible to partition the items into boxes of consecutive items such that each box has a weight of at most .
If is a weight where the partitioning is impossible, then all weights less than are also cases where partitioning is impossible.
However, if is a weight where the partitioning is possible, then then all weights greater than cannot be the smallest weight where partitioning is possible.
Therefore, we can find the smallest that satisfies the above equation using binary search.
Last updated