You are given two lists of integers: `itemWeights` representing the weights of items, and `containerCapacities` representing the capacities of containers. Your task is to assign items to containers such that the total weight of items in each container does not exceed its capacity. The goal is to find an assignment that maximizes the number of items distributed. If multiple assignments distribute the maximum number of items, any one of them is acceptable.
Explanation: We can put item with weight 1 and item with weight 2 into container 1 (capacity 3). This fills container 1 with weight 3. We can put item with weight 3 and item with weight 4 into container 2 (capacity 7). This fills container 2 with weight 7. Total weight transported is 3 + 7 = 10. Items transported: 4. Item with weight 5 cannot be placed.
Explanation: We can put item with weight 10 into container 2 (capacity 15). We can put item with weight 20 into container 1 (capacity 25). Total weight transported is 10 + 20 = 30. Items transported: 2. Item with weight 30 cannot be placed.
Explanation: No item can fit into any container, so 0 total weight is transported.
Analyze constraints and compute optimal solutions step-by-step.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak