//  Bug Party.cpp
//  2013/01/17.

#if 1

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

struct Bug
{	ll a, b; Bug(ll a=0, ll b=0) : a(a), b(b) {} }; // a=放出量 b=許容量

bool cmpb(const Bug& l, const Bug& r)
{	return l.b > r.b; }

bool check(const vector<Bug>& bugs, ll n)
{
	ll foo = 0;
	priority_queue<ll> que;
	
	rep(i, n)
	{
		foo += bugs[i].a;
		que.push(bugs[i].a);
	}
	
	bool flag = (foo <= bugs[n-1].b * n) || (foo <= bugs[bugs.size()-1].b * n);
	
	REP(i, n, bugs.size())
	{
		if(que.top() > bugs[i].a)
		{
			foo -= que.top() - bugs[i].a;
			que.pop();
			que.push(bugs[i].a);
		}
		
		flag |= foo <= bugs[i].b * n;
	}

	return flag;
}

int main()
{
	int N;
	cin >> N;
	
	vector<Bug> bugs(N);
	rep(i, N) cin >> bugs[i].a >> bugs[i].b;
	
	sort(ALL(bugs), cmpb);

	ll ok = 0;
	for(ll ub = N+1; ub - ok > 1; )
	{
		ll mid = (ok + ub) / 2;
		
		if(check(bugs, mid)) ok = mid;
		else ub = mid;
	}
	
	cout << ok << endl;
}

#endif