[Python] Clear Greedy+Heap Solution with Video Explanation
Video with clear visualization and explanation:\nhttps://youtu.be/TIn0wbbJDVs\n\n\n\nIntuition: Greedy+Heap\n \n\nCode\n\nfrom heapq import *\n\nclass Solution:
Video with clear visualization and explanation:\nhttps://youtu.be/TIn0wbbJDVs\n\n\n\nIntuition: Greedy+Heap\n \n\n**Code**\n```\nfrom heapq import *\n\nclass Solution:\n    def maxAverageRatio(self, classes: List[List[int]], extraStudents: int) -> float:\n        heap = []\n        \n        for p, t in classes:\n            delta = ((p+1)/(t+1))-(p/t)\n            heappush(heap, (-delta, p, t))\n        \n        for _ in range(extraStudents):\n            delta, p, t = heappop(heap)\n            p += 1\n            t += 1\n            delta_new = ((p+1)/(t+1))-(p/t)\n            heappush(heap, (-delta_new, p, t))\n            \n        res = sum(p/t for delta, p, t in heap)/len(heap)\n        return res\n```\n\n\n\nTime: O(n+klogn) / Space: O(n)\n\n\nFeel free to subscribe to my channel. More LeetCoding videos coming up!
['Python']