d small packages i slimited. all items must be placed in packages and used packages have to be filled completely. Write a function that calculates the minimum number of packages needed to hold a given number of tiems. If its not possible to meet the requirements, return -1. For example, if we have 16 items, 2 large and 10 small packages, the function should return 8( 2large packages + 6 small packages). C++ #include
A large package can hold five items, while the small package can hold only one item. the available number of both large and small packages i slimited. all items must be placed in packages and used packages have to be filled completely. Write a function that calculates the minimum number of packages needed to hold a given number of tiems. If its not possible to meet the requirements, return -1. For example, if we have 16 items, 2 large and 10 small packages, the function should return 8( 2large packages + 6 small packages).
C++
#include <stdexcept>
#include <iostream>
int minimalNumberOfPackages(int items, int availableLargePackages, int availableSmallPackages)
{
throw std::logic_error("Waiting to be implemented");
}
#ifndef RunTests
int main()
{
std::cout << minimalNumberOfPackages(16, 2, 10);
}
#endif
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images