// EXCHANGE ARGUMENTS
// https://codeforces.com/blog/entry/63533

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

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

typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;

//Loop defines
#define rep(i,n) for(int i=0;i<n;++i)
#define dow(i,n) for(int i=n-1;i>=0;--i)

//Print defines
#define pr(_) cout << _ << endl
#define prln() cout << endl
#define pra(a,n) rep(i,n) cout<<a[i]<<" "; prln()
#define prv(v) rep(i,v.size()) cout<<v[i]<<" "; prln()
#define endl "\n"

//Natural set
#define fill_nat(v,n) rep(i,n) v[i]=i // or use iota
// const ll inf = numeric_limits<ll>::max() / 2;

//Vector
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front

//Data structures
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set

#define st first
#define nd second

// INT_MAX


// ======[ DEBUG TEMPLATE ]======
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;
// ==============================


int boxPyramid(vector<pii> boxes) {
    sort(boxes.begin(), boxes.end(), [](pii a, pii b) {
        return a.st + a.nd < b.st + b.nd;
    });
    int n = boxes.size();

    ll total = 0;
    priority_queue<ll> bags;

    for (int i=0; i<n; ++i) {
        total += boxes[i].nd;
        bags.push(boxes[i].nd);
        if (total > boxes[i].st + boxes[i].nd) {
            total -= bags.top();
            bags.pop();
        }
        // ans = max(ans, optimal.size() - 1);
        // deb(total);
        // deb(optimal);
    }

    return bags.size();
}

int main() {
// #ifndef ONLINE_JUDGE 
//     freopen("input.txt", "r", stdin); 
//     freopen("output.txt", "w", stdout); 
// #endif
    cin.sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int size;
    cin >> size;
    vector<pii> v;
    for (int i=0; i<size; ++i) {
        int str, weight;
        cin >> str >> weight;
        v.push_back(make_pair(str, weight));
    }
    int ans = boxPyramid(v);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512