#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef pair<int,int> P;
int N;
vector<P> ps;
signed main(){
	cin>>N;
	rep(i,N){
		int a,b;
		cin>>b>>a;
		ps.pb(P(b+a,a));
	}
	sort(all(ps));
	priority_queue<int> qa;
	int T = 0;
	int ans = 0;
	rep(i,N){
		int a = ps[i].sc;
		int b = ps[i].fs;
		T+=a;
		ans++;
		qa.push(a);
		if(T>b){
			int rm = qa.top();
			qa.pop();
			T -= rm;
			ans--;
		}
	}
	cout<<ans<<endl;
}
