Cod sursa(job #181084)

Utilizator savimSerban Andrei Stan savim Data 17 aprilie 2008 21:01:23
Problema Hvrays Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.2 kb
#include <stdio.h>
#include <algorithm>
#define maxl 100010
using namespace std;

int i,j,k,n,t,H,V,val,gas;
int h[maxl][2],v[maxl][2];
int p[maxl],q[maxl];
char cit[30];

inline int cmp(int x, int y)
{
    return h[x][0]<h[y][0];
}
inline int cmp2(int x, int y)
{
    return v[x][0]<v[y][0];
}
int main()
{
    freopen("hvrays.in","r",stdin);
    freopen("hvrays.out","w",stdout);
    
    scanf("%d",&t);
    while (t>0)
    {
        t--;
        scanf("%d %d\n",&H,&V);
        for (i=1; i<=H; i++)
        {
            scanf("%d %d",&h[i][0],&h[i][1]);
            p[i]=i;
        }

        for (i=1; i<=V; i++)
        {
            scanf("%d %d",&v[i][0],&v[i][1]);
            q[i]=i;
        }
        
        sort(p+1,p+H+1,cmp);
        sort(q+1,q+V+1,cmp2);
        
        j=V;k=0;val=0;
        for (i=H; i>=1; i--)
        if (h[p[i]][1]>=val)
        {
            gas=0;
            while (v[q[j]][0]>=h[p[i]][0] && j>0)
            {
                  if (v[q[j]][1]>val) val=v[q[j]][1];
                  j--;
                  gas=1;
            }
            if (gas) k++;
        }

        printf("%d\n",k);
    }
    
    return 0;    
}