参考:❀
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
const int MAXN=+;
struct rec
{
int a,b;
bool operator < (const rec& x) const
{
return a<x.a;
}
}; rec cow[MAXN],sunscreen[MAXN];
int C,L,ans=; int main()
{
scanf("%d%d",&C,&L);
for (int i=;i<C;i++) scanf("%d%d",&cow[i].a,&cow[i].b); //a:min b:max
for (int i=;i<L;i++) scanf("%d%d",&sunscreen[i].a,&sunscreen[i].b);//a:effect b:num
priority_queue< int,vector<int>,greater<int> > pque;
sort(cow,cow+C);
sort(sunscreen,sunscreen+L);
int j=;
for (int i=;i<L;i++)
{
while (j<C && cow[j].a<=sunscreen[i].a)
{
pque.push(cow[j].b);
j++;
}
while (!pque.empty() && sunscreen[i].b)//莫忘队列为空时也不执行
{
int temp=pque.top();
pque.pop();
if (temp<sunscreen[i].a) continue;
sunscreen[i].b--;
ans++;
}
}
cout<<ans<<endl;
return ;
}