Cod sursa(job #198580)

Utilizator devilkindSavin Tiberiu devilkind Data 12 iulie 2008 19:28:08
Problema Hvrays Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

#define NMAX 200002
#define pb push_back
#define sz size()
#define mp make_pair
#define ff first
#define ss second

vector< pair< pair<int,int>, int > > v;
long int H,V;

int cmp(pair< pair<int,int> , int > x, pair< pair<int,int> , int > y)
{
	if (x.ff.ff==y.ff.ff) return x.ss>y.ss;
	return x.ff.ff>y.ff.ff;
}

void compute()
{
	sort(v.begin(),v.end(), cmp);
	
	int mx=-1,nmx=-1,sol=0,i;

	for (i=0;i<v.sz;i++)
	{
		if (v[i].ss==1) {nmx=max( v[i].ff.ss, nmx);continue;}
		if (v[i].ff.ss>mx) {sol++;mx=nmx;} 
	}
	printf("%ld\n",sol);
}

int main()
{
	freopen("hvrays.in","r",stdin);
	freopen("hvrays.out","w",stdout);

	long int i,T,x,y;

	for (scanf("%ld",&T);T;T--)
	{
		scanf("%ld %ld",&H,&V);
		v.clear();

		for (i=1;i<=H;i++)
		{
			scanf("%ld %ld",&x,&y);
			v.pb( mp( mp(x,y),0) );
		}

		for (i=1;i<=V;i++)
		{
			scanf("%ld %ld",&x,&y);
			v.pb( mp( mp(x,y),1) );
		}
		compute();
	}

	return 0;
}