Cod sursa(job #223588)

Utilizator mihai_floreaFlorea Mihai Alexandru mihai_florea Data 28 noiembrie 2008 21:37:07
Problema Hvrays Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <fstream>
#include <algorithm>
using namespace std;
const int NMAX=100001,Inf=66666666;
#define x first
#define y second
pair<int,int> h[NMAX],v[NMAX];
int T,H,V;
ifstream f("hvrays.in");
ofstream g("hvrays.out");
int solve(){
    int i,j=V,sol=0,ymax=-1;
    sort(h+1,h+H+1);
    sort(v+1,v+V+1);
    for (i=H;i;i--)
      if (h[i].y>ymax){
        ++sol;
        for (;j && v[j].x>=h[i].x;j--)
          ymax=max(ymax,v[j].y);
          }
    return sol;
    }
int main(){
    int i;
    for (f>>T;T;T--){
        f>>H>>V;
        for (i=1;i<=H;++i) f>>h[i].x>>h[i].y;
        for (i=1;i<=V;++i) f>>v[i].x>>v[i].y;
        g<<solve()<<'\n';
        }
    return 0;
}