Number of days to produce specified number of 3 different colored balls

29 Views Asked by At

Suppose we want to produce $x,y,z$ amount of red, blue, green balls, respectively, using a machine. This machine can produce either (1) 2 balls of the same color in 1 day, or (2) one ball of each color in 1 day. What is the minimum number of days to produce the required number of balls of each color? Note that you can exceed the number of required balls of each color.

I think the greedy approach is optimal here, but I'm not sure how to prove it is optimal. By greedy, what I mean is we're going to initially use option (2) $\min(x,y,z)$ times. Let's just assume $x = \min(x, y, z)$ without loss of generality. Afterwards, we will need $y - x$ blue and $z - x$ green balls. At this point, I propose that we use option (1) $\big\lfloor \frac{y - x}{2} \big\rfloor + \big\lfloor \frac{z - x}{2} \big\rfloor$ times.

After this point, we will have either acquired all the balls needed (i.e., $y-x$ and $z-x$ are both even), or red and/or green needs one more ball (which takes 1 more day using option (2)).

So if we define $a = \max(x,y,z)$, $c = \min(x,y,z)$, $b = \{x, y, z \} \setminus \{a, c\}$, I am proposing that the optimal solution is $$ c + \bigg\lfloor \frac{a - c}{2} \bigg\rfloor + \bigg\lfloor \frac{b - c}{2} \bigg\rfloor + \bigg\lceil \frac{(a - c) \mod 2 + (b - c) \mod 2}{2} \bigg\rceil $$

or $$ c + \bigg\lceil \frac{a+b-2c}{2} \bigg\rceil $$

Is this solution optimal? If so, how do I prove its optimality?

1

There are 1 best solutions below

3
On

Edit: your solution is in fact optimal. I misunderstood it originally. A simpler solution is below.

Consider the case where, WLOG, $x \leq y \leq z$. The correct solution is to get one ball of each colour $y$ times, and then get two balls of the green colour as many times as necessary (which will be $ceil(\frac{z - y}{2})$ times).

It's relatively easy to prove this solution is correct. For consider any solution in which we use option (1) on two different colours: then WLOG we could have used option (2) twice. So WLOG any other solution will consist only of using option (2) and using option (1) on exactly 1 colour. And it's clear that WLOG, we can assume that colour to be green. So clearly, this hypothetical other solution is no better than ours.

Your solution is identical to mine since it replaces $2n$ uses of option (2) with $n$ uses of option (1) on blue and $n$ uses of option (1) on green for some $n$.