Cod sursa(job #2090996)

Utilizator MihaelaCismaruMihaela Cismaru MihaelaCismaru Data 18 decembrie 2017 22:56:35
Problema Hvrays Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.16 kb
#include<fstream>
#include<algorithm>
using namespace std;
ifstream in ("hvrays.in");
ofstream out ("hvrays.out");
int n,m,t,ilp,sol;
struct punct {
    int a,b;
}o[100001],v[10001],last_point;
bool cmp (punct x, punct y) {
    if (x.a == y.a) {
        return x.b < y.b;
    }
    return x.a < y.a;
}
int main (void) {
    in >> t;
    for (int h = 1; h <= t; h ++) {
        in >> n >> m;
        for (int i = 1; i <= n; i ++) {
            in >> o[i].a >> o[i].b;
        }
        for (int i = 1; i <= m; i ++) {
            in >> v[i].a >> v[i].b;
        }
        sort (v + 1, v + m + 1,cmp);
        sort (o + 1, o + n + 1,cmp);
        sol = 0; ilp = 0; last_point = {0,0};
        for (int i = 1; i <= m; i ++) {
            if ( (i > 1) && (v[i].a <= last_point.a || v[i].b <= last_point.b)) {
                continue;
            }
            sol ++;
            while (true) {
                if (o[ilp].a > v[i].a || o[ilp].b > v[i].b || ilp > n) {
                    break;
                }
                last_point = o[ilp];
                ilp ++;
            }
        }
        out << sol<<"\n";
    }
    return 0;
}