士兵按照右边界从小到大排序,然后依次寻找武器中最小的满足区间的
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const double PI = acos(-1.0);
template <class T> inline T MAX(T a, T b){if (a > b) return a;return b;}
template <class T> inline T MIN(T a, T b){if (a < b) return a;return b;}
const int N = 111;
const int M = 11111;
const LL MOD = 1000000007LL;
const int dir[4][2] = {1, 0, -1, 0, 0, -1, 0, 1};
const int INF = 0x3f3f3f3f;
struct node
{
int l, r;
}so[3333];
int w[40100];
inline bool cmp(node a, node b)
{
return a.r < b.r;
}
int main()
{
int n, m;
while (scanf("%d%d", &n, &m) != EOF)
{
int i, j, k;
for (i = 0; i < n; ++i)
{
scanf("%d%d", &so[i].l, &so[i].r);
}
multiset < int > s;
multiset < int > ::iterator it;
for (i = 0; i < m; ++i)
{
scanf("%d", &k);
s.insert(k);
}
sort(so, so + n, cmp);
int ans = 0;
for (i = 0; i < n; ++i)
{
it = s.lower_bound(so[i].l);
if (it != s.end() && *it <= so[i].r)
{
ans++;
s.erase(it);
}
}
printf("%d\n", ans);
}
return 0;
}