1 1 3 2 1 8 2 7 2 6 2
13
#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;
struct P
{
int x,y;
} hehe[1000];
struct C
{
int x,y;
} he[1000];
bool cmd1(P a,P b)
{
return a.x<b.x;
}
bool cmd2(C a,C b)
{
if(a.x==b.x)
{
return a.y<b.y;
}
else
{
return a.x>b.x;
}
}
int main()
{
int n,m;
int t;
int i,j;
while(cin>>t)
{
while(t--)
{
int ans=0;
cin>>n>>m;
for(i=0; i<n; i++)
{
cin>>hehe[i].x>>hehe[i].y;
}
for(i=0; i<m; i++)
{
cin>>he[i].x>>he[i].y;
}
sort(hehe,hehe+n,cmd1);
sort(he,he+m,cmd2);
for(i=0; i<n; i++)
{
for(j=0; j<m; j++)
{
if(hehe[i].x>=he[j].y&&he[j].x!=0)
{
he[j].x=0;
break;
}
}
}
for(i=0; i<m; i++)
{
ans+=he[i].x;
}
cout<<ans<<endl;
}
}
return 0;
}
原文:http://www.cnblogs.com/yinghualuowu/p/5003122.html