Minimum Sum 10

Sort by

recency

|

3 Discussions

|

  • + 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()
    }
    
  • + 1 comment
    import heapq
    def minSum(num, k):
        num1 = [-i for i in num]
        heapq.heapify(num1)
        m = heapq.heappop(num1)
        for i in range(k):
            m = heapq.heappushpop(num1, m//2)
        return -1*(sum(num1)+m)
    
  • + 1 comment
    def minSum(num, k):
        num = sorted(num)
        queue = deque([])
        queue.append(math.ceil(num.pop()/2))
        
        for i in range(k-1):
            
            if len(num)==0:
                num=sorted(queue)
                queue=deque([])
                
            temp = num[-1]
            
            if len(queue)>0 and queue[0]>temp:
                t = queue.popleft()
                queue.append(math.ceil(t/2))    
            else:
                num.pop()
                queue.append(math.ceil(temp/2))
                
        return sum(queue)+sum(num)
    

No more comments