Skip to content

Latest commit

 

History

History
21 lines (19 loc) · 538 Bytes

1792.-maximum-average-pass-ratio.md

File metadata and controls

21 lines (19 loc) · 538 Bytes

1792. Maximum Average Pass Ratio

class Solution:
    def maxAverageRatio(self, classes: List[List[int]], e: int) -> float:
        ans = 0
        h = []
        for p , t in classes:
            ans += (p/t)
            h.append((-(t - p)/(t * (t + 1.0)), t, p))
        heapq.heapify(h)
        while e:
            v, t, p = heapq.heappop(h)
            ans -= v 
            t += 1
            p += 1
            heapq.heappush(h, (-(t - p)/(t * (t + 1.0)), t, p))
            e -= 1
        return ans/len(classes)