#include <cstdio>
#include <functional>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int n;
	scanf("%d",&n);
	vector<pair<int,int> > dat;
	dat.reserve(n);
	for (int i = 0; i < n;i ++) {
		int a,b;
		scanf("%d%d",&a,&b);
		dat.push_back(make_pair(b,a));
	}
	sort(dat.begin(), dat.end());
	vector<int> maxheap, minheap;
	long long cursum = 0;
	maxheap.reserve(n);
	minheap.reserve(n);
	int ans = 0;
	for (int i = n-1; i >= 0; i--) {
		int a = dat[i].second;
		int b = dat[i].first;
		long long limit = b * (long long) maxheap.size() + b - a;
		while(!minheap.empty() && cursum + minheap[0] <= limit + b) {
			cursum += minheap[0];
			limit += b;
			maxheap.push_back(minheap[0]);
			push_heap(maxheap.begin(), maxheap.end());
			pop_heap(minheap.begin(), minheap.end(), greater<int>());
			minheap.pop_back();
		}
		while(cursum > limit && !maxheap.empty()) {
			cursum -= maxheap[0];
			limit -= b;
			minheap.push_back(maxheap[0]);
			push_heap(minheap.begin(), minheap.end(),greater<int>());
			pop_heap(maxheap.begin(), maxheap.end());
			maxheap.pop_back();
		}
		if (cursum <= limit)
			ans = max(ans, (int)maxheap.size() + 1);
		if (!minheap.empty() && ans >= maxheap.size() + i + (b-1)*(long long)i / minheap[0] + 2)
			break;
		if (i && cursum + a <= dat[i-1].first * (long long)(maxheap.size() + 2) - a) {
			cursum += a;
			maxheap.push_back(a);
			push_heap(maxheap.begin(), maxheap.end());
		} else {
			minheap.push_back(a);
			push_heap(minheap.begin(), minheap.end(), greater<int>());
		}
	}
	printf("%d\n", ans);
	return 0;
}