//#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <cassert>
#include <algorithm>
#include <cmath>
#include <set>
#include <climits>
#include <map>
using namespace std;
#define SPEED_UP iostream::sync_with_stdio(false);
#define FIXED_FLOAT cout.setf(ios::fixed, ios::floatfield);
#define rep(i, s, t) for(int (i)=(s);(i)<=(t);++(i))
#define urep(i, s, t) for(int (i)=(s);(i)>=(t);--(i))
#define in_bound(l, r, i) (l)<=(i)&&(i)<(r)
typedef long long LL;
const int Maxn = 3000;
const int inf = INT_MAX/2;
struct st{
int x, y, t, s;
st(int x, int y, int t, int s):x(x), y(y), t(t), s(s){}
bool operator < (const st &rhs) const {
return t > rhs.t;
}
};
struct Edge{
int from, to, ci, pi, ri;
};
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
int c, l;
vector<pair<int, int> > a, b;
LL solve() {
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int i = 0, j = 0, sa = a.size(), sb = b.size(), ans = 0;
while (i < sa && j < sb) {
if (a[i].second < b[j].first) {
++i;
continue;
}
if (a[i].first > b[j].first) {
++j;
continue;
}
++ans;
//cout << "cow: " << a[i].first << ' ' << a[i].second << " get " << b[j].first << endl;
++i;
--b[j].second;
if (b[j].second == 0) ++j;
}
return ans;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
#endif
SPEED_UP
while (cin >> c >> l) {
int x, y;
a.clear();
b.clear();
rep(i, 0, c-1) {
cin >> x >> y;
a.push_back(make_pair(x, y));
}
rep(i, 0, l-1) {
cin >> x >> y;
if (y)
b.push_back(make_pair(x, y));
}
cout << solve() << endl;
}
return 0;
}
http://blog.csdn.net/sdj222555/article/details/10698641
poj 1905 (贪心失败 = =)
最新推荐文章于 2017-10-15 17:13:24 发布