You are given two integer arrays capacity and used, both of length n. Partition i can hold capacity[i] units of data and currently stores used[i] units.
Data can be moved between partitions freely, in chunks of any size. Return the minimum number of partitions needed to store all of the data currently spread across the partitions.
Put another way, find the size of the smallest subset of partitions whose total capacity is at least the total amount of data stored across all partitions.
Function Signature
def min_partitions(capacity: list[int], used: list[int]) -> int:
Rules
-
capacity[i]
and
used[i]
describe the same partition
i
.
-
A partition you keep can hold data up to its full capacity, whatever it stored before the move.
-
If the total amount of stored data is 0, return 0.
Constraints
-
1 <= n <= 10^5
-
1 <= capacity[i] <= 10^9
-
0 <= used[i] <= capacity[i]
Examples
Input: capacity = [10, 20, 30, 40], used = [5, 10, 15, 20]
Output: 2
The total data is 5 + 10 + 15 + 20 = 50. The largest single partition holds only 40, but the two largest hold 40 + 30 = 70, which is enough.
Input: capacity = [5, 5, 5], used = [3, 3, 3]
Output: 2
The total data is 9. One partition holds 5, which is too little, and any two partitions hold 10.
Input: capacity = [3, 8], used = [0, 0]
Output: 0
No data is stored, so no partition is needed.