POJ - 3614 Sunscreen
#include<iostream>
#include<algorithm>
#define x first
#define y second
using namespace std;
typedef pair<int,int>PII;
const int N = 2510;
PII a[N],b[N];
int n,m;
int main()
{
cin>>n>>m;
for(int i=0;i<n;i++) cin>>b[i].x>>b[i].y;
for(int i=0;i<m;i++) cin>>a[i].x>>a[i].y;
sort(a,a+m);sort(b,b+n);
int ans=0;
for(int i=n-1;i>=0;i--)
for(int j=m-1;j>=0;j--)
if(b[i].x<=a[j].x && a[j].x<=b[i].y && a[j].y)
{
ans++;
a[j].y--;
break;
}
cout<<ans<<endl;
return 0;
}