#include <bits/stdc++.h>
#define INF 1e9
#define eps 1e-6
typedef long long ll;
using namespace std;

struct P{
	ll a, b;
}p[200010];
int n;
ll now, las;

bool cmp(P x, P y){
	return x.a + 2 * x.b > y.a + 2 * y.b;
}

int main(){

	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> p[i].b >> p[i].a;
	sort(p + 1, p + n + 1, cmp);
	for(int i = 1; i <= n; i++)
		las += p[i].b;
	if(now > las){
		puts("0");
		return 0;
	}
	for(int i = 1; i <= n; i++){
		now += p[i].b + p[i].a, las -= p[i].b;
		if(now > las){
			cout << i << endl;
			return 0;
		}
	}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
  int64_t n, takahashi=0, aoki=0, count=0;
  cin >> n;
  priority_queue<int64_t> q;
  for(int i=0; i<n; i++){
    int64_t a, b;
    cin >> a >> b;
    aoki += a;
    q.push(2*a+b);
  }
  while(takahashi<=aoki){
    takahashi += q.top();//-q.top().second;
    //aoki -= q.top().second;
    q.pop();
    count++;
  }
  cout << count << endl;
}