Greedy, use priority queue to get the maximum increasement. O(nLogn), binary serach doesn't work
\n\nclass Solution {\npublic:\n    double maxAverageRatio(vector<vector<int>>& classes, int extraStudents) {\n        priority_queue<pair<double, pair<int, int>
\n```\nclass Solution {\npublic:\n    double maxAverageRatio(vector<vector<int>>& classes, int extraStudents) {\n        priority_queue<pair<double, pair<int, int> > > pq;\n        for(auto &cls : classes) {\n            int t = cls[1], p = cls[0];\n            double add = (p + 1) * 1.0 / (t + 1) - (p * 1.0 / t);\n            pq.push({add, {p, t}});\n        }\n        while(extraStudents--) {\n            auto p = pq.top(); pq.pop();\n            int &t = p.second.second;\n            int &pa = p.second.first;\n            ++t; ++pa;\n            p.first = (pa + 1) * 1.0 / (t + 1) - pa * 1.0 / t;\n            pq.push(p);\n        }\n        double res = 0;\n        while(pq.size()) {\n            res += pq.top().second.first * 1.0 / pq.top().second.second; pq.pop();\n        }\n        return res / classes.size();\n    }\n};\n```
[]