Best Solution You will ever see in Hinenglish
SochDekho Question keh rha hain ki har ek student kaisa add kara taka avergae max ho jai. Toh agr sum max kar denga toh avg bhi max ho jaiga
Aur sum max ke lia
# Soch\nDekho Question keh rha hain ki har ek student kaisa add kara taka avergae max ho jai. Toh agr sum max kar denga toh avg bhi max ho jaiga \nAur sum max ke lia unn ratio mein students add karo jo sum ko maximize karai\nPehla thought aayga DP karloo jissa ya toh iss student pe dalo ya mat daloo\nBut constraints dekho pta chalaga ki not possible DP \nSo kooch greedy hoga\nOkay ab ratios ke term mein socho\nagr a/b ratio mein apan ek student ko add karta hain toh ratio (a+1)/(b+1) hoga.\nAur jo humara sum hain voh (a+1)/(b+1)-a/b se increase karaga toh agr apan har sami iss ko max kara with priority queue then humara final ratio bhi max hoga.\nHence bas itna sochna tha iss lia greedy work karaga.\n\n# Code\n```python3 []\nclass Solution:\n    def maxAverageRatio(self, classes: List[List[int]], extraStudents: int) -> float:\n        temp=[]\n        for a,b in classes:\n            ratio=(a-b)/((b)*(b+1))\n            heapq.heappush(temp,[ratio,a,b])\n        while extraStudents>0:\n            ratio,a,b=heapq.heappop(temp)\n            a=a+1\n            b=b+1\n            extraStudents-=1\n            ratio=(a-b)/((b)*(b+1))\n            heapq.heappush(temp,[ratio,a,b])\n        ans=0.00000\n        #print(temp)\n        while temp:\n            _,a,b=heapq.heappop(temp)\n            ans+=a/b\n        return ans/len(classes)\n\n```
['Python3']