Maximum Score From Removing Stones

You are playing a solitaire game with three piles of stones of sizes a, b, and c respectively. Each turn you choose two different non-empty piles, take one stone from each, and add 1 point to your score. The game stops when there are fewer than two non-empty piles, meaning there are no more available moves.

Given three integers a, b, and c, return the maximum score you can get.

Example 1
Inputa = 2, b = 4, c = 6
Output6
The starting state is (2, 4, 6), and one optimal sequence removes stones for 6 turns until fewer than two piles are non-empty.
Example 2
Inputa = 4, b = 4, c = 6
Output7
The starting state is (4, 4, 6), and one optimal sequence removes stones for 7 turns until all piles are empty.

Constraints

  • 1 <= a, b, c <= 10^5

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate