[C++] Simple Heap solution. [Detailed Explanation]
\n/*\n    https://leetcode.com/problems/maximum-average-pass-ratio/\n    \n    At a glance the obvious choice seems like picking the class with least pass\n    
```\n/*\n    https://leetcode.com/problems/maximum-average-pass-ratio/\n    \n    At a glance the obvious choice seems like picking the class with least pass\n    ratio each time and adding a genius student. But this only brings the lower \n    ratio scores near the avg, doesn\'t try to increase the max observed score or\n    decide where to add a student in case two classes have the same pass ratio.\n    So to answer the above ques, we use the delta change increment in avg ratio score.\n    The class that can show the max change is picked and a student is added there.\n    This way a class with max promise is always picked.\n    \n    TC: O(nlogn + klogn + nlogn) ~ O((n+k)logn), n: no. of classes\n*/\n\nclass Solution {\npublic:\n    // Computes the change seen when a new student is added to current class strength\n    double delta_increment(int &pass, int &total) {\n        return (double) (pass + 1) / (total + 1) - (double)pass / total;    \n    }\n    \n    double maxAverageRatio(vector<vector<int>>& classes, int extraStudents) {\n        // Max heap wrt to the delta increment each class pass ratio can achieve\n        priority_queue< tuple<double, int, int>, vector< tuple<double, int, int> >> max_heap;\n        \n        for(auto class_score: classes) \n            max_heap.emplace(make_tuple(delta_increment(class_score[0], class_score[1]),\n                                         class_score[0], class_score[1]));\n        \n        // Add the genius students to those classes where the ratio increment is max\n        while(extraStudents--) {\n            auto max_delta_class = max_heap.top();\n            max_heap.pop();\n            auto [delta, pass, total] = max_delta_class;\n            ++pass, ++total;\n            max_heap.emplace(make_tuple(delta_increment(pass, total), pass, total));\n        }\n        \n        // Find the total avg class pass ratio\n        double avg_pass = 0;\n        while(!max_heap.empty()) {\n            auto max_delta_class = max_heap.top();\n            max_heap.pop();\n            avg_pass += (double)get<1>(max_delta_class) / get<2>(max_delta_class);\n        }\n        return avg_pass / classes.size();\n    }\n};\n```
['C', 'Heap (Priority Queue)', 'C++']