Cod sursa(job #1305276)

Utilizator diana97Diana Ghinea diana97 Data 29 decembrie 2014 17:58:41
Problema Hvrays Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;

ifstream f ("hvrays.in");
ofstream g ("hvrays.out");

const int NMAX = 100000 + 10;

struct Raza {
    int x, y;
};

int t, h, v;

Raza H[NMAX], V[NMAX];

void citeste() {
    f >> h >> v;
    for (int i = 1; i <= h; i++) f >> H[i].x >> H[i].y;
    for (int i = 1; i <= v; i++) f >> V[i].x >> V[i].y;
}

inline bool comp(Raza a, Raza b) {
    return a.x > b.x;
}

void rezolva() {
    int maxim = 0, sol = 0;
    for (int i = 1, j = 1; i <= h; i++)
        if (H[i].y > maxim) {
            sol++;
            while(j <= v && V[j].x >= H[i].x) {
                maxim = max(maxim, V[j].y);
                j++;
            }
        }

    g << sol << '\n';
}

int main() {
    f >> t;
    while (t--) {
        citeste();
        sort(H + 1, H + h + 1, comp);
        sort(V + 1, V + v + 1, comp);
        rezolva();
    }
    return 0;
}