TopCoder problem "PackingParts" used in SRM 297 (Division II Level One)

Problem Statement


Given a set of parts and a set of boxes, you are asked to determine how many of the parts can be packed into boxes. You can put at most one part into each box. In order for a part to fit into a box, the box must be the same size as or larger than the part. You follow the following process when packing the parts:

  1. Choose the smallest part that has not been packed yet.
  2. Find the smallest empty box the part fits into. If there is no such box, you cannot pack any more parts, and you stop.
  3. Pack the part into the box.
  4. If all parts have been packed, stop. Otherwise, continue with step 1.

You are given a int[] partSizes containing the sizes of the parts, and a int[] boxSizes containing the sizes of the boxes. Both int[]s will be sorted in non-descending order.

Return an int representing the maximum number of parts you can pack by following the process above.



Parameters:int[], int[]
Method signature:int pack(int[] partSizes, int[] boxSizes)
(be sure your method is public)


-partSizes will contain between 1 and 50 elements, inclusive.
-boxSizes will contain between 1 and 50 elements, inclusive.
-Both partSizes and boxSizes will be sorted in non-decreasing order.
-Each element in partSizes and boxSizes will be between 1 and 100, inclusive.


Returns: 3
We have three parts of size 2. Two of them can be packed into boxes of size 2, and one into a box of size 3.
Returns: 2
The part of size 1 goes into the box of size 2 and the part of size 5 goes into the box of size 5.
Returns: 3
We have four parts of size 10, but only three boxes that can fit parts that big.
Returns: 4
Here, we have plenty of boxes to choose from.
Returns: 3
The boxes are big, but we only have three, so we cannot pack four parts.
Returns: 6

Problem url:

Problem stats url:




PabloGilberto , brett1479 , vorthys , Olexiy

Problem categories: