[C++]- Simple and easy to understand solution
Ques : How we are arranging in priority queue ? Based on what factor comparator will arrange ?\n--> Based upon the gain of average after incrementing the existi
**Ques : How we are arranging in priority queue ? Based on what factor comparator will arrange ?**\n--> Based upon the gain of average after incrementing the existing values of {pass,total}. Gain should be maximum.\n\n```\nclass comparator{\n    public : \n        int operator()(pair<int,int> &v1,pair<int,int> &v2){\n            double new_val1=(double)(v1.first+1)/(v1.second+1);\n            double old_val1=(double)v1.first/v1.second;\n            \n            double new_val2=(double)(v2.first+1)/(v2.second+1);\n            double old_val2=(double)v2.first/v2.second;\n            \n            double diff1=new_val1-old_val1;\n            double diff2=new_val2-old_val2;\n            \n            return (diff1<=diff2);\n            \n        }\n};\nclass Solution {\npublic:\n    \n    double maxAverageRatio(vector<vector<int>>& classes, int extraStudents) {\n        priority_queue<pair<int,int>, vector<pair<int,int> >,comparator> pq;\n        int count=0;\n        for(int i=0;i<classes.size();i++){\n            if(classes[i][0]!=classes[i][1])\n                pq.push(make_pair(classes[i][0],classes[i][1]));\n            else    //if class with 100% pass average\n                count++;\n        }\n        while(extraStudents>0 && !pq.empty()){\n            pair<int,int> v=pq.top();pq.pop();\n            v.first++,v.second++;\n            pq.push(v);\n            extraStudents--;\n        }\n        \n        double pass=0,total=0;\n        double ans=0;\n       while(!pq.empty()){\n            pair<int,int> v=pq.top();pq.pop();\n            pass=v.first,total=v.second;\n            ans+=pass/total;\n        }\n        ans+=count;\n        return ans/classes.size();\n    }\n};\n```\n\nPS - Same code will give TLE on 2 cases if we use vector instead of pair.
['Greedy', 'C', 'Heap (Priority Queue)', 'C++']