Priority Queue Approach ||O(NlogN) ||Beats 89% Users|| Brief Desciption of Time and Space Complexity
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://Create a Max Heap and look for the max ration change \n    double maxAverageRatio(vector<vector<int>>& classes, int extraStudents) {\n        priority_queue<pair<double,pair<double,double>>>pq;\n        int no_of_class=classes.size();\n        for(int i=0;i<no_of_class;i++){//O(n)\n            double pass=classes[i][0];\n            double total=classes[i][1];\n            double average=(double)(pass/total)-(double)((pass+1)/(total+1));\n            pq.push({abs(average),{pass,total}});//O(logn)\n        }\n        //O(nlogn)\n        while(extraStudents!=0){//O(ExtraStudents)\n            auto min_average=pq.top();\n            pq.pop();//O(logn)\n            double pass=min_average.second.first;\n            double total=min_average.second.second;\n            double new_ration=(double)((pass+1)/(total+1))-(double)(pass+2)/(total+2);\n            pq.push({abs(new_ration),{pass+1,total+1}});//o(logn)\n            extraStudents--;\n        }\n        //O(class_size*log(class_size)+Extra_students*(2*log(Extra_Students)))\n        double ans;\n        double sum=0;\n        while(!pq.empty()){\n            auto front=pq.top();\n            pq.pop();\n            double average=front.second.first/front.second.second;\n            cout<<"Av"<<average<<endl;\n            sum+=average;\n        }\n        cout<<sum<<" ";\n        ans=sum/(double)(no_of_class);\n        return ans;\n\n        //Overall TC;O(2*class_size*log(class_size)+Extra_students*(2*log(Extra_Students)))\n        //Simpel TC:O(2nlogn+2elogn);n=no of classes;e=no of Extra students \n        //Space Complexity:O(1);\n        \n    }\n};\n\nPLZZ upvote \n\n```
['C++']