[题解]ZOJ Monthly, May 2011 » ZOJ3508

ZOJ3508
ZOJ3508.cpp


#include <set>
#include <cstdio>
#include <utility>
#include <algorithm>

using namespace std;

const int MAXN = 65536;

pair<int, int> p[MAXN];

int main() {
	int n, m, t;
	multiset<int> s;
	multiset<int>::iterator it;

	while (scanf("%d%d", &n, &m) != EOF) {
		for (int i = 0; i < n; ++i) {
			scanf("%d%d", &p[i].second, &p[i].first);
		}
		s.clear();
		for (int i = 0; i < m; ++i) {
			scanf("%d", &t);
			s.insert(t);
		}
		sort(p, p + n);
		t = 0;
		for (int i = 0; i < n; ++i) {
			it = s.lower_bound(p[i].second);
			if (it != s.end() && *it <= p[i].first) {
				++t;
				s.erase(it);
			}
		}
		printf("%d\n", t);
	}

	return 0;
}

//Run ID 	Submit Time 	Judge Status 	Problem ID 	Language 	Run Time(ms) 	Run Memory(KB) 	User Name 	Admin
//745 	2011-04-27 03:53:16 	Accepted 	I 	C++ 	30 	1484 	watashi@ArcOfDream 	Source
4 Responses to “ZOJ3508”
  1. AND1989 says:

    为什么,存贮武器的pair p[MAXN];要开那么大,如果开小了就Segmentation Fault,我在浙大的OJ经常遇到这种情况 ,而题目要求不是只有2500吗?求神牛解析,谢谢!

  2. Yular says:

    台湾的神人真的很强啊。。。。。。。他们平时是怎么训练的呢?

  3.  
Leave a Reply