思路:
我们发现可以直接贪心,即选包含当前点的区间中右端点最小的,可以直接用堆来维护
c o d e code code
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#define ll long long
using namespace std;
const ll MAXN = 2e5 + 10;
ll n, m;
ll s[MAXN];
struct node {
ll x, y;
}a[MAXN];
priority_queue<int> q;
bool cmp(node x, node y) {
return x.x < y.x;
}
int main() {
freopen("dream.in", "r", stdin);
freopen("dream.out", "w", stdout);
scanf("%d%d", &n, &m);
for(ll i = 1; i <= n; i ++) scanf("%d%d", &a[i].x, &a[i].y);
for(ll i = 1; i <= m; i ++) scanf("%d", &s[i]);
sort(s + 1, s + 1 + m);
sort(a + 1, a + 1 + n, cmp);
ll sum = 0;
for(ll i = 1, j = 1; i <= m; i ++) {
while(a[j].x <= s[i] && j <= n) q.push(-a[j].y), j++;
while(!q.empty() && -q.top() < s[i]) q.pop();
if(!q.empty()) {
q.pop();
sum ++;
}
}
printf("%d", sum);
return 0;
}