C++ | Greedy | Priority Queue
Code
# Code\n```cpp []\ndouble calc(int a,int b){\n    return (a+1) / double(b+1) - (a) / double(b);\n}\n\nclass Solution {\npublic:\n    double maxAverageRatio(vector<vector<int>>& classes, int extraStudents) {\n        priority_queue<pair<double, pair<int, int>>>pq;\n        for(auto i : classes)pq.push({calc(i[0],i[1]), {i[0], i[1]}});\n\n        while(extraStudents--){\n            auto[cost, p] = pq.top(); pq.pop();\n\n            p.first++, p.second++;\n            pq.push({calc(p.first, p.second), {p.first, p.second}});\n        }\n\n        double ans = 0;\n        while(pq.size())\n            ans += pq.top().second.first / double(pq.top().second.second), pq.pop();\n\n        return ans/classes.size();\n    }\n};\n```
['Greedy', 'Heap (Priority Queue)', 'C++']