1753. Maximum Score From Removing Stones Medium
1/**
2 * [1753] Maximum Score From Removing Stones
3 *
4 * 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).
5 * Given three integers a, b, and c, return the maximum score you can get.
6 *
7 * Example 1:
8 *
9 * Input: a = 2, b = 4, c = 6
10 * Output: 6
11 * Explanation: The starting state is (2, 4, 6). One optimal set of moves is:
12 * - Take from 1st and 3rd piles, state is now (1, 4, 5)
13 * - Take from 1st and 3rd piles, state is now (0, 4, 4)
14 * - Take from 2nd and 3rd piles, state is now (0, 3, 3)
15 * - Take from 2nd and 3rd piles, state is now (0, 2, 2)
16 * - Take from 2nd and 3rd piles, state is now (0, 1, 1)
17 * - Take from 2nd and 3rd piles, state is now (0, 0, 0)
18 * There are fewer than two non-empty piles, so the game ends. Total: 6 points.
19 *
20 * Example 2:
21 *
22 * Input: a = 4, b = 4, c = 6
23 * Output: 7
24 * Explanation: The starting state is (4, 4, 6). One optimal set of moves is:
25 * - Take from 1st and 2nd piles, state is now (3, 3, 6)
26 * - Take from 1st and 3rd piles, state is now (2, 3, 5)
27 * - Take from 1st and 3rd piles, state is now (1, 3, 4)
28 * - Take from 1st and 3rd piles, state is now (0, 3, 3)
29 * - Take from 2nd and 3rd piles, state is now (0, 2, 2)
30 * - Take from 2nd and 3rd piles, state is now (0, 1, 1)
31 * - Take from 2nd and 3rd piles, state is now (0, 0, 0)
32 * There are fewer than two non-empty piles, so the game ends. Total: 7 points.
33 *
34 * Example 3:
35 *
36 * Input: a = 1, b = 8, c = 8
37 * Output: 8
38 * Explanation: One optimal set of moves is to take from the 2nd and 3rd piles for 8 turns until they are empty.
39 * After that, there are fewer than two non-empty piles, so the game ends.
40 *
41 *
42 * Constraints:
43 *
44 * 1 <= a, b, c <= 10^5
45 *
46 */
47pub struct Solution {}
48
49// problem: https://leetcode.com/problems/maximum-score-from-removing-stones/
50// discuss: https://leetcode.com/problems/maximum-score-from-removing-stones/discuss/?currentPage=1&orderBy=most_votes&query=
51
52// submission codes start here
53
54impl Solution {
55 pub fn maximum_score(a: i32, b: i32, c: i32) -> i32 {
56 0
57 }
58}
59
60// submission codes end
61
62#[cfg(test)]
63mod tests {
64 use super::*;
65
66 #[test]
67 fn test_1753() {
68 }
69}
70
Back
© 2025 bowen.ge All Rights Reserved.