Max Heap , C++ Easy Beats 90% ✅✅
Approach\n Describe your approach to solving the problem. \nWhat do you think about extra students, in which class do you add extra students.\nAfter adding a st
# Approach\n<!-- Describe your approach to solving the problem. -->\nWhat do you think about **extra students**, in which class do you add extra students.\nAfter adding a student to all class keep **track of difference** but actually we will add that one student in class which has **maximum difference.**\n\n# Complexity\n- Time complexity:O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    double maxAverageRatio(vector<vector<int>>& c, int es) {\n\n        int n  = c.size();\n        double avg  = 0,ans = 0;\n        priority_queue<pair<double,int>> pq;\n\n        for(int i = 0;i<n;i++)\n        {\n            double diff =(double)(c[i][0]+1)/(double)(c[i][1]+1)-(double)c[i][0]/(double)c[i][1];\n            pq.push({diff,i});\n        }\n        while(es--)\n        {\n           int i = pq.top().second;\n           pq.pop();\n           c[i][0]+=1;\n           c[i][1]+=1;\n           double diff = (double)(c[i][0]+1)/(double)(c[i][1]+1)-(double)c[i][0]/(double)c[i][1];\n           pq.push({diff,i});\n        }\n\n        for(int i = 0;i<n;i++)\n        {\n            avg = (double)c[i][0]/(double)c[i][1];\n            ans+=avg;\n        }\n        return ans/(double)n;\n    }\n};\n```\n
['Heap (Priority Queue)', 'C++']