forked from keshavnandan/Topcoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPackingBallsDiv2.txt
68 lines (45 loc) · 1.1 KB
/
PackingBallsDiv2.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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)
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