I am working on a leetcode problem 1962 in which i have used heapq._heapify_max(list) function and found it is not working properly
I tried directly popping the elements max heapq with the function heapq.heappop(list) but it gives me max element only on the first pop and returns min elements for the remaining. So i have also tried the function heapq._heappop_max(list) but this also returns me max elements only on first two times of popping and min elements for remaining time. Can someone explain me why this is happening. this is my code
class Solution:
def minStoneSum(self, piles: List[int], k: int) -> int:
heapq._heapify_max(piles)
for _ in range(k):
x = heapq._heappop_max(piles)
print(x)
heapq.heappush(piles, (x // 2) if (x % 2 == 0) else (x // 2 + 1))
return sum(piles)