Java PriorityQueue
\nclass Solution {\n    public double maxAverageRatio(int[][] classes, int extraStudents) {\n        PriorityQueue<int[]> queue = new PriorityQueue<>(new Cmp())
```\nclass Solution {\n    public double maxAverageRatio(int[][] classes, int extraStudents) {\n        PriorityQueue<int[]> queue = new PriorityQueue<>(new Cmp());\n        for(int[] c: classes) queue.offer(c);   // add all to priority queue\n        for(;extraStudents > 0;extraStudents--) {    // add extra student to class that will max increase the average\n            int[] c = queue.poll();\n            c[0]++; c[1]++;\n            queue.offer(c);\n        }\n        double result =0;\n        while(!queue.isEmpty()) {       // Calculate sum of pass ratios\n            int[] c = queue.poll();\n            result += (double)c[0]/c[1];\n        }\n        return result/classes.length;    // return average\n    }\n}\nclass Cmp implements Comparator<int[]> {  // to sort in descending order of diff when 1 is added to class\n    public int compare(int[] x, int[] y) {\n        double xDiff = (double)(x[0]+1)/(x[1]+1) - (double)x[0]/x[1], yDiff = (double)(y[0]+1)/(y[1]+1) - (double)y[0]/y[1];\n        return xDiff > yDiff? -1 : 1;\n    }\n}\n```
[]