We are given k candy bars to divide up among n people. Each bar may be left
whole, split into 2 equal pieces, or split into 3 equal pieces. We must distribute all
the candy to the people, but we want to
be as fair as possible. Define the "inequity" of a distribution of the
candy to be the difference between the minimum amount received by a person
and the maximum amount received by a person. We want to minimize the
inequity.
Among solutions that have minimum inequity, we want to choose the one that has
the fewest pieces. Each whole bar counts as one piece, while each split bar counts as either two
or three pieces depending on how it was split.
Create a class Equity that contains a method minPieces that takes n, the
number of people, and k, the number of candy bars, and returns the smallest
number of pieces that we will need in order to divide the candy bars with minimum inequity.
|