doublemaxAverageRatio(vector<vector<int>>& classes, int extraStudents){ priority_queue<Ratio> q; for (auto &c : classes) { q.push({c[0], c[1]}); }
for (int i = 0; i < extraStudents; i++) { auto [pass, total] = q.top(); q.pop(); q.push({pass + 1, total + 1}); }
double res = 0; for (int i = 0; i < classes.size(); i++) { auto [pass, total] = q.top(); q.pop(); res += 1.0 * pass / total; } return res / classes.size(); } };
funcmaxAverageRatio(classes [][]int, extraStudents int)(ans float64) { h := hp(classes) heap.Init(&h) for ; extraStudents > 0; extraStudents-- { h[0][0]++ h[0][1]++ heap.Fix(&h, 0) } for _, c := range h { ans += float64(c[0]) / float64(c[1]) } return ans / float64(len(classes)) }