Minimum Sum 10

  • + 0 comments
    fun minSum(nums: Array<Int>, k: Int): Int {
    
        val maxHeap = PriorityQueue<Int>(reverseOrder())
        maxHeap.addAll(nums.toList())
     
        repeat(k) {   
          val maxElement = maxHeap.poll()
          val newElement = Math.ceil(maxElement.toDouble() / 2).toInt()
          maxHeap.offer(newElement)
        }
        return maxHeap.sum()
    }