using heaps | c++ 🏆🔥
Intuitionin this problem in order to maximise the average pass ratio you need to maximise the pass ratio
the maximum change in the pass ration is checked acc to
# Intuition\n![25b9210e-1683-4751-99aa-f9a72307ed16_1702489054.9060743.jpeg](https://assets.leetcode.com/users/images/91f4c11c-edcd-407d-9e8d-cafab42be297_1734241483.5342772.jpeg)\nin this problem in order to maximise the average pass ratio you need to maximise the pass ratio\nthe maximum change in the pass ration is checked acc to how much the ratio of any class changes if any student is added into it.\nfor this we will maintain a heap\nin this the change is already present at the top of the priority queue for the next addition of student.\nthen again the top value is taken and a student is added and then the change that will be done for it.\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        priority_queue<pair<double,pair<int,int>>> pq;\n        for(int i=0;i<classes.size();i++){\n            int n=classes[i][0];\n            int d=classes[i][1];\n            double change=(double)(n+1)/(d+1)-(double)n/d;\n            pq.push({change,{n,d}});\n        }\n        for(int i=0;i<extraStudents;i++){\n            auto [change,p]=pq.top();\n            pq.pop();\n            int n=p.first;\n            int d=p.second;\n            n++;\n            d++;\n            double newchange=(double)(n+1)/(d+1)-(double)n/d;\n            pq.push({newchange,{n,d}});\n        }\n        double passratio=0;\n        while(!pq.empty()){\n            auto [a,b]=pq.top();\n            pq.pop();\n            int n=b.first;\n            int d=b.second;\n            passratio+=(double)n/d;\n        }\n        return passratio/classes.size();\n        \n    }\n};\n```
['C++']