#include<bits/stdc++.h>
#define int long long

using namespace std;

bool cmp(pair<int,int> &a,pair<int,int> &b)
{
    return 2*a.first+a.second>2*b.first+b.second;
}

int32_t main()
{
    int n;
    cin>>n;
    vector< pair<int,int> > v(n);
    int a=0,b=0;
    for(int i=0;i<n;i++)
    {
        cin>>v[i].first >>v[i].second;
        a+=v[i].first;
    }

    sort(v.begin(),v.end(),cmp);
    /*for(auto u: v)
    {
        cout<< u.first <<" "<<u.second<<endl;
    }*/
    int ans = 0;
    for(int i=0;i<n;i++)
    {
        ans++;
        b+=2*v[i].first + v[i].second;
        if(b>a) break;
    }
    cout<<ans<<endl;
    return 0;
}
#include<bits/stdc++.h>
#define rep(i,n) for ( int i=0; i< (n); ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

// aoki = sum(not go)ai
// takahashi = sum(go)(ai+bi)
//takahashi>aoki => sum(go)bi+sum(go)(ai)> sum(not go)(ai)
//takahashi>aoki => sum(go)bi + 2sum(go)(ai) > sum(all)(ai)

bool OK( int t, int n, ll asum, vector<ll> &win ){
    ll ans = 0;
    rep(i,t) ans += win[n-1-i];
    return ans>asum;
}

int main(){
    int n;
    cin >> n;
    vector<ll> win(n);
    ll asum = 0;
    rep(i,n){
        ll a,b;
        cin >> a >> b;
        asum += a;
        win[i] = b + 2*a;
    }
    sort(win.begin(),win.end());
    int t1 = 0, t2=n;
    while(t2-t1>1){
        int piv = (t1+t2)/2;
        if( OK(piv,n,asum,win) ) t2=piv;
        else t1=piv;
    }
    cout << t2 << endl;
    return 0;
}