标签:clu void can cst line pen pre bzoj ble
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1029
经典的贪心问题,不解释。
#include <cstdio>
#include <algorithm>
#include <queue>
const int maxn = 150005;
int n, ima, ans;
struct st {
int x, y;
} a[maxn];
std::priority_queue<int> hp;
bool cmp(const st & aa, const st & ss) {
return aa.y < ss.y;
}
int main(void) {
//freopen("in.txt", "r", stdin);
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d%d", &a[i].x, &a[i].y);
}
std::sort(a, a + n, cmp);
for (int i = 0; i < n; ++i) {
if (ima + a[i].x <= a[i].y) {
ima += a[i].x;
++ans;
hp.push(a[i].x);
}
else if (a[i].x < hp.top()) {
ima = ima - hp.top() + a[i].x;
hp.pop();
hp.push(a[i].x);
}
}
printf("%d\n", ans);
return 0;
}
_bzoj1029 [JSOI2007]建筑抢修【贪心 堆】
标签:clu void can cst line pen pre bzoj ble
原文地址:http://www.cnblogs.com/ciao-sora/p/6375646.html