比赛 2024暑期C班集训4 评测结果 AAAAAAAAAA
题目名称 梦境 最终得分 100
用户昵称 ┭┮﹏┭┮ 运行时间 0.239 s
代码语言 C++ 内存使用 2.41 MiB
提交时间 2024-07-04 10:44:11
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define fi first 
#define se second
const int N = 2e5+10;

ll read(){
    ll x = 0,f = 1;char c = getchar();
    for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
    for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
    return x * f;
}

int n,m,ans;
int t[N];
struct made{
    int l,r;
    bool operator < (const made x)const{
        if(l != x.l)return l < x.l;
        return r < x.r;
    }
}a[N];


priority_queue<pii,vector<pii>,greater<pii> >q;
int main(){
    freopen("dream.in","r",stdin);
    freopen("dream.out","w",stdout);
    n = read(),m = read();
    for(int i = 1;i <= n;i++)a[i].l = read(),a[i].r = read();
    for(int i = 1;i <= m;i++)t[i] = read();
    sort(a+1,a+1+n);
    sort(t+1,t+1+m);
    int j = 1;
    for(int i = 1;i <= m;i++){ 
        while(j <= n && a[j].r < t[i])j++;
        while(j <= n && a[j].l <= t[i] && t[i] <= a[j].r)q.push(make_pair(a[j].r,j)),j++;
        while(!q.empty() && q.top().fi < t[i])q.pop();
        if(!q.empty()){
            ans++,q.pop();
        } 
    }
    printf("%d\n",ans);
    
    
    return 0;
    
}