Containers
SRM 370 · 2007-10-09 · by mateuszek
Problem Statement
- If the current package cannot fit into the current container, skip to step 3. Otherwise, go to the next step.
- Put the current package into the current container. Grab the next package, and go back to step 1.
- Put the current container aside (you will not put any more packages into that container). Move on to the next container in line, and go back to step 1.
Notes
- A set of packages fits into a container if the total size of all the packages in the set does not exceed the capacity of the container.
- You must use the containers and the packages in the order that they are given. You may not reorder them.
Constraints
- containers will contain between 1 and 50 elements, inclusive.
- Each element of containers will be between 1 and 1000, inclusive.
- packages will contain between 1 and 50 elements, inclusive.
- Each element of packages will be between 1 and 1000, inclusive.
- It will be possible to put all the packages inside containers using the method described in the statement.
{ 5, 5, 5 }
{ 5, 5, 5 }
Returns: 0
Here, we've got 3 packages of size 5 and 3 containers of size 5, so no space will be wasted.
{ 5, 6, 7 }
{ 5, 5, 5 }
Returns: 3
All the packages are of size 5. We will put the first package into the container of size 5, the second package into the container of size 6 and the third into the container of size 7. The overall wasted space will be equal to (5 - 5) + (6 - 5) + (7 - 5) = 3.
{ 2, 3, 5 }
{ 3 }
Returns: 7
Here, we've got only one package of size 3. First, we'll try to put it into the container of size 2, but it won't fit, so we'll put it into the second container, leaving the third untouched. The overall wasted space will be 2 + (3 - 3) + 5 = 7.
{ 3, 4, 5, 6 }
{ 3, 3, 3, 3, 3 }
Returns: 3
{ 1000 }
{ 1000 }
Returns: 0
Submissions are judged against all 80 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Containers with a public method int wastedSpace(vector<int> containers, vector<int> packages) · 80 test cases · 2 s / 256 MB per case