1962. Remove Stones to Minimize the Total Medium

@problem@discussion
#Array#Heap (Priority Queue)



1/**
2 * [1962] Remove Stones to Minimize the Total
3 *
4 * You are given a 0-indexed integer array piles, where piles[i] represents the number of stones in the i^th pile, and an integer k. You should apply the following operation exactly k times:
5 * 
6 * 	Choose any piles[i] and remove floor(piles[i] / 2) stones from it.
7 * 
8 * Notice that you can apply the operation on the same pile more than once.
9 * Return the minimum possible total number of stones remaining after applying the k operations.
10 * floor(x) is the greatest integer that is smaller than or equal to x (i.e., rounds x down).
11 *  
12 * Example 1:
13 * 
14 * Input: piles = [5,4,9], k = 2
15 * Output: 12
16 * Explanation: Steps of a possible scenario are:
17 * - Apply the operation on pile 2. The resulting piles are [5,4,<u>5</u>].
18 * - Apply the operation on pile 0. The resulting piles are [<u>3</u>,4,5].
19 * The total number of stones in [3,4,5] is 12.
20 * 
21 * Example 2:
22 * 
23 * Input: piles = [4,3,6,7], k = 3
24 * Output: 12
25 * Explanation: Steps of a possible scenario are:
26 * - Apply the operation on pile 2. The resulting piles are [4,3,<u>3</u>,7].
27 * - Apply the operation on pile 3. The resulting piles are [4,3,3,<u>4</u>].
28 * - Apply the operation on pile 0. The resulting piles are [<u>2</u>,3,3,4].
29 * The total number of stones in [2,3,3,4] is 12.
30 * 
31 *  
32 * Constraints:
33 * 
34 * 	1 <= piles.length <= 10^5
35 * 	1 <= piles[i] <= 10^4
36 * 	1 <= k <= 10^5
37 * 
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/remove-stones-to-minimize-the-total/
42// discuss: https://leetcode.com/problems/remove-stones-to-minimize-the-total/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47    pub fn min_stone_sum(piles: Vec<i32>, k: i32) -> i32 {
48        0
49    }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56    use super::*;
57
58    #[test]
59    fn test_1962() {
60    }
61}
62


Back
© 2025 bowen.ge All Rights Reserved.