Java | O(mlogn) | Heap, Greedy | Small code
\nclass Solution {\n    public double maxAverageRatio(int[][] classes, int extraStudents) {\n        double sum=0;\n        PriorityQueue<int[]> pq = new Priori
```\nclass Solution {\n    public double maxAverageRatio(int[][] classes, int extraStudents) {\n        double sum=0;\n        PriorityQueue<int[]> pq = new PriorityQueue<>((a,b)->Double.compare((double)(b[0]+1)/(b[1]+1)-(double)b[0]/b[1],(double)(a[0]+1)/(a[1]+1)-(double)a[0]/a[1]));\n        for(int[] c: classes){\n            pq.add(c);\n            sum+=(double)c[0]/c[1];\n        }\n        \n        while(extraStudents > 0){\n            int[] c = pq.poll();\n            pq.add(new int[]{c[0]+1,c[1]+1});\n            double change = (double)(c[0]+1)/(c[1]+1)-(double)c[0]/c[1];\n            sum += change;\n            extraStudents--;\n        }\n        return sum/classes.length;\n    }\n}\n```
['Greedy', 'Heap (Priority Queue)']