Problem Statement
We have R red, G green, and B blue balls.
We want to divide them into as few packages as possible.
Each package must contain 1, 2, or 3 balls.
Additionally, each package must be either a "normal set" (all balls in the package have the same color), or a "variety set" (no two balls have the same color).
Compute and return the smallest possible number of packages.
Definition
- Class:
- PackingBallsDiv2
- Method:
- minPacks
- Parameters:
- int, int, int
- Returns:
- int
- Method signature:
- int minPacks(int R, int G, int B)
- (be sure your method is public)
Constraints
- R, G, and B will each be between 1 and 100, inclusive.
Examples
4
2
4
Returns: 4
We have 4 red, 2 green, and 4 blue balls. Clearly, we need at least four packages to store 10 balls. One possibility of using exactly four packages looks as follows: RGB, RG, RR, BBB. (I.e., the first package has 1 ball of each color, the second package has a red and a green ball, and so on.)1
7
1
Returns: 3
Here the only possible solution is to have one package with RGB and two packages with GGG each.2
3
5
Returns: 4
78
53
64
Returns: 66
100
100
100
Returns: 100