- 优先队列里可加array
- 具体声明:
priority_queue<pair<double, array<int,2>>> pq;
class Solution {
public:
double maxAverageRatio(vector<vector<int>>& classes, int extraStudents) {
auto profit = [&](double a, double b){
return (a+1)/(b+1) - a/b;
};
double sum=0;
priority_queue<pair<double, array<int,2>>> pq;
for(auto& e:classes){
sum+=1.0*e[0]/e[1];
pq.push({profit(e[0],e[1]), {e[0],e[1]}});
}
int& k=extraStudents;
while(k--){
auto [delta, e] = pq.top(); pq.pop();
sum+=delta;
pq.push({profit(e[0]+1,e[1]+1),{e[0]+1, e[1]+1}});
}
return sum/classes.size();
}
};