Maximum Number of Eaten Apples LeetCode solution in Python
1import heapq234class Solution(object):5def eatenApples(self, apples, days):6"""7:type apples: List[int]8:type days: List[int]9:rtype: int10"""11heap = [(days[0], apples[0])]12heapq.heapify(heap)13day = 014rtn = 015while heap or day < len(days):16# print(heap, day)17apple = 018if heap:19cnt, apple = heapq.heappop(heap)20while heap and cnt <= day and apple > 0:21cnt, apple = heapq.heappop(heap)22if apple > 0 and cnt > day:23rtn += 124day += 125if apple > 1 and cnt > day:26heapq.heappush(heap, (cnt, apple - 1))27if day < len(days) and apples[day] > 0:28heapq.heappush(heap, (day + days[day], apples[day]))29return rtn