Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1346 Accepted Submission(s): 336
#include <map> #include <set> #include <cmath> #include <queue> #include <stack> #include <cstdio> #include <string> #include <vector> #include <cstring> #include <iostream> #include <algorithm> #define ll long long using namespace std; const int maxn = 100005; struct Node { int x, y, id; }mc[maxn], ts[maxn]; int cnt[maxn]; bool cmp(Node a, Node b) { if (a.x!=b.x) return a.x>b.x; return a.y>b.y; } int main() { int n, m; while (scanf("%d%d", &n, &m)==2) { for (int i=0; i<n; i++) { scanf("%d%d", &mc[i].x, &mc[i].y); } for (int i=0; i<m; i++) { scanf("%d%d", &ts[i].x, &ts[i].y); } sort(ts, ts+m, cmp); sort(mc, mc+n, cmp); memset(cnt, 0, sizeof(cnt)); int num=0; ll ans=0; for (int i=0, j=0; i<m; i++) { while (j<n&&mc[j].x>=ts[i].x) { cnt[mc[j].y]++; j++; } for (int k=ts[i].y; k<=100; k++) { if (cnt[k]) { cnt[k]--; num++; ans+=500*ts[i].x+2*ts[i].y; break; } } } printf("%d %I64d\n", num, ans); } return 0; }
hdu 4864 Task 贪心,布布扣,bubuko.com
原文:http://www.cnblogs.com/mandora/p/3862589.html