记录编号 574664 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 [CSP 2021S]廊桥分配 最终得分 100
用户昵称 Gravatar┭┮﹏┭┮ 是否通过 通过
代码语言 C++ 运行时间 0.446 s
提交时间 2022-08-09 17:25:43 内存使用 4.41 MiB
显示代码纯文本
#include <bits/stdc++.h> 
#include <queue>
using namespace std;
int n,m1,m2,sum1[100010],sum2[100010],ans;
struct made{
    int l,r;
}a[100010],c[100010];
struct made1{
    int e,id;
    made1(){}
    made1(int x,int y){
        e = x,id = y;
    }
}; 
bool cmp(made x,made y){
    if(x.l == y.l)return x.r < y.r;
    return x.l < y.l;
}
struct cmp1{
    bool operator()(made1 x,made1 y){
        return x.e > y.e;
    }
};
void sou(made x[],int sum[],int M){
    priority_queue<int,vector<int>,greater<int> >q1;
    priority_queue<made1,vector<made1>,cmp1>q2;
    for(int i = 1;i <= n;i++){
        q1.push(i);
    }
    for(int i = 1;i <= M;i++){
        while(!q2.empty() && q2.top().e < x[i].l){
            q1.push(q2.top().id);
            q2.pop();
        }
        if(!q1.empty()){
            int y = q1.top();q1.pop();
            q2.push(made1(x[i].r,y));
            sum[y]++;
        } 
    }
}
int main(){
    freopen("2021airport.in","r",stdin);
    freopen("2021airport.out","w",stdout);
    scanf("%d%d%d",&n,&m1,&m2);
    for(int i = 1;i <= m1;i++)scanf("%d%d",&a[i].l,&a[i].r);
    for(int i = 1;i <= m2;i++)scanf("%d%d",&c[i].l,&c[i].r);
    sort(a+1,a+1+m1,cmp);
    sort(c+1,c+1+m2,cmp);
    sou(a,sum1,m1);
    sou(c,sum2,m2);
    for(int i = 1;i <= n;i++){
        sum1[i] += sum1[i-1];
        sum2[i] += sum2[i-1];
    } 
    for(int i = 0;i <= n;i++){
        ans = max(ans,sum1[i] + sum2[n-i]);
    }
    cout<<ans<<endl;
    
    return 0;
}