Pagini recente » Cod sursa (job #1164866) | Cod sursa (job #830967) | Cod sursa (job #1736875) | Cod sursa (job #2711688) | Cod sursa (job #1774261)
#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;
}