Cod sursa(job #2014201)

Utilizator refugiatBoni Daniel Stefan refugiat Data 23 august 2017 09:45:49
Problema Hvrays Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.38 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#define NMAX 100005
using namespace std;
ifstream si("hvrays.in");
ofstream so("hvrays.out");
string buf;
string::iterator bit;
void citint(int &x)
{
    for(;*bit>'9'||*bit<'0';++bit);
    for(x=0;*bit<='9'&&*bit>='0';++bit)
    {
        x=x*10+*bit-'0';
    }
}
struct str
{
    int x,y;
};
str h[NMAX+1],v[NMAX+1];

bool cmp(str x,str y)
{
    if(x.x==y.x)
    {
        return x.y>y.y;
    }
    return x.x>y.x;
}

int main()
{
    getline(si,buf,(char)0);
    bit=buf.begin();
    int t;
    citint(t);
    for(int q=1;q<=t;++q)
    {
        int n,m;
        citint(n);
        citint(m);
        for(int i=1;i<=n;++i)
        {
            citint(h[i].x);
            citint(h[i].y);
        }
        sort(h+1,h+n+1,cmp);

        for(int i=1;i<=m;++i)
        {
            citint(v[i].x);
            citint(v[i].y);
        }
        sort(v+1,v+m+1,cmp);

        int sol=0;
        for(int i=1,j=1,aux=-1;i<=n;++i)
        {
            if(aux<h[i].y)
            {
                for(++sol;j<=m&&h[i].x<=v[j].x;++j)
                {
                    if(aux<v[j].y)
                    {
                        aux=v[j].y;
                    }
                }
            }
        }

        so<<sol<<'\n';
    }

    return 0;
}