Maximum Score From Removing Stones
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.
func max(x, y int) int {
if x > y {
return x
}
return y
}
func min(x, y int) int {
if x < y {
return x
}
return y
}
func maximumScore(a int, b int, c int) int {
// can also use priority queue
sum := a + b + c
mx := max(a, max(b, c))
return min(sum - mx, sum / 2)
}