PackingBallsDiv2
SRM 609 · 2013-12-22 · by semiexp
SRM 609 · 2013-12-22 · by semiexp · Brute Force, Simple Search, Iteration
Problem Statement
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.
Constraints
- R, G, and B will each be between 1 and 100, inclusive.
Examples
0)
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)
1 7 1 Returns: 3
Here the only possible solution is to have one package with RGB and two packages with GGG each.
2)
2 3 5 Returns: 4
3)
78 53 64 Returns: 66
4)
100 100 100 Returns: 100
Submissions are judged against all 133 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class PackingBallsDiv2 with a public method int minPacks(int R, int G, int B) · 133 test cases · 2 s / 256 MB per case