## L2-046 天梯赛的赛场安排

题目链接：
https://pintia.cn/problem-sets/994805046380707840/exam/problems/type/7?problemSetProblemId=1649748772841508873&page=1

题目分析：
本题的考点是**结构体+优先级队列**，因为每个学校包含的信息较多，用结构体来存储比较方便，用优先级队列可以快速找到尚未安排赛场的最多的队员人数，好进行分配

具体看解法代码：
```cpp
#include<bits/stdc++.h>
using namespace std;
//总结：题目包含的信息比较多，我们可以创建结构体来记录数据
struct school{
    string name;
    int total_stu;
    int teacher;
    int res_stu;//剩余的需要安排的学生数量
};
int main(){
    int n,c;
    cin>>n>>c;
    vector<string> sl_name;
    map<string,int> ans;//存最后的答案
    auto cmp=[](struct school&a,struct school&b){
        return a.res_stu<b.res_stu;
    };
    vector<int> room;//这里我们还需要一个变量来存储剩余空位数
    priority_queue<school,vector<school>,decltype(cmp)> pq(cmp);
    for(int i=0;i<n;i++){
        string s; cin>>s;
        sl_name.push_back(s);
        int x; cin>>x;
        pq.push({s,x,0,x});
    }
    while(!pq.empty()){
        school current=pq.top();
        pq.pop();
        if(current.res_stu==0){
            ans[current.name]=current.teacher;
            continue;//如果为0，就一直删,同时存一下数据
        }
        if(current.res_stu>=c){
            current.res_stu-=c;
            current.teacher++;
            room.push_back(0);
            pq.push(current);//这里再重新加入优先级队列
        }
        else{
            bool find=false;
            for(auto &space:room){//这里一定要用引用
                if(space>=current.res_stu){
                    current.res_stu=0;
                    space-=current.res_stu;
                    current.teacher++;
                    find=true;
                    break;
                }
            }
                if(!find){
                    room.push_back(c-current.res_stu);
                    current.teacher++;
                    current.res_stu=0;
                }
                pq.push(current);
        }
    }
    for(auto& s:sl_name){
        cout<<s<<" "<<ans[s]<<endl;
    }
    cout<<room.size();
    return 0;
}
