#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 150010
struct node {
ll t1, t2;
bool operator < (const node &T) const {
return t2 == T.t2 ? t1 < T.t1 : t2 < T.t2;
}
} a[N];
int n, ans;
ll tim;
priority_queue < ll > q;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%lld %lld", &a[i].t1, &a[i].t2);
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; ++i) {
q.push(a[i].t1);
if (tim + a[i].t1 <= a[i].t2) {
++ans;
tim += a[i].t1;
} else {
if (tim - q.top() + a[i].t1 <= a[i].t2) {
tim += a[i].t1 - q.top();
q.pop();
}
}
}
printf("%d", ans);
return 0;
}
以上代码直接将建筑弹到堆里了,没有判断是否修当前建筑并进行弹出,然后下面反悔的时候就直接取堆顶了。
蒟蒻当时没多想,把建筑弹入堆的步骤放到 if 判断外面就直接过了,现在想起来好像有点假 qwq