mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
52 lines
2.4 KiB
HTML
52 lines
2.4 KiB
HTML
<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>
|
||
<p><strong>Example 1:</strong></p>
|
||
|
||
<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>
|
||
|
||
<p><strong>Example 2:</strong></p>
|
||
|
||
<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>
|
||
|
||
<p><strong>Example 3:</strong></p>
|
||
|
||
<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>
|