Given an array of integers, perform some number k of oeprations. Each operation consists of removing any element from the array, dividing it by 2 and inserting the ceiling of that result back into the array. Minimize the sum of the elements in the final array.

Example:

nums = [10, 20, 7]
k = 4

Pick Pick/2 Ceiling Result
Initial Array [10, 20, 7]
7 3.5 4 [10, 20, 4]
10 5 5 [5, 20, 4]
20 10 10 [5, 10, 4]
10 5 5 [5, 5, 4]

The sum of the final array is 5 + 5 + 4 = 14, and that sum is the minimal.

Function Description

Complete the function minSum in the editor below. The function must return an integer denoting the minimum sum of the array after k steps.

minSum has the following parameters:

  • int nums[n]: an array of integers, indexed 0 to n-1
  • int k: an integer

Constraints

  • 1 <= n <= 10^5
  • 1 <= num[i] <= 10^4 (where 0 <= i < n)
  • 1 <= k <= 10^7
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.