FPEvalRepoPublic/LeetCodeMetaData
0194
1{2 "id": 3654,3 "name": "minimum-array-sum",4 "difficulty": "Medium",5 "link": "https://leetcode.com/problems/minimum-array-sum/",6 "date": "2024-11-17",7 "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`",8 "test_case": [9 {10 "label": "Example 1",11 "input": "nums = [2,8,3,19,3], k = 3, op1 = 1, op2 = 1",12 "output": "23 "13 },14 {15 "label": "Example 2",16 "input": "nums = [2,4,3], k = 3, op1 = 2, op2 = 1",17 "output": "3 "18 }19 ],20 "constraints": [21 "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.",22 "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.",23 "Apply Operation 2 to nums[1] = 8, making nums[1] = 5.",24 "Apply Operation 1 to nums[3] = 19, making nums[3] = 10.",25 "The resulting array becomes [2, 5, 3, 10, 3], which has the minimum possible sum of 23 after applying the operations.",26 "Apply Operation 1 to nums[0] = 2, making nums[0] = 1.",27 "Apply Operation 1 to nums[1] = 4, making nums[1] = 2.",28 "Apply Operation 2 to nums[2] = 3, making nums[2] = 0.",29 "The resulting array becomes [1, 2, 0], which has the minimum possible sum of 3 after applying the operations.",30 "1 <= nums.length <= 100",31 "0 <= nums[i] <= 105",32 "0 <= k <= 105",33 "0 <= op1, op2 <= nums.length"34 ],35 "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 ",36 "java_template": "class Solution {\n public int minArraySum(int[] nums, int k, int op1, int op2) {\n \n }\n}",37 "metadata": {38 "func_name": "minArraySum"39 }40}