3366. Minimum Array Sum Medium

@problem@discussion
#Array#Dynamic Programming



1/**
2 * [3366] Minimum Array Sum
3 *
4 * You are given an integer array nums and three integers k, op1, and op2.
5 * You can perform the following operations on nums:
6 * 
7 * 	Operation 1: Choose an index i and divide nums[i] by 2, rounding up to the nearest whole number. You can perform this operation at most op1 times, and not more than once per index.
8 * 	Operation 2: Choose an index i and subtract k from nums[i], but only if nums[i] is greater than or equal to k. You can perform this operation at most op2 times, and not more than once per index.
9 * 
10 * Note: Both operations can be applied to the same index, but at most once each.
11 * Return the minimum possible sum of all elements in nums after performing any number of operations.
12 *  
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">nums = [2,8,3,19,3], k = 3, op1 = 1, op2 = 1</span>
16 * Output: <span class="example-io">23</span>
17 * Explanation:
18 * 
19 * 	Apply Operation 2 to nums[1] = 8, making nums[1] = 5.
20 * 	Apply Operation 1 to nums[3] = 19, making nums[3] = 10.
21 * 	The resulting array becomes [2, 5, 3, 10, 3], which has the minimum possible sum of 23 after applying the operations.
22 * </div>
23 * <strong class="example">Example 2:
24 * <div class="example-block">
25 * Input: <span class="example-io">nums = [2,4,3], k = 3, op1 = 2, op2 = 1</span>
26 * Output: <span class="example-io">3</span>
27 * Explanation:
28 * 
29 * 	Apply Operation 1 to nums[0] = 2, making nums[0] = 1.
30 * 	Apply Operation 1 to nums[1] = 4, making nums[1] = 2.
31 * 	Apply Operation 2 to nums[2] = 3, making nums[2] = 0.
32 * 	The resulting array becomes [1, 2, 0], which has the minimum possible sum of 3 after applying the operations.
33 * </div>
34 *  
35 * Constraints:
36 * 
37 * 	1 <= nums.length <= 100
38 * 	<font face="monospace">0 <= nums[i] <= 10^5</font>
39 * 	0 <= k <= 10^5
40 * 	0 <= op1, op2 <= nums.length
41 * 
42 */
43pub struct Solution {}
44
45// problem: https://leetcode.com/problems/minimum-array-sum/
46// discuss: https://leetcode.com/problems/minimum-array-sum/discuss/?currentPage=1&orderBy=most_votes&query=
47
48// submission codes start here
49
50impl Solution {
51    pub fn min_array_sum(nums: Vec<i32>, k: i32, op1: i32, op2: i32) -> i32 {
52        0
53    }
54}
55
56// submission codes end
57
58#[cfg(test)]
59mod tests {
60    use super::*;
61
62    #[test]
63    fn test_3366() {
64    }
65}
66


Back
© 2025 bowen.ge All Rights Reserved.