max heap | C++ | Commented code || Greedy
\n\ndouble maxAverageRatio(vector<vector<int>>& classes, int extra) {\n       priority_queue<pair<double,pair<int,int>>>pq;\n        int n=classes.size();\n    
```\n\ndouble maxAverageRatio(vector<vector<int>>& classes, int extra) {\n       priority_queue<pair<double,pair<int,int>>>pq;\n        int n=classes.size();\n        //calculating the difference between the previous ration and new ratio\n        //here I will increament student and pass student of each class by one and will chaeck where difference is maximum\n        //thats why I am using preiority queue so that my max profit will be on top;\n        for(int i=0;i<n;i++)\n        {\n            int pass=classes[i][0];\n            int stud=classes[i][1];\n            double diff=(double)(pass+1)/(stud+1)-(double)(pass)/(stud);\n            pq.push({diff,{pass,stud}});\n        }\n        //now keep adding one by one new students to the class untill extra will not become zero\n        while(extra--)\n        {\n            auto x=pq.top();\n            pq.pop();\n            \n            int pass=x.second.first;\n            int stud=x.second.second;\n            pass++;\n            stud++;\n            //chck your new difference and reassign to the priority queue after popping the previous one\n            double newdiff=(double)(pass+1)/(stud+1)-(double)(pass)/(stud);\n            pq.push({newdiff,{pass,stud}});\n            \n        }\n        //till here you have successfully assinged the student in optimal class\n        //just take the avarage and this is your ans;\n        double ans=0.0;\n         while(!pq.empty())\n         {\n             auto x=pq.top();\n             pq.pop();\n             ans+=(double)(x.second.first)/(x.second.second);\n         }\n        return ans/n;\n    }\n\n```
[]