Cod sursa(job #1774261)

Utilizator Athena99Anghel Anca Athena99 Data 8 octombrie 2016 19:02:18
Problema Hvrays Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <algorithm>
#include <fstream>

using namespace std;

ifstream fin("hvrays.in");
ofstream fout("hvrays.out");

const int nmax= 100000;

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(  ) {
    int t;
    fin>>t;
    for ( int cnt= 1; cnt<=t; ++cnt ) {
        int n, m;
        fin>>n>>m;

        for ( int i= 1; i<=n; ++i ) {
            fin>>h[i].x>>h[i].y;
        }
        sort( h+1, h+n+1, cmp );

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

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

        fout<<sol<<"\n";
    }

    return 0;
}