<p>You are given an array <code>nums</code> of positive integers. In one operation, you can choose <strong>any</strong> number from <code>nums</code> and reduce it to <strong>exactly</strong> half the number. (Note that you may choose this reduced number in future operations.)</p>

<p>Return<em> the <strong>minimum</strong> number of operations to reduce the sum of </em><code>nums</code><em> by <strong>at least</strong> half.</em></p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [5,19,8,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The initial sum of nums is equal to 5 + 19 + 8 + 1 = 33.
The following is one of the ways to reduce the sum by at least half:
Pick the number 19 and reduce it to 9.5.
Pick the number 9.5 and reduce it to 4.75.
Pick the number 8 and reduce it to 4.
The final array is [5, 4.75, 4, 1] with a total sum of 5 + 4.75 + 4 + 1 = 14.75. 
The sum of nums has been reduced by 33 - 14.75 = 18.25, which is at least half of the initial sum, 18.25 &gt;= 33/2 = 16.5.
Overall, 3 operations were used so we return 3.
It can be shown that we cannot reduce the sum by at least half in less than 3 operations.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [3,8,20]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The initial sum of nums is equal to 3 + 8 + 20 = 31.
The following is one of the ways to reduce the sum by at least half:
Pick the number 20 and reduce it to 10.
Pick the number 10 and reduce it to 5.
Pick the number 3 and reduce it to 1.5.
The final array is [1.5, 8, 5] with a total sum of 1.5 + 8 + 5 = 14.5. 
The sum of nums has been reduced by 31 - 14.5 = 16.5, which is at least half of the initial sum, 16.5 &gt;= 31/2 = 15.5.
Overall, 3 operations were used so we return 3.
It can be shown that we cannot reduce the sum by at least half in less than 3 operations.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= nums[i] &lt;= 10<sup>7</sup></code></li>
</ul>

class Solution:
    def halveArray(self, nums: List[int]) -> int:
        
        summ = 0
        op = 0
        a = [i*-1 for i in nums]
        heapq.heapify(a)

        for i in nums:
            summ += i

        halfsum = summ

        for index in range(len(nums)):

            num = heapq.heappop(a) * -1
            halfsum = halfsum - num/2.0
            heapq.heappush(a, num/2.0 * -1)
            op += 1

            if halfsum <= summ/2.0:
                return op

        return op

        

        # nums.sort(reverse=True)
        # summ = 0
        # index = 0
        # op = 0

        # # Get the sum
        # for i in nums:
        #     summ += i
        # print(summ)

        # summ1 = summ

        # while index < len(nums)-1:

        #     print(nums)
        #     halfsum = summ1 - nums[index]/2.0
        #     summ1 -= nums[index]/2.0
        #     nums[index] /= 2.0

        #     print(halfsum)
        #     if nums[index] < nums[index+1]:
        #         if index != 0 and nums[index - 1] > nums[index + 1]:
        #             index-=1
        #         else:
        #             index += 1

        #     op += 1

        #     if halfsum < summ/2.0:
        #         return op

        # return op



    #     op = 0
        
    #     index, number, summ = self.maximum(nums)
    #     halfsum = summ - number/2.0
    #     # print(halfsum ,summ , number)

    #     while halfsum > summ/2.0:
    #         op += 1
    #         nums[index] = number/2.0
    #         # print(halfsum ,summ , number)
    #         index, number, halfsum = self.maximum(nums)
            
            
    #     return op

    # def maximum(self, nums):

    #     summ = nums[0]
    #     maxi = nums[0]
    #     i = 0
    #     for index in range(1,len(nums)):
    #         if maxi < nums[index]:
    #             maxi = nums[index]
    #             i = index
    #         summ += nums[index]

    #     return (i,maxi, summ)


    #     # for i in nums:
    #     #     halfsum += i/2.0
    #     #     op += 1
            
    #     #     print(halfsum + summ - i)
    #     #     if halfsum + summ - i < summ/2:
    #     #         return op
        
    #     return op
841