N = int(input())
ab = [list(map(int, input().split())) for _ in range(N)]
aoki = 0
taka = 0
for a, b in ab:
    aoki += a
ab.sort(key=lambda x: sum(x) + x[0], reverse=True)
ans = 0
for a, b in ab:
    aoki -= a
    taka += a + b
    ans += 1
    if taka > aoki:
        break
print(ans)

33c494ef0bda88f436582f4588b3e7c1654d493a
<mask token>

<mask token>
for a, b in ab:
    aoki += a
ab.sort(key=lambda x: sum(x) + x[0], reverse=True)
<mask token>
for a, b in ab:
    aoki -= a
    taka += a + b
    ans += 1
    if taka > aoki:
        break
print(ans)

N = int(input())
ab = [list(map(int, input().split())) for _ in range(N)]
aoki = 0
taka = 0
for a, b in ab:
    aoki += a
ab.sort(key=lambda x: sum(x) + x[0], reverse=True)
ans = 0
for a, b in ab:
    aoki -= a
    taka += a + b
    ans += 1
    if taka > aoki:
        break
print(ans)
