Cod sursa(job #329888)

Utilizator AndreiDDiaconeasa Andrei AndreiD Data 7 iulie 2009 23:25:01
Problema Hvrays Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <cstdio>
#include <algorithm>

using namespace std;

#define file_in "hvrays.in"
#define file_out "hvrays.out"

#define Nmax 101000
#define mp make_pair


pair<int,int> H[Nmax],V[Nmax];
int T,h,v;
int nrr,ymax,maxx;

bool cmp( pair <int, int> a, pair<int ,int> b)
{
	if (a.second==b.second)
		return (a.first>b.first);
	return (a.second>b.second);
}


int main()
{
	int i,j,x,y;
	freopen(file_in,"r",stdin);
	freopen(file_out,"w",stdout);
	
	scanf("%d", &T);
	
	while(T--)
	{
		scanf("%d %d", &h,&v);
		
		for (i=1;i<=h;++i) 
		{
			scanf("%d %d", &x,&y);  
			H[i]=mp(x,y);
		}
		for (i=1;i<=v;++i)
        {
			scanf("%d %d", &x,&y);  
			V[i]=mp(x,y);
		}
		
		sort(H+1,H+h+1,cmp);
		sort(V+1,V+v+1,cmp);
		
		ymax=-1;
		maxx=-1;
		nrr=0;
		j=1;
		for (i=1;i<=h;++i)
		{
			if (H[i].first>ymax)
			{
				nrr++;
			for (;j<=v && H[i].second<=V[j].second;++j)
				ymax=max(ymax,V[j].first);
		    }
		}
		
		printf("%d\n", nrr);
	}
	
	fclose(stdin);
	fclose(stdout);
	
	return 0;
}