Pagini recente » Cod sursa (job #2458044) | Cod sursa (job #2308123) | Cod sursa (job #2494977) | Cod sursa (job #1041343) | Cod sursa (job #1065839)
#include<fstream>
#include<algorithm>
#define x first
#define y second
#define N 100010
#define punct pair<int,int>
using namespace std;
ifstream f("hvrays.in");
ofstream g("hvrays.out");
int t,i,sol,h,v,p,cur,maxi;
punct vh[N],vv[N];
inline bool cmp(punct a,punct b)
{
return a.y>b.y;
}
int main()
{
f>>t;
for(;t;--t)
{
f>>h>>v;
for(i=1;i<=h;++i)
f>>vh[i].x>>vh[i].y;
for(i=1;i<=v;++i)
f>>vv[i].x>>vv[i].y;
sort(vh+1,vh+h+1,cmp);
sort(vv+1,vv+v+1,cmp);
p=1;
cur=maxi=-1;
sol=0;
for(i=1;i<=h;++i)
{
while(p<=v&&vv[p].y>=vh[i].y)
{
maxi=max(maxi,vv[p].x);
++p;
}
if(cur<maxi)
{
cur=maxi;
++sol;
}
}
g<<sol<<'\n';
}
return 0;
}