2022-03-27 20:45:09 +08:00
< p > You are playing a solitaire game with < strong > three piles< / strong > of stones of sizes < code > a< / code > , < code > b< / code > , and < code > c< / code > respectively. Each turn you choose two < strong > different non-empty < / strong > piles, take one stone from each, and add < code > 1< / code > point to your score. The game stops when there are < strong > fewer than two non-empty< / strong > piles (meaning there are no more available moves).< / p >
< p > Given three integers < code > a< / code > , < code > b< / code > , and < code > c< / code > , return < em > the< / em > < strong > < em > maximum< / em > < / strong > < em > < strong > score< / strong > you can get.< / em > < / p >
< p > < / p >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 1:< / strong > < / p >
2022-03-27 20:45:09 +08:00
< pre >
< strong > Input:< / strong > a = 2, b = 4, c = 6
< strong > Output:< / strong > 6
< strong > Explanation:< / strong > The starting state is (2, 4, 6). One optimal set of moves is:
- Take from 1st and 3rd piles, state is now (1, 4, 5)
- Take from 1st and 3rd piles, state is now (0, 4, 4)
- Take from 2nd and 3rd piles, state is now (0, 3, 3)
- Take from 2nd and 3rd piles, state is now (0, 2, 2)
- Take from 2nd and 3rd piles, state is now (0, 1, 1)
- Take from 2nd and 3rd piles, state is now (0, 0, 0)
There are fewer than two non-empty piles, so the game ends. Total: 6 points.
< / pre >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 2:< / strong > < / p >
2022-03-27 20:45:09 +08:00
< pre >
< strong > Input:< / strong > a = 4, b = 4, c = 6
< strong > Output:< / strong > 7
< strong > Explanation:< / strong > The starting state is (4, 4, 6). One optimal set of moves is:
- Take from 1st and 2nd piles, state is now (3, 3, 6)
- Take from 1st and 3rd piles, state is now (2, 3, 5)
- Take from 1st and 3rd piles, state is now (1, 3, 4)
- Take from 1st and 3rd piles, state is now (0, 3, 3)
- Take from 2nd and 3rd piles, state is now (0, 2, 2)
- Take from 2nd and 3rd piles, state is now (0, 1, 1)
- Take from 2nd and 3rd piles, state is now (0, 0, 0)
There are fewer than two non-empty piles, so the game ends. Total: 7 points.
< / pre >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 3:< / strong > < / p >
2022-03-27 20:45:09 +08:00
< pre >
< strong > Input:< / strong > a = 1, b = 8, c = 8
< strong > Output:< / strong > 8
< strong > Explanation:< / strong > One optimal set of moves is to take from the 2nd and 3rd piles for 8 turns until they are empty.
After that, there are fewer than two non-empty piles, so the game ends.
< / pre >
< p > < / p >
< p > < strong > Constraints:< / strong > < / p >
< ul >
< li > < code > 1 < = a, b, c < = 10< sup > 5< / sup > < / code > < / li >
< / ul >