题目链接
按照minSPF递减的顺序排序,再选择可用的SPF最大的防晒霜
#include<cstdio>
#include<algorithm>
using namespace std;
#define _rep(i,a,b) for(int i=(a);i<=(b);i++)
const int N=2510;
int c,l,ans;
struct node{
int minspf,maxspf;
bool operator <(const node&rhs)const{
return minspf>rhs.minspf;}
}cow[N];
struct NODE{
int spf,cover;
bool operator <(const NODE&rhs)const{
return spf>rhs.spf;}
}fss[N];
int main()
{
//freopen("in.txt","r",stdin);
scanf("%d%d",&c,&l);
_rep(i,1,c)scanf("%d%d",&cow[i].minspf,&cow[i].maxspf);
sort(cow+1,cow+1+c);
_rep(i,1,l)scanf("%d%d",&fss[i].spf,&fss[i].cover);
sort(fss+1,fss+l+1);
_rep(i,1,c)
{
_rep(j,1,l)
{
if(fss[j].cover>0&&fss[j].spf<=cow[i].maxspf&&fss[j].spf>=cow[i].minspf)
{
fss[j].cover--;
ans++;
break;
}
}
}
printf("%d\n",ans);
return 0;
}