Regards to the task description, there is a packaging machine that dispenses the product base of packet size and weight capacity. Number of the packed items should not exceed the packed size or weight capacity.
The algorithm is to first read this packed capacity information then dispense of product bath inside the packed
in each iteration, the maximum item that can put in the packed will be defined by comparing the available index, available weight, and available items.
If remain item greater than the available space in the packet, then a new packed defined.
For simplicity python script has been chosen for this algorithm. before printing each packet sorted base on item's length