You're running a packaging optimization system for an e-commerce company! You have n packages of various sizes that need to be shipped, and you must choose the single best supplier from m available suppliers to minimize wasted space.
Each supplier offers boxes of different sizes with unlimited supply. A package can only fit in a box if the package size ≤ box size. The wasted space for each package is calculated as: box_size - package_size.
Goal: Find the supplier that minimizes the total wasted space across all packages, or return -1 if no supplier can accommodate all packages.
Example: Packages [2,3,5] with supplier boxes [4,8]:
• Package 2 → Box 4 (waste: 2)
• Package 3 → Box 4 (waste: 1)
• Package 5 → Box 8 (waste: 3)
• Total waste: 2 + 1 + 3 = 6
Input & Output
Constraints
- n == packages.length
- m == boxes.length
- 1 ≤ n ≤ 105
- 1 ≤ m ≤ 105
- 1 ≤ packages[i] ≤ 105
- 1 ≤ boxes[j].length ≤ 105
- 1 ≤ boxes[j][k] ≤ 105
- Sum of all boxes across suppliers ≤ 105