Using PriorityQueue || O(K logn)
IntuitionUse PriorityQueue to get next best pass, total after using each of extraStudent.ApproachPriorityQueue is used to store nextPassRatioDiff i.e. (pass + 1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse PriorityQueue to get next best pass, total after using each of extraStudent.\n\n---\n\n---\n\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nPriorityQueue is used to store nextPassRatioDiff i.e. (pass + 1) / (total + 1) - (pass / total). This tells us what will be next best class to add new student.\n\n---\n\n---\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    O(n) + O(K logn) + O(n) = O(K logn)\n**K = 2** times the extraStudents.\nAnd, **logn** for offering or polling from the heap.\n\n---\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    O(n)   \nFor PriorityQueue.\n\n---\n\n\n---\n\n\n# Code\n```java []\nclass Solution {\n    public static double nextPassRatioDiff(double pass, double total){\n        return (pass + 1) / (total + 1) - (pass / total);\n    }\n\n\n    public double maxAverageRatio(int[][] classes, int extraStudents) {\n        int n = classes.length;\n        PriorityQueue<double[] > maxHeap = new PriorityQueue<>((a, b) -> Double.compare(b[0], a[0]));\n        //entry = {nextPassRatioDiff, pass, total}\n        for(int[] arr: classes){\n            int pass = arr[0];\n            int total = arr[1];\n            double next = nextPassRatioDiff(pass, total);\n            maxHeap.offer(new double[]{next, pass, total});\n        }\n        while(extraStudents > 0){\n            double[] top= maxHeap.poll();\n            double pass = top[1] + 1;\n            double total = top[2] + 1;\n            double next = nextPassRatioDiff(pass, total);\n            maxHeap.offer(new double[]{next, pass, total});\n            extraStudents--;\n        }\n        double totalPassRatio = 0;\n        while(!maxHeap.isEmpty()){\n            double[] arr = maxHeap.poll();\n            double pass = arr[1];\n            double total = arr[2];\n            totalPassRatio += (pass / total);\n        }\n        return totalPassRatio / n;\n    }\n\n}\n```
['Array', 'Greedy', 'Heap (Priority Queue)', 'Java']