Maximum Score From Removing Stones - Problem
Imagine you're playing a strategic stone removal game with three piles of stones containing a, b, and c stones respectively.
The rules are simple but require strategy:
- Each turn, you must choose two different non-empty piles
- Remove exactly one stone from each of the chosen piles
- Earn 1 point for each successful move
- The game ends when you have fewer than two non-empty piles remaining
Your goal is to maximize your score by making optimal moves. The key insight is that you want to keep playing as long as possible, which means balancing the piles strategically.
Example: With piles [2, 4, 6], you could potentially make up to 6 moves by always picking stones from the two largest piles, resulting in a maximum score of 6.
Input & Output
example_1.py โ Basic Case
$
Input:
a = 2, b = 4, c = 6
โบ
Output:
6
๐ก Note:
Total stones = 12. Max pile = 6, others = 6. Since 6 โค 6, we can make 12/2 = 6 moves. Optimal strategy: always pick from the two largest piles.
example_2.py โ Imbalanced Case
$
Input:
a = 4, b = 4, c = 2
โบ
Output:
4
๐ก Note:
Total stones = 10. Max pile = 4, others = 6. Since 4 โค 6, we can make 10/2 = 5 moves... wait, let's verify: (4,4,2) โ (3,3,2) โ (2,2,2) โ (1,1,2) โ (0,0,2). Actually 4 moves, limited by balance.
example_3.py โ Edge Case
$
Input:
a = 1, b = 8, c = 8
โบ
Output:
8
๐ก Note:
Total stones = 17. Max pile = 8, others = 9. Since 8 โค 9, we can make 17/2 = 8 moves (integer division). The large pile doesn't dominate completely.
Constraints
- 0 โค a, b, c โค 105
- At least one pile must be non-empty
- Time limit: 1 second per test case
Visualization
Tap to expand
Understanding the Visualization
1
Identify the Strategy
Always remove from the two largest piles to maximize game duration
2
Check for Limitations
Determine if one pile is so large it limits our total moves
3
Calculate Maximum
Use the mathematical formula to get the answer instantly
Key Takeaway
๐ฏ Key Insight: Always pick from the two largest piles to maximize the number of moves. The mathematical formula gives us the answer instantly without simulation.
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code