🚀Beats 99%, Python3, Heap, easy to understand🚀
Complexity
Time complexity: O(nlogn)

Space complexity: O(n)
Code
# Complexity\n- Time complexity: O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Solution:\n    def maxAverageRatio(self, classes: List[List[int]], extraStudents: int) -> float:\n        def possible_gain(passed, total):\n            return (passed + 1) / (total + 1) - passed / total\n\n        max_heap = []\n        pass_rate_sum = 0.0\n\n        for passed, total in classes:\n            pass_rate_sum += passed / total\n            heapq.heappush(max_heap, (-possible_gain(passed, total), passed, total))\n\n        for _ in range(extraStudents):\n            current_gain, passed, total = heapq.heappop(max_heap)\n            pass_rate_sum += -current_gain\n            passed, total = passed + 1, total + 1\n            heapq.heappush(max_heap, (-possible_gain(passed, total), passed, total))\n\n        return pass_rate_sum / len(classes)\n```
['Heap (Priority Queue)', 'Python3']