beats 97% 🎯✅✅✅ easy to understand
IntuitionApproachComplexity
Time complexity:

Space complexity:
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:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\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        auto profit = [&](double pass, double total) {\n            return (pass + 1) / (total + 1) - pass / total;\n        };\n\n        double total = 0;\n        priority_queue<pair<double, array<int, 2>>> pq;\n        for (int i = 0; i < classes.size(); i++) {\n            total += (double)classes[i][0] / classes[i][1];\n            pq.push({profit(classes[i][0], classes[i][1]),\n                     {classes[i][0], classes[i][1]}});\n        }\n\n        while (extraStudents--) {\n            auto [pfit, arr] = pq.top();\n            pq.pop();\n            total += pfit;\n            pq.push({profit(arr[0] + 1, arr[1] + 1), {arr[0] + 1, arr[1] + 1}});\n        }\n        return total / classes.size();\n    }\n};\n```
['C++']