Cod sursa(job #814779)

Utilizator radustn92Radu Stancu radustn92 Data 16 noiembrie 2012 03:16:28
Problema Hvrays Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <set>
#include <queue>
#define pii pair <int,int>
#define x first
#define y second
#define NMAX 100005
using namespace std;
ifstream in("hvrays.in");
ofstream out("hvrays.out");
int t,n,m,rez;
pii A[NMAX],B[NMAX];
void read()
{
    in>>n>>m;
    int i;
    for (i=1; i<=n; i++)
        in>>A[i].x>>A[i].y;
    for (i=1; i<=m; i++)
        in>>B[i].x>>B[i].y;
}
inline int max(int x,int y)
{
    return x>y ? x : y;
}
void solve()
{
   // sort(A+1,A+n+1);
  //  sort(B+1,B+m+1);
    rez=0;
    int i,p=m+1,curr=-1,best=-1;
    for (i=n; i>=1; i--)
    {
        while (p-1>0 && B[p-1].x>=A[i].x)
            best=max(best,B[--p].y);
        if (A[i].y>curr)
        {
            curr=best;
            rez++;
        }
    }
}
int main()
{
    freopen("hvrays.in","r",stdin);
    freopen("hvrays.out","w",stdout);
    in>>t;
    while (t--)
    {
        read();
        solve();
        out<<rez<<'\n';
    }
    return 0;
}