#include<bits/stdc++.h>
using namespace std;
#define N 150005
typedef long long ll;
typedef struct node { ll t1,t2; } B;
B b[N];
bool cmp(const B & a,const B & b) { return a.t2 < b.t2; }
int main(){
ll n,t = 0,ans = 1;
cin >> n;
for(ll i = 1;i <= n;i ++)
cin >> b[i].t1 >> b[i].t2;
sort(b + 1,b + 1 + n,cmp);
t = b[1].t1;
for(ll i = 2;i <= n;i ++)
{
if(t + b[i].t1 <= b[i].t2)
{
t += b[i].t1;
ans ++;
}
}
cout << ans << endl;
return 0;
}
思路大体就是贪心,每次尽可能抢修最早报废的建筑
是不是思路有漏洞,大佬帮忙看下,谢谢