Coloring tables with 3 colored balloons such that all 3 balloons are not same. You have $r$ red, $g$ green, and $b$ blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some tables shouldn't have the same color. What maximum number $t$ of tables can be decorated if we know the number of balloons of each color?
The problem is from an old codeforces contest https://codeforces.com/problemset/problem/478/C
Here is my analysis
Say given colors are $(a, b, c)$ and $a \le b \le c$ then if $max (a, b, c) - min (a, b, c) \le 1$ that means

*

*Either $max (a, b, c) == min (a, b, c) \implies a = b = c $ and answer is $ a = \frac{(a + b + c)}{3} $

*Or $(a, b, c) = (a, a, a + 1)$ or $(a, a + 1, a + 1)$, here total number of colors = 3a + 1 or 3a + 2, hence total number of decorations can maximum be a which is $\frac{(a + b + c)}{3}$
Secondly consider the case where $c> 2 * (a + b)$, then it is clear that answer is (a + b) because we can create tables using $(a, 0, 2a) + (0, b, 2b)$ number of decorations.
Editorial suggests that if $a + b <c$, then take (0, 1, 2) colors to create decoration and continue, now we have $(a, b-1, c-2)$, I didn't understand why would this lead to optimal strategy.
Also what happens in the case when $a + b> c$ ? Can someone explain?
There is an editorial but I feel it is not complete https://codeforces.com/blog/entry/14307#comment-192751
 A: Let $r_n, g_n, b_n$ be the number of red, green, and blue balloons left after decorating $n$ tables, respectively. So $r_0 = r, g_0 = g, b_0 = b$. It actually does not matter what the relative sizes of $r, g, b$ are. An optimal strategy is:

When decorating table $n+1$:

*

*If the maximum difference between $r_n, g_n, b_n$ is $0$ or $1$, then use a balloon of each of the three colors.

*Otherwise, use two balloons of the most populous color, and one baloon of the most populous of the other two colors. In case of ties, choose one of the tying colors at random.

Continue until there is only one color left, or fewer than three
balloons.

Assume WLOG that $r \ge g \ge b$.
Suppose that for all tables $k < n$, $r_k > g_k > b_k$. Then $r_k - b_k \ge 2$, so each table is decorated with two red balloons and one green. This will continue until either $r_n = g_n$ or $g_n = b_n$.

*

*If $r_n = g_n$ from then on, red and green will switch back and forth between supplying one or two balloons to each table as long as they stay above $b_n$. But at every step $|r_n - g_n| \le 1$. This will end only when either $r_n = b_n$ or $g_n = b_n$. Since the other value is at most one higher, the maximum difference condition is met. From this point on, all tables will get one balloon of each color. This will continue until blue is gone. Since all three counts have been going down by $1$ at each turn, the differences between them do not change, so the color equal to $b_n$ earlier will also be gone, and the other color can have at most $1$ left. Since there not enough balloon left to decorate another table, regardless of the color, no scheme can decorate more tables than this.

*If $g_n = b_n$, each table will continue to get two red balloons, but now blue and green will switch off supplying the third balloon, with the quantities of the two never differing by more than $1$. This will continue until either $r_n$ is equal to whichever of $g_n$ or $b_n$ is higher, or until both $g_n = b_n = 0$.

*

*If $r_n$ catches up with $g_n$ or $b_n$, the other color can be at most $1$ lower, so the maximum difference condition is met. From that point on, all three balloon are used on each table until one color runs out, at which time there can be at most $1$ balloon for either of the other two colors. That is, at most two balloons are left. Again, no more tables can be decorated regardless of the balloon colors, so no other scheme can improve on this.

*If $r_n$ does not catch up with $g_n$ or $b_n$ until they are both $0$, then every table has two red balloons and one balloon from green or blue. Since every green and blue balloon was used, there are $g+b$ tables, and since the problem rules require one such balloon at each table, it is impossible to decorate more tables by any other scheme.



Thus in every case, this algorithm decorates the maximum number of tables possible, which is
$$\begin{cases}r+g+b - \max(r,g,b),&2\max(r,g,b) \ge r+g+b\\[1em]
\left\lfloor \dfrac{r+g+b}3\right\rfloor,&2\max(r,g,b) < r+g+b\end{cases}$$
A: Assume that there are $3m=a+b+c$ balloons, with $a\leq b\leq c$ balloons of colors $A$, $B$, $C$.
Claim. We can legally decorate $m$ tables iff
$$a+b\geq m,\qquad{\rm i.e.,}\qquad c\leq2m\ .\tag{1}$$
Proof. When $c>2m$ the $C$-balloons cannot be distributed legally. – Conversely: Assume $(1)$. Put the $A$-balloons on $a\leq m$ different tables and $m-a$ balloons of color $B$ on the remaining tables. There are $a+b-m\geq0$ of the $B$-balloons left. Put them on different tables as second balloon. Finally bring all allocations to three, using the $C$-balloons.$\quad\square$
When $a\leq b\leq c$ are given, but $(1)$ is not fulfilled, we can legally decorate just $a+b<m$ tables, and $c-2(a+b)>0$ balloons of color $C$ are left over.
