Minimum Sum 10

  • + 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)