#include<bits/stdc++.h>
const int N = 5005;
const long long inf = 1e18;
using namespace std;

typedef pair <int, int> ii;
vector <ii> mv;

int n, ans;
long long dp[N][N], Min[N];

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++){
        int x, y; cin >> x >> y;
        x += y;
        mv.push_back(ii(x, y));
    }
    sort(mv.begin(), mv.end());
    for (int i = 0; i < N; i++) Min[i] = inf;
    Min[0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = i; j >= 1; j--){
            if (mv[i-1].first - mv[i-1].second >= Min[j-1]) dp[i][j] = Min[j-1] + mv[i-1].second;
            else dp[i][j] = inf;
            Min[j] = min(Min[j], dp[i][j]);
            if (dp[i][j] != inf) ans = max(ans, j);
        }
    }
    cout << ans;
}

#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
ll dp[5555];
int main(void)
{
    int n;
    cin>>n;
    vector < pii > s(n);
    for (auto &it : s)
        cin>>it.fi>>it.se;
    sort(all(s),[&](pii x,pii y)
         {
            return (x.fi + x.se) < (y.fi + y.se);
         });
    for (int i = 1;i <= n;++i)
        dp[i] = 1e18;
    dp[0] = 0;
    for (auto it : s)
        for (int i = n;i;--i)
            if (dp[i - 1] <= it.fi)
                smin(dp[i],dp[i - 1] + it.se);
    int ans = 0;
    for (int i = 0;i <= n;++i)
        if (dp[i] < 1e18)
            ans = i;
    cout << ans << '\n';
    return 0;
}
