{ "id": 3654, "name": "minimum_array_sum", "difficulty": "Medium", "link": "https://leetcode.com/problems/minimum-array-sum/", "date": "2024-11-17 00:00:00", "task_description": "You are given an integer array `nums` and three integers `k`, `op1`, and `op2`. You can perform the following operations on `nums`: **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. **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. **Note:** Both operations can be applied to the same index, but at most once each. Return the **minimum** possible **sum** of all elements in `nums` after performing any number of operations. **Example 1:** **Input:** nums = [2,8,3,19,3], k = 3, op1 = 1, op2 = 1 **Output:** 23 **Explanation:** Apply Operation 2 to `nums[1] = 8`, making `nums[1] = 5`. Apply Operation 1 to `nums[3] = 19`, making `nums[3] = 10`. The resulting array becomes `[2, 5, 3, 10, 3]`, which has the minimum possible sum of 23 after applying the operations. **Example 2:** **Input:** nums = [2,4,3], k = 3, op1 = 2, op2 = 1 **Output:** 3 **Explanation:** Apply Operation 1 to `nums[0] = 2`, making `nums[0] = 1`. Apply Operation 1 to `nums[1] = 4`, making `nums[1] = 2`. Apply Operation 2 to `nums[2] = 3`, making `nums[2] = 0`. The resulting array becomes `[1, 2, 0]`, which has the minimum possible sum of 3 after applying the operations. **Constraints:** `1 <= nums.length <= 100` `0 <= nums[i] <= 105` `0 <= k <= 105` `0 <= op1, op2 <= nums.length`", "public_test_cases": [ { "label": "Example 1", "input": "nums = [2,8,3,19,3], k = 3, op1 = 1, op2 = 1", "output": "23 " }, { "label": "Example 2", "input": "nums = [2,4,3], k = 3, op1 = 2, op2 = 1", "output": "3 " } ], "private_test_cases": [ { "input": [ [ 0, 6, 8, 16, 17, 13, 17, 18, 20, 20, 20, 21, 34, 35, 5, 6, 12, 16, 16, 16 ], 73, 11, 11 ], "output": 316 }, { "input": [ [ 2, 3, 6, 8, 8, 8, 9, 10, 13, 14, 15, 16, 16, 18, 19, 22, 23, 24, 25, 27, 27, 27, 27, 28, 30, 35, 35, 37, 37, 38, 39, 44, 46, 23, 24, 24, 25, 25, 26, 28, 28, 28, 28, 29, 29, 29, 29, 30, 31, 31, 33, 34, 34, 34, 35, 35, 36, 36, 38, 39, 39, 42, 43, 1, 2, 2, 4, 5, 7, 8, 8, 12, 12, 14, 17, 18, 18 ], 87, 30, 57 ], "output": 1809 }, { "input": [ [ 0, 0, 0, 1, 3, 3, 4, 5, 5, 7, 10, 11, 12, 14, 15, 17, 18, 9, 10, 10, 12, 14, 14, 15, 15, 16, 16, 16, 17, 17, 18, 19, 1, 1, 2, 3, 22, 23, 23, 24, 24, 24, 24, 25, 25, 26, 27, 27, 29, 29, 31, 31, 31, 31, 33, 33, 33, 34, 34, 36, 37, 37, 38, 38, 38, 39, 39, 39, 0, 0, 1, 2, 3, 3, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 9, 10, 10, 10, 11, 11, 12, 12, 12 ], 40, 76, 33 ], "output": 1510 }, { "input": [ [ 5, 5, 4, 5, 7, 8, 9, 12, 13, 14, 16, 18, 19, 19, 22, 23, 24, 24, 26, 27, 28, 28, 29, 30, 34, 36, 37, 37, 41, 42, 42, 45, 46, 48, 3, 3, 4, 4 ], 98, 35, 10 ], "output": 837 }, { "input": [ [ 4, 13, 14, 17, 18, 21, 24, 25, 1, 2, 4, 7, 37, 37, 41, 43, 43, 53, 54, 60, 63, 69, 76, 77, 81, 84, 84, 85, 85, 87, 89, 89, 92, 96, 96 ], 26, 0, 4 ], "output": 1771 }, { "input": [ [ 16, 33, 83, 90, 101 ], 12, 0, 2 ], "output": 323 }, { "input": [ [ 2, 3, 3, 7, 8, 8, 8, 10, 7, 7, 8, 8, 12, 14, 15, 15, 16, 17, 21, 23, 25, 26, 26, 27, 28, 28, 28, 28, 28, 29, 31, 31, 35, 36, 37, 37, 37, 41, 41, 42, 42, 42, 45, 47, 48, 49, 51, 22, 22, 23 ], 30, 42, 3 ], "output": 1244 }, { "input": [ [ 2, 3, 4, 5, 6, 6, 7, 8, 8, 8, 9, 10, 12, 12, 13, 13, 13, 15, 16, 17, 17, 0, 1, 2, 2, 5, 6, 7, 8, 9, 9, 10, 10, 11, 11, 11, 12, 13, 15, 16, 17, 0, 0, 2, 2, 2, 2, 3, 4, 6, 7, 8, 8, 10, 10, 11, 12, 12, 13, 14, 16, 16, 16 ], 35, 62, 43 ], "output": 553 }, { "input": [ [ 0, 2, 6, 6, 9, 13, 14, 24, 4, 6, 7, 7, 11, 12, 14, 15, 18, 19, 22, 23, 23, 24, 25, 26, 30, 30, 31, 34, 36, 37, 39, 43, 43, 44, 45 ], 8, 27, 32 ], "output": 742 }, { "input": [ [ 0, 1, 2, 2, 6, 7, 7, 9, 12, 19, 19, 21, 23, 25, 29, 31, 31, 34, 19, 19, 20, 21, 21, 22, 23, 1, 6, 8, 10, 14, 18, 19, 34, 35, 35, 36, 36, 39, 40, 41, 41, 44, 44, 44, 45, 0, 1, 4, 6 ], 47, 24, 11 ], "output": 1024 } ], "haskell_template": "minArraySum :: [Int] -> Int -> Int -> Int -> Int\nminArraySum nums k op1 op2 ", "ocaml_template": "let minArraySum (nums: int list) (k: int) (op1: int) (op2: int) : int = ", "scala_template": "def minArraySum(nums: List[Int],k: Int,op1: Int,op2: Int): Int = { \n \n}", "java_template": "class Solution {\n public int minArraySum(int[] nums, int k, int op1, int op2) {\n \n }\n}", "python_template": "class Solution(object):\n def minArraySum(self, nums, k, op1, op2):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :type op1: int\n :type op2: int\n :rtype: int\n \"\"\"\n " }