目录:
题目:
分析:
比较简单的贪心题目,但小编这里采用了基排的思想,记录每种防晒霜的数量。因为 的值小于1001,所以在空间上更加优秀。
代码:
#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
inline LL read() {
LL d=0,f=1;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
return d*f;
}
struct node{
int b,e;
}e[2501];
bool cmp(node x,node y)
{
return x.b>y.b;
}
int c[1001];
int main()
{
int n,m;
n=read();m=read();
for(int i=1;i<=n;i++)
{
e[i].b=read();e[i].e=read();
}
int a,b,ans=0;
sort(e+1,e+1+n,cmp);
for(int i=1;i<=m;i++)
{
a=read();b=read();
c[a]+=b;
}
for(int i=1;i<=n;i++)
{
for(int j=e[i].e;j>=e[i].b;j--)
if(c[j]>0)
{
ans++;c[j]--;break;
}
}
printf("%d",ans);
return 0;
}