//#include <bits/stdc++.h>
 
#include <iostream>
#include <algorithm>
 
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <cstring>
#include <string>
#include <utility>
#include <array>
#include <complex>
#include <valarray>
 
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>
 
 
using namespace std;
#define int long long
 
typedef long long ll;
typedef unsigned long long ull;
//typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;
 
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
 
const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const ll INFLL = 1LL<<62;
const double EPS = 1e-12;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;
 
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod
#define inside(y, x, h, w) (0 <= (y) && (y) < (h) && 0 <= (x) && (x) < (w)) ? true : false

int n;
int a[300000 + 5], b[300000 + 5];
pair<int, int> sa[300000 + 5], sb[300000 + 5];

struct segtree {
    int size;
    vector<pair<long long, int>> node;

    segtree (int n) : size(1) {
        while (size < n) size *= 2;
        node.resize(2 * size - 1, make_pair(1e12, 300000 + 5));
		rep(i, n) node[i + size - 1].se = i;
    }

    void update(int k, int a) {
        k += size - 1;
        node[k].fi = a;
        while (k > 0){
            k = (k - 1) / 2;
			if (node[2 * k + 1] < node[2 * k + 2]) {
				node[k].fi = node[2 * k + 1].fi;
				node[k].se = node[2 * k + 1].se;
			}
			else {
				node[k].fi = node[2 * k + 2].fi;
				node[k].se = node[2 * k + 2].se;
			}
        }
    }
    //[queryL: queryR)
    pair<long long, int> get(int queryL, int queryR, int k = 0, int nodeL = 0, int nodeR = -1) {
        if (nodeR == -1) nodeR = size;
        if (nodeR <= queryL || queryR <= nodeL) return make_pair(INFLL / 10, -1);
        if (queryL <= nodeL && nodeR <= queryR) return make_pair(node[k].fi, node[k].se);
        else{
            int nodeM = (nodeL + nodeR) / 2;
            pair<long long, int> vl = get(queryL, queryR, 2 * k + 1, nodeL, nodeM);
            pair<long long, int> vr = get(queryL, queryR, 2 * k + 2, nodeM, nodeR);
			if (vl.fi < vr.fi) return make_pair(vl.fi, vl.se);
			else return make_pair(vr.fi, vr.se); 
        }
    }
};

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
	cin >> n;
	rep(i, n) {
		cin >> a[i] >> b[i];
		sa[i].fi = a[i];
		sa[i].se = i;
		sb[i].fi = b[i];
		sb[i].se = i;

	}
	sort(sa, sa + n);
	sort(sb, sb + n);
	int l = 0, r = n + 1;
	while (r -  l > 1) {
		segtree seg(n);
		rep(i, n) seg.update(i, a[i]);
		int m = (r + l) / 2;
		int sum_a = 0;
		bool checked[n] = {};
		rep(i, m - 1) {
			int idx = sa[i].se;
			seg.update(idx, 1e12);
			checked[idx] = true;
			sum_a += sa[i].fi;
		}
		/*
		rep(i, n) cout << sa[i].fi << " " << sa[i].se << " ";
		cout << endl;
		cout << m << " " << sum_a << endl; 
		*/
		bool ok = false;
		rep(i, n) {
			int idx = sb[i].se;
			if (checked[idx]) {
				pair<int, int> p = seg.get(0, n);
				if (p.fi == 1e12) break;
				checked[p.se] = true;
				seg.update(p.se, 1e12);
				if (sum_a + p.fi <= m * b[idx]) {
					ok = true;
					break;
				}
				sum_a -= a[idx];
				sum_a += p.fi;
			}
			else {
				checked[idx] = true;
				seg.update(idx, 1e12);
				if (sum_a + a[idx] <= m * b[idx]) {
					ok = true;
					break;
				}
			}
		}
		if (ok) l = m;
		else r = m;
	}
	cout << l << endl;
}

Measured memory_bytes: 33916