Cod sursa(job #181105)

Utilizator savimSerban Andrei Stan savim Data 17 aprilie 2008 21:12:25
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[2][maxl],v[2][maxl];
int p[maxl],q[maxl];
char cit[30];

inline int cmp(int x, int y)
{
    return h[0][x]<h[0][y];
}
inline int cmp2(int x, int y)
{
    return v[0][x]<v[0][y];
}
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[0][i],&h[1][i]);
            p[i]=i;
        }

        for (i=1; i<=V; i++)
        {
            scanf("%d %d",&v[0][i],&v[1][i]);
            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[0][q[j]]>=h[0][p[i]] && j>0)
            {
                  if (v[1][q[j]]>val) val=v[1][q[j]];
                  j--;
                  gas=1;
            }
            if (gas) k++;
        }

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