C++ Use set to track the most effective at the end
~~~\nclass Solution {\npublic:\n    double maxAverageRatio(vector>& c, int extraStudents) {\n        set> s;\n        int n = c.size();\n        for (int i = 0;
~~~\nclass Solution {\npublic:\n    double maxAverageRatio(vector<vector<int>>& c, int extraStudents) {\n        set<pair<double, int>> s;\n        int n = c.size();\n        for (int i = 0; i < n; ++i) {\n            double d = 1.0 * (c[i][0] + 1) / (c[i][1] + 1) - 1.0 * c[i][0] / c[i][1];\n            s.insert({d, i});\n        }\n        \n        while (extraStudents > 0) {\n            auto it = s.rbegin();\n            int i = it->second;\n            s.erase(*it);\n            c[i][0] = c[i][0] + 1; \n            c[i][1] = c[i][1] + 1; \n            double d = 1.0 * (c[i][0] + 1) / (c[i][1] + 1) - 1.0 * c[i][0] / c[i][1];\n            s.insert({d, i});\n            --extraStudents;\n        }\n        \n        double res = 0.0;\n        for (int i = 0; i < n; ++i) {\n            res += 1.0 * c[i][0] / c[i][1];\n        }\n        return res/n;\n    }\n};\n~~~\n
[]