 Simple and Understand the maxAverageRatio
** Proper Explanation for Each steps**Step 1: Priority Queue Initialization
A priority queue is created to store classes.
Classes are sorted based on how much t
###  ** Proper Explanation for Each steps**\n\n### **Step 1: Priority Queue Initialization**\n```java\nPriorityQueue<int[]> pq = new PriorityQueue<>((a, b) -> Double.compare(diff(b), diff(a)));\n```\n- A **priority queue** is created to store classes.\n- Classes are sorted based on how much their pass rate would improve if one extra student is added.\n- The class with the **highest improvement** comes first in the queue.\n\n---\n\n### **Step 2: Add All Classes to the Queue**\n```java\nfor (int[] cl : classes) pq.add(cl);\n```\n- Each class (represented as an array of `[pass, total]`) is added to the priority queue for evaluation.\n\n---\n\n### **Step 3: Distribute Extra Students**\n```java\nfor (int i = 0; i < extraStudents; i++) {\n    int[] next = pq.poll();\n    next[0]++;\n    next[1]++;\n    pq.add(next);\n}\n```\n- For each extra student:\n  - **Poll** the class with the highest improvement.\n  - **Update** the class by adding one more pass and one more total student.\n  - **Re-add** the updated class back to the queue.\n\n---\n\n### **Step 4: Calculate the Final Average Pass Rate**\n```java\ndouble sum = 0.0;\nwhile (!pq.isEmpty()) {\n    int[] next = pq.poll();\n    sum += (double) next[0] / next[1];\n}\nreturn sum / classes.length;\n```\n- After distributing all students:\n  - **Calculate** the pass rate for each class.\n  - **Sum** up all the pass rates.\n  - **Return** the average pass rate across all classes.\n\n---\n\n### **Helper Function: `diff`**\n```java\nprivate double diff(int[] a) {\n    return (double)(a[0] + 1) / (a[1] + 1) - (double) a[0] / a[1];\n}\n```\n- This function calculates the **improvement in pass rate** if one extra student is added to a class. \n\n---\n\nThis entire process ensures the **extra students** are distributed in a way that maximizes the overall pass rate across all classes.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n\n# Code\n```java []\nimport java.util.PriorityQueue;\n\nclass Solution {\n    public double maxAverageRatio(int[][] classes, int extraStudents) {\n        PriorityQueue<int[]> pq = new PriorityQueue<>((a, b) -> Double.compare(diff(b), diff(a)));\n        for (int[] cl : classes) pq.add(cl);\n\n        for (int i = 0; i < extraStudents; i++) {\n            int[] next = pq.poll();\n            next[0]++;\n            next[1]++;\n            pq.add(next);\n        }\n\n        double sum = 0.0;\n        while (!pq.isEmpty()) {\n            int[] next = pq.poll();\n            sum += (double) next[0] / next[1];\n        }\n        return sum / classes.length;\n    }\n\n    private double diff(int[] a) {\n        return (double)(a[0] + 1) / (a[1] + 1) - (double) a[0] / a[1];\n    }\n}\n\n```
['Java']