贪心。
/*
Poj: 3614 Sunscreen
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#define MaxLC 2505
using namespace std;
struct Cow {
int minn, maxx;
bool operator < (const struct Cow & t) const {
return maxx < t.maxx;
}
}cow[MaxLC];
struct SPF {
int spf;
int total;
bool operator < (const struct SPF &t) const {
if(spf < t.spf)
return true;
else
return false;
}
}lotion[MaxLC];
int c, l;
int res;
int main()
{
//freopen("data.in", "rb", stdin);
while(scanf("%d%d", &c, &l) != EOF) {
for(int i = 0; i < c; i++) {
scanf("%d%d", &cow[i].minn, &cow[i].maxx);
}
for(int i = 0; i < l; i++) {
scanf("%d%d", &lotion[i].spf, &lotion[i].total);
}
sort(cow, cow + c);
sort(lotion, lotion + l);
res = 0;
for(int i = 0; i < c; i++) {
for(int j = 0; j < l; j++) {
if(lotion[j].spf >= cow[i].minn && lotion[j].spf <= cow[i].maxx && lotion[j].total > 0) {
res++;
lotion[j].total--;
break;
}
if(lotion[j].spf > cow[i].maxx)
break;
}
}
printf("%d\n", res);
}
return 0;
}