Maximum multiple of 3 using three numbers and given operations

347 Views Asked by At

Given three numbers $a$, $b$ and $c$ find the greatest multiple of 3 that can be formed from these numbers using the following rules and operations.

  1. The initial result is $0$
  2. During each operations a sum of exactly three is formed using the numbers and added to the result
  3. For extracting a sum of three you can either subtract 1 from each number or you can subtract 2 from one number and 1 from another number but you cannot subtract 3 from any number.
  4. The numbers must remain greater than or equal to zero after each operations i.e. you cannot subtract 2 from 1 or 1 from from 0.
  5. The above process is repeated until no more operations can be performed.

What is the maximal sum you can obtain?

Example: 5 4 3

The maximum multiple that can be obtained from above numbers using the operations is 12. One possible way is:

5 4 3 -> 4 3 2 -> 3 2 1 -> 2 1 0 -> 0 0 0

My thoughts right now: I haven't reached a definitive solution but I think first we should try to subtract 1's from all the three numbers as many times as possible because it will probably increase the chances to select numbers in the future again. So after subtracting 1's from all numbers maximum times we get our sum as $3$ * $min$( $a$, $b$, $c$) and this minimum value is subtracted from each of $a$, $b$ and $c$. I do not know how to proceed next. Any help?

1

There are 1 best solutions below

0
On BEST ANSWER

It seems likely to me that this process should give the answer:

  1. Relabel if needed so that $a\le b\le c$.
  2. If $c > 2(a + b)$, then set $c = 2(a + b)$. (The remaining stones in that pile are untouchable.)
  3. The maximum size of the 4th pile is $3\lfloor{a + b + c\over 3}\rfloor$.

The algorithm is simple. Keep taking two stones from the largest pile and one from the second largest until you arrive at a condition where all piles differ in size from the others by at most 1. As long as $c \le 2(a + b)$, this should be possible. (Otherwise $c$ will still have extra stones after $a$ and $b$ are empty.) At that point take 1 stone from all three piles until one of the piles is gone. There will remain at most 2 stones in the remaining piles, so no further steps can be taken.