- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to find maximum score from removing stones in Python

Suppose we have three values a, b and c. We are playing a solitaire game with three piles of stones whose sizes are a, b, and c respectively. Each turn the player selects two different non-empty piles, take one stone from each, and add 1 point to his score. The game ends when there are fewer than two non-empty piles. So we have to find the maximum score you can get.

So, if the input is like a = 4, b = 4, c = 6, then the output will be 7 because the initial state is (4, 4, 6), then we can follow these steps −

Select from 1st and 2nd piles so current state is (3, 3, 6)

Select from 1st and 3rd piles so current state is (2, 3, 5)

Select from 1st and 3rd piles so current state is (1, 3, 4)

Select from 1st and 3rd piles so current state is (0, 3, 3)

Select from 2nd and 3rd piles so current state is (0, 2, 2)

Select from 2nd and 3rd piles so current state is (0, 1, 1)

Select from 2nd and 3rd piles so current state is (0, 0, 0)

And finally there are fewer than two non-empty piles, so the game ends.

To solve this, we will follow these steps −

minimum := minimum of a, b and c

maximum := maximum of a, b and c

left := a + b + c - maximum - minimum

if maximum-left <= minimum, then

return minimum + left - quotient of (1 + minimum - (maximum-left))/2

return minimum + (minimum of (maximum-minimum) and left)

## Example

Let us see the following implementation to get better understanding −

def solve(a, b, c): minimum = min(a,b,c) maximum = max(a,b,c) left = a+b+c-maximum-minimum if maximum-left<=minimum: return minimum + left-(1+minimum-(maximum-left))//2 return minimum + min(maximum-minimum,left) a = 4 b = 4 c = 6 print(solve(a, b, c))

## Input

4, 4, 6

## Output

7

- Related Questions & Answers
- Program to count maximum score from removing substrings in Python
- Program to find maximum score from performing multiplication operations in Python
- Program to find the maximum score from all possible valid paths in Python
- Program to find maximum score in stone game in Python
- Program to find maximum sum by removing K numbers from ends in python
- Program to find maximum additive score by deleting numbers in Python
- Program to find maximum score of brick removal game in Python
- Program to find maximum score of a good subarray in Python
- Python program to find word score from list of words
- Program to find maximum score we can get in jump game in Python
- Program to find how max score we can get by removing 10 or 01 from binary string in Python
- C++ code to find maximum stones we can pick from three heaps
- Program to find minimum cost to merge stones in Python
- Python program to find runner-up score
- C++ Program to find maximum score of bit removal game