Here is the problem. We have N jars. Each jar can have any number of beans. These beans have to be distributed among C children. The resulting distribution should serve two goals Now
the number of beans that each child gets must be the same (+/- 1 when total number of beans is not a multiple of C)
each child to get all the beans from minimum number of distinct jars. Why? It is possible that beans in a jar may be contaminated. We want as few children to get infected as possible. E.g. if we have two jars with N beans each and two children, each child gets N beans. we would want child one to get N beans from jar 1 and child two to get beans from jar 2. As opposed to a solution, wherein child 1 gets half beans from jar 1 and half beans from jar 2. In former solution, if jar 1 is contaminated, only child 1 is infected. In latter solution, both children are infected.
So if
C = 5
beans = {B0:12, B1:12, B2:12, B3:12, B4:12} // Jar:<Bean-Count>
Distribution should be
{C1:{B0:12}, C1:{B1:12}, C2:{B2:12}, C3:{B3:12}, C4:{B4:12}}
Because each child has beans from exactly one jar. Following distribution will be less preferred
{C0:{B0:6, B1:6}, C1:{B0:6, B1:6}, C2:{B2:12}, C3:{B3:12}, C4:{B4:12}}
What will be the algorithm for achieving the distribution strategy with above goals in mind?