**easy understandable soln**
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    double maxAverageRatio(vector<vector<int>>& classes, int extraStudents) {
        
        auto calcGain = [](int pass, int total) -> double {
            return (double)(pass + 1) / (total + 1) - (double)pass / total;
        };

        
        priority_queue<pair<double, pair<int, int>>> pq;

        
        for (const auto& cls : classes) {
            int pass = cls[0], total = cls[1];
            pq.push({calcGain(pass, total), {pass, total}});
        }

        
        while (extraStudents > 0) {
            auto [gain, cls] = pq.top();
            pq.pop();
            int pass = cls.first, total = cls.second;

            
            pass += 1;
            total += 1;

            
            pq.push({calcGain(pass, total), {pass, total}});
            extraStudents--;
        }

        
        double sum = 0.0;
        while (!pq.empty()) {
            auto [gain, cls] = pq.top();
            pq.pop();
            int pass = cls.first, total = cls.second;
            sum += (double)pass / total;
        }

        return sum / classes.size();
    }
};

```
['Array', 'Greedy', 'Sorting', 'Heap (Priority Queue)', 'C++']