#include<bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define MAX 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define zoom ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
    return (b.ff + b.ss > a.ff + a.ss);
}

int main() {


    zoom;
    ll n, i, j;
    cin>>n;
    vector<pair<ll, ll> >A(n);
    for(i = 0; i < n; i += 1)
        cin>>A[i].ff>>A[i].ss;
    sort(A.begin(), A.end(), cmp);
    vector<vector<ll> > dp(n, vector<ll>());
    dp[0].pb(0);
    dp[0].pb(A[0].ss);
    for(i = 1; i < n; i += 1) {
        dp[i].pb(0);
        for(j = 1; j <= i; j += 1) {
            ll temp1 = dp[i - 1][j];
            ll temp2 = -1;
            if(dp[i - 1][j - 1] != -1 && dp[i - 1][j - 1] <= A[i].ff)
                temp2 = dp[i - 1][j - 1] + A[i].ss;            
            if((temp1 == -1 && temp2 == - 1))
                dp[i].pb(-1);
            else if(temp1 == -1)
                dp[i].pb(temp2);
            else if(temp2 == -1)
                dp[i].pb(temp1);
            else
                dp[i].pb(min(temp1, temp2));
        }
        if(dp[i - 1][j - 1] != -1 && dp[i - 1][j - 1] <= A[i].ff)
            dp[i].pb(dp[i - 1][j - 1] + A[i].ss);
        else
            dp[i].pb(-1); 
    }
    ll ans = -1;
    for(i = n - 1; i >= 0; i -= 1) {
        for(j = i + 1; j >= 1; j -= 1) {
            if(dp[i][j] != -1)
            ans = max(ans, j); 
        }
    }
    cout<<ans;
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;


int main() {
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    vector<P> c(n);
    
    REP(i, n) cin >> a[i] >> b[i];
    REP(i, n) {
        c[i].first = a[i] + b[i];
        c[i].second = i;
    }
    sort(ALL(c));
    reverse(ALL(c));

    ll aoki = 0, takahashi = 0;
    REP(i, n) {
        if(i % 2 == 0) {
            aoki += a[c[i].second];
        } else {
            takahashi += b[c[i].second];
        }
    }

    cout << aoki - takahashi << endl;

    return 0;
}