#3074
Apple Redistribution into Boxes
newbie · 195 · lc easy +16 · verified · 78.5% accepted · 408 likes · top 90%
Description
You have n apple packs where pack i holds apple[i] apples, and m boxes where box i can hold capacity[i] apples. Apples from one pack may be split among multiple boxes. Return the minimum number of boxes needed to contain all the apples.
Example 1:
Input: apple = [1,3,2], capacity = [4,3,1,5,2]
Output: 2
Explanation: We will use boxes with capacities 4 and 5.
It is possible to distribute the apples as the total capacity is greater than or equal to the total number of apples.
Example 2:
Input: apple = [5,5,5], capacity = [2,4,2,7]
Output: 4
Explanation: We will need to use all the boxes.
Code
1
2
3