题目链接
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
const int N = 150010;
#define int long long
int n;
typedef pair<int,int>PII;
priority_queue<int,vector<int>,less<int>>heap;
PII a[N];
signed main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
int t1,t2;
cin>>t1>>t2;
a[i]={t2,t1};
}
sort(a+1,a+n+1);
int res=0,tmp=0;
for(int i=1;i<=n;i++)
{
if(tmp+a[i].second<=a[i].first)
{
tmp+=a[i].second;
res++;
heap.push(a[i].second);
}
else if(heap.top()>a[i].second)
{
tmp-=heap.top();
heap.pop();
heap.push(a[i].second);
tmp+=a[i].second;
}
}
cout<<res<<endl;
}