Easy Solution, Priority Queue
IntuitionApproachComplexity
Time complexity: O(nlog(n))

Space complexity: O(n)
Code
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(nlog(n))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    double maxAverageRatio(vector<vector<int>>& classes, int extraStudents) {\n        priority_queue<pair<double, pair<int, int>>> pq;\n        for(int i = 0; i < classes.size(); i++){\n            pq.push({(classes[i][0] + 1)*1.0 /(classes[i][1] + 1) - classes[i][0]*1.0/classes[i][1], {classes[i][0], classes[i][1]}});\n        }\n        while(extraStudents--){\n            auto [a, b] = pq.top().second;\n            pq.pop();\n            pq.push({(a + 2)*1.0/(b + 2) - (a + 1)*1.0/(b + 1), {a + 1, b + 1}});\n        }\n        double ans = 0;\n        while(!pq.empty()){\n            auto [a, b] = pq.top().second;\n            ans += a * 1.0 / b;\n            pq.pop();\n        }\n        return ans/classes.size();\n    }\n};\n```
['C++']