Python [greedy]
In this question we want to modify ratios r1, r2, ..., rn such that (r1 + r2 + ... + rn) / n is maximized. As n is common, equivalently maximize (r1 + r2 + ... 
In this question we want to modify ratios `r1, r2, ..., rn` such that `(r1 + r2 + ... + rn) / n` is maximized. As `n` is common, equivalently maximize `(r1 + r2 + ... + rn)`.\n\nSuppose that we only have 1 extra student. We should choose the ratio `ri = xi/yi` such that the difference `(xi+1)/(yi+1) - xi/yi` is maximum. Suppose that this is true for `k` extra students. If we have a `k+1`-st student, then we should once again find the ratio such that the above target difference is maximized. It then follows from the Principle of Induction that this stepwise approach is optimal for all values of `extraStudents`.\n\nThis is now nothing but a greedy solution. We can easily code using a max heap.\n\n```python\nclass Solution:\n    def maxAverageRatio(self, classes, extraStudents):\n        hp = []\n        for x, y in classes:\n            target_difference = (x+1)/(y+1) - x/y\n            heapq.heappush(hp, (-target_difference, x, y))\n        \n        for _ in range(extraStudents):\n            _, x, y = heapq.heappop(hp)\n            target_difference = (x+2)/(y+2) - (x+1)/(y+1)\n            heapq.heappush(hp, (-target_difference, x+1, y+1))\n        \n        ans = 0\n        while hp:\n            _, x, y = heapq.heappop(hp)\n            ans += x / y / len(classes)\n        return ans\n```
[]