#include <iostream>
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <set>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>

using namespace std;

#define f first
#define s second

typedef long long LLI;



int n;


pair<int, pair<int, int> > p[5001];
long long dp[5001][5001];

const long long inf = 1e15;

int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; ++i) {
		scanf("%d %d", &p[i].s.f, &p[i].s.s);
		p[i].f = p[i].s.f + p[i].s.s;
	}
	sort(p, p + n);
	
	for(int i = 0; i < 5001; ++i) {
		dp[i][0] = 0;
		for(int j = 1; j < 5001; ++j) dp[i][j] = inf;
	}
	

	int ans = 1;

	dp[0][1] = p[0].s.s;

	for(int i = 1; i < n; ++i) {
		for(int j = 1; j <= n; ++j) {
			dp[i][j] = dp[i-1][j];
			if(p[i].s.s + dp[i-1][j-1] < dp[i][j] && p[i].s.f >= dp[i-1][j-1]) dp[i][j] = p[i].s.s + dp[i-1][j-1];
			if(dp[i][j] < inf) ans = max(ans, j);
		}
	}
	printf("%d\n", ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std ;

const int N = 5010 ;
const long long inf = 10000000000000000 ;
pair<int,int> zab [ N ] ;

bool cmp ( pair<int,int> A, pair<int,int> B ) {
    return A.first + A.second < B.first + B.second ;
}

long long dp [ N ][ 3 ];

int main() {
 //   freopen("input.txt", "r", stdin) ;
    int n ; cin >> n ;
    for ( int i = 0 ; i < n ; ++i )
        cin >> zab[i].first >> zab[i].second ;
    sort ( zab, zab+n, cmp ) ;
    int ans =0 ;
    for ( int i = 1 ; i <= n ; ++i ) {
        for ( int j = 0 ; j < n ; ++j ) {
            if ( i == 1 ) dp[j][i%2] = zab[j].first ;
            else if ( j + i <= n ) dp[j][i%2] = min ( 1ll*zab[j].first, dp[j+1][(i-1)%2] - zab[j].second );
            else dp[j][i%2] = -inf ;
        }
        bool kPosible = (dp[n-1][i%2] >= 0ll) ;
        for ( int j = n-2 ; j >= 0 ; --j ) {
            dp[j][i%2] = max ( dp[j][i%2], dp[j+1][i%2] ) ;
            kPosible |= (dp[j][i%2]>=0ll) ;
        }
        if ( kPosible ) ans = i ;
    }
    cout << ans << '\n' ;
}
