Beat 99%|C++ solution| easy to understand
Intuitionwe need to maximise average.so for this we have to find the maximum growth rate of each class.ApproachComplexity

Time complexity: O (N logN)



Space
# Intuition\nwe need to maximise average.so for this we have to find the maximum growth rate of each class.\n\n# Approach\n\n# Complexity\n- Time complexity: O (N logN)\n![Screenshot 2024-12-15 165708.png](https://assets.leetcode.com/users/images/e8fc6e05-3f78-401d-9129-31c83aca1af8_1734262194.9973867.png)\n\n- Space complexity:O(N)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    double maxAverageRatio(vector<vector<int>>& nums, int ex) {\n        priority_queue<pair<double,int>>q;\n        int n=nums.size();\n        double ans=0;\n        for(int i=0;i<nums.size();i++){\n            double w=(double)(nums[i][0]+1)/(double)(nums[i][1]+1);\n            double y=(double)nums[i][0]/(double)nums[i][1];\n            ans+=y/n;\n            q.push({w-y,i});\n        }\n        while(ex--){\n            auto d=q.top().second;\n            ans+=q.top().first/n;\n            q.pop();\n            nums[d][0]++;\n            nums[d][1]++;\n            double w=(double)(nums[d][0])/(double)(nums[d][1]);\n            double x=(double)(nums[d][0]+1)/(double)(nums[d][1]+1);\n            q.push({x-w,d});   \n\n        }\n    return ans;}\n};\n```\n\n
['C++']