TheRealSamuel/LeetCodeProblem
0564
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 00:00:00",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 "public_test_cases": [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 "private_test_cases": [21 {22 "input": [23 [24 0,25 6,26 8,27 16,28 17,29 13,30 17,31 18,32 20,33 20,34 20,35 21,36 34,37 35,38 5,39 6,40 12,41 16,42 16,43 1644 ],45 73,46 11,47 1148 ],49 "output": 31650 },51 {52 "input": [53 [54 2,55 3,56 6,57 8,58 8,59 8,60 9,61 10,62 13,63 14,64 15,65 16,66 16,67 18,68 19,69 22,70 23,71 24,72 25,73 27,74 27,75 27,76 27,77 28,78 30,79 35,80 35,81 37,82 37,83 38,84 39,85 44,86 46,87 23,88 24,89 24,90 25,91 25,92 26,93 28,94 28,95 28,96 28,97 29,98 29,99 29,100 29,101 30,102 31,103 31,104 33,105 34,106 34,107 34,108 35,109 35,110 36,111 36,112 38,113 39,114 39,115 42,116 43,117 1,118 2,119 2,120 4,121 5,122 7,123 8,124 8,125 12,126 12,127 14,128 17,129 18,130 18131 ],132 87,133 30,134 57135 ],136 "output": 1809137 },138 {139 "input": [140 [141 0,142 0,143 0,144 1,145 3,146 3,147 4,148 5,149 5,150 7,151 10,152 11,153 12,154 14,155 15,156 17,157 18,158 9,159 10,160 10,161 12,162 14,163 14,164 15,165 15,166 16,167 16,168 16,169 17,170 17,171 18,172 19,173 1,174 1,175 2,176 3,177 22,178 23,179 23,180 24,181 24,182 24,183 24,184 25,185 25,186 26,187 27,188 27,189 29,190 29,191 31,192 31,193 31,194 31,195 33,196 33,197 33,198 34,199 34,200 36,201 37,202 37,203 38,204 38,205 38,206 39,207 39,208 39,209 0,210 0,211 1,212 2,213 3,214 3,215 3,216 3,217 3,218 4,219 4,220 5,221 5,222 5,223 6,224 6,225 6,226 6,227 7,228 7,229 9,230 10,231 10,232 10,233 11,234 11,235 12,236 12,237 12238 ],239 40,240 76,241 33242 ],243 "output": 1510244 },245 {246 "input": [247 [248 5,249 5,250 4,251 5,252 7,253 8,254 9,255 12,256 13,257 14,258 16,259 18,260 19,261 19,262 22,263 23,264 24,265 24,266 26,267 27,268 28,269 28,270 29,271 30,272 34,273 36,274 37,275 37,276 41,277 42,278 42,279 45,280 46,281 48,282 3,283 3,284 4,285 4286 ],287 98,288 35,289 10290 ],291 "output": 837292 },293 {294 "input": [295 [296 4,297 13,298 14,299 17,300 18,301 21,302 24,303 25,304 1,305 2,306 4,307 7,308 37,309 37,310 41,311 43,312 43,313 53,314 54,315 60,316 63,317 69,318 76,319 77,320 81,321 84,322 84,323 85,324 85,325 87,326 89,327 89,328 92,329 96,330 96331 ],332 26,333 0,334 4335 ],336 "output": 1771337 },338 {339 "input": [340 [341 16,342 33,343 83,344 90,345 101346 ],347 12,348 0,349 2350 ],351 "output": 323352 },353 {354 "input": [355 [356 2,357 3,358 3,359 7,360 8,361 8,362 8,363 10,364 7,365 7,366 8,367 8,368 12,369 14,370 15,371 15,372 16,373 17,374 21,375 23,376 25,377 26,378 26,379 27,380 28,381 28,382 28,383 28,384 28,385 29,386 31,387 31,388 35,389 36,390 37,391 37,392 37,393 41,394 41,395 42,396 42,397 42,398 45,399 47,400 48,401 49,402 51,403 22,404 22,405 23406 ],407 30,408 42,409 3410 ],411 "output": 1244412 },413 {414 "input": [415 [416 2,417 3,418 4,419 5,420 6,421 6,422 7,423 8,424 8,425 8,426 9,427 10,428 12,429 12,430 13,431 13,432 13,433 15,434 16,435 17,436 17,437 0,438 1,439 2,440 2,441 5,442 6,443 7,444 8,445 9,446 9,447 10,448 10,449 11,450 11,451 11,452 12,453 13,454 15,455 16,456 17,457 0,458 0,459 2,460 2,461 2,462 2,463 3,464 4,465 6,466 7,467 8,468 8,469 10,470 10,471 11,472 12,473 12,474 13,475 14,476 16,477 16,478 16479 ],480 35,481 62,482 43483 ],484 "output": 553485 },486 {487 "input": [488 [489 0,490 2,491 6,492 6,493 9,494 13,495 14,496 24,497 4,498 6,499 7,500 7,501 11,502 12,503 14,504 15,505 18,506 19,507 22,508 23,509 23,510 24,511 25,512 26,513 30,514 30,515 31,516 34,517 36,518 37,519 39,520 43,521 43,522 44,523 45524 ],525 8,526 27,527 32528 ],529 "output": 742530 },531 {532 "input": [533 [534 0,535 1,536 2,537 2,538 6,539 7,540 7,541 9,542 12,543 19,544 19,545 21,546 23,547 25,548 29,549 31,550 31,551 34,552 19,553 19,554 20,555 21,556 21,557 22,558 23,559 1,560 6,561 8,562 10,563 14,564 18,565 19,566 34,567 35,568 35,569 36,570 36,571 39,572 40,573 41,574 41,575 44,576 44,577 44,578 45,579 0,580 1,581 4,582 6583 ],584 47,585 24,586 11587 ],588 "output": 1024589 }590 ],591 "haskell_template": "minArraySum :: [Int] -> Int -> Int -> Int -> Int\nminArraySum nums k op1 op2 ",592 "ocaml_template": "let minArraySum (nums: int list) (k: int) (op1: int) (op2: int) : int = ",593 "scala_template": "def minArraySum(nums: List[Int],k: Int,op1: Int,op2: Int): Int = { \n \n}",594 "java_template": "class Solution {\n public int minArraySum(int[] nums, int k, int op1, int op2) {\n \n }\n}",595 "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 "596}