1792. Maximum Average Pass Ratio

class Solution:
    def maxAverageRatio(self, classes: List[List[int]], extraStudents: int) -> float:
        def calcGain(studs, total):
            return  -1 * ((studs + 1) / (total + 1) -  studs / total)

        ratios = [(calcGain(x[0], x[1]), x) for x in classes]
        heapq.heapify(ratios)

        while extraStudents:
            first = heapq.heappop(ratios)
            newData = [first[1][0] + 1, first[1][1] + 1]
            newRatio = calcGain(newData[0], newData[1])
            newValue = (newRatio, newData)
            heapq.heappush(ratios, newValue)
            extraStudents -= 1


        total = 0
        for e in ratios:
            total += e[1][0] / e[1][1]

        return (total / len(classes))

        return 0