251 ms -> 100% | 97.74 MB -> 56.39% | Simple as it gets with explanation.
Code
![fef.png](https://assets.leetcode.com/users/images/1bd1d97a-1088-4ee9-8734-d7373076e134_1734269618.0650334.png)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    double maxAverageRatio(vector<vector<int>>& classes, int extraStudents) {\n        int classesLen = classes.size();\n        \n        // pq to know which class will increase the avg the most\n        priority_queue<pair<double, int>> valueQueue;\n        double finalAvg = 0.0;\n        double localAvg = 0.0;\n\n\n        // going through all classes adding them to finalAvg and\n        // placing their avg increase into the pq if we were to add\n        // an extra student there\n        for (int i = 0; i < classesLen; ++i) {\n            localAvg = static_cast<double>(classes[i][0]) / classes[i][1];\n            valueQueue.push({(static_cast<double>(classes[i][0] + 1) / (classes[i][1] + 1)) - localAvg, i});\n            finalAvg += localAvg;\n        }\n\n        // devide the avg once after the loop\n        finalAvg /= classesLen;\n\n\n        // while there are students to distribute we go through the pq\n        while (extraStudents > 0) {\n            // we take the class with highest avg inc value\n            auto top = valueQueue.top();\n            valueQueue.pop();\n\n            // add the value / classLen to the finalAvg\n            finalAvg += top.first / classesLen;\n\n            // we add a student to that class\n            ++classes[top.second][0];\n            ++classes[top.second][1];\n\n            // recalculate that class avg inc if we were to add an\n            // extra student\n            localAvg = static_cast<double>(classes[top.second][0]) / classes[top.second][1];\n            valueQueue.push({(static_cast<double>(classes[top.second][0] + 1) / (classes[top.second][1] + 1)) - localAvg, top.second});\n            \n            // decrement the extraStudents left\n            --extraStudents;\n        }\n\n        return finalAvg;\n    }\n};\n```
['C++']