Cod sursa(job #184231)

Utilizator raula_sanChis Raoul raula_san Data 23 aprilie 2008 12:30:57
Problema Hvrays Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <cstdio>
#include <vector>
#include <algorithm>

#define pb push_back
#define mp make_pair

#define ff first
#define ss second

using namespace std;

int T, N, M, Ret;

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

void Solve()
{
	sort(H.begin(), H.end());
	sort(V.begin(), V.end());
	Ret = 0;
	
	int i, j, x = -1, y = -1;

	for(i=N-1, j=M-1; i>=0 && j>=0; --i)
	{
		if(y < H[i].ss)
		{
			x = V[j].ff;
			y = V[j].ss;

			++ Ret;
		}

		while(j >= 0 && V[j].ff >= H[i].ff) -- j;
	}
}

int main()
{
	freopen("hvrays.in", "rt", stdin);
	freopen("hvrays.out", "wt", stdout);

	for(scanf("%d", &T); T; --T)
	{
		scanf("%d %d", &N, &M);

		int i, x, y;
		for(i=1; i<=N; ++i)
		{
			scanf("%d %d", &x, &y);
			H.pb(mp(x, y));
		}

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

		Solve();

		printf("%d\n", Ret);

		H.clear();
		V.clear();
	}

	fclose(stdin);
	fclose(stdout);

	return 0;
}