N = int(eval(input()))

A = list(map(int, input().split()))

B = list(map(int, input().split()))





# 各テストの余裕を小さい順に

margins = [[i, a - b] for i, (a, b) in enumerate(zip(A, B)) if (a - b) > 0]

margins.sort(key=lambda m: m[1])



# 調整済みA

X = A[:]



# 余裕が大きい方から使っていく

for i in range(N):

    while (A[i] < B[i]) and margins:

        cost = B[i] - A[i]

        mi, margin = margins[-1]



        if margin > cost:

            margins[-1][1] -= cost

            A[mi] -= cost

            A[i] += cost



        else:

            margins.pop()

            A[mi] -= margin

            A[i] += margin





ans = 0

for a, b, x in zip(A, B, X):

    if b - a > 0:

        print((-1))

        break



    if a != x:

        ans += 1

else:

    print(ans)

from itertools import accumulate

N = int(eval(input()))

A = list(map(int, input().split()))

B = list(map(int, input().split()))





surplus = [(a - b) for a, b in zip(A, B) if (a - b) > 0]

surplus.sort(reverse=True)

surplus_acc = [0] + list(accumulate(surplus))



short = [(b - a) for a, b in zip(A, B) if (b - a) > 0]

need = sum(short)

short_num = len(short)





if need > sum(surplus):

    print((-1))

    exit()

else:

    for i in range(len(surplus_acc)):

        if surplus_acc[i] >= need:

            print((i + short_num))

            exit()

N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# 各テストの余裕を小さい順に
margins = [[i, a - b] for i, (a, b) in enumerate(zip(A, B)) if (a - b) > 0]
margins.sort(key=lambda m: m[1])
# 調整済みA
X = A[:]
# 余裕が大きい方から使っていく
for i in range(N):
    while (A[i] < B[i]) and margins:
        cost = B[i] - A[i]
        mi, margin = margins[-1]
        if margin > cost:
            margins[-1][1] -= cost
            A[mi] -= cost
            A[i] += cost
        else:
            margins.pop()
            A[mi] -= margin
            A[i] += margin
ans = 0
for a, b, x in zip(A, B, X):
    if b - a > 0:
        print((-1))
        break
    if a != x:
        ans += 1
else:
    print(ans)

from itertools import accumulate

N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
surplus = [(a - b) for a, b in zip(A, B) if (a - b) > 0]
surplus.sort(reverse=True)
surplus_acc = [0] + list(accumulate(surplus))
short = [(b - a) for a, b in zip(A, B) if (b - a) > 0]
need = sum(short)
short_num = len(short)
if need > sum(surplus):
    print((-1))
    exit()
else:
    for i in range(len(surplus_acc)):
        if surplus_acc[i] >= need:
            print((i + short_num))
            exit()

+from itertools import accumulate + -# 各テストの余裕を小さい順に -margins = [[i, a - b] for i, (a, b) in enumerate(zip(A, B)) if (a - b) > 0] -margins.sort(key=lambda m: m[1]) -# 調整済みA -X = A[:] -# 余裕が大きい方から使っていく -for i in range(N): -    while (A[i] < B[i]) and margins: -        cost = B[i] - A[i] -        mi, margin = margins[-1] -        if margin > cost: -            margins[-1][1] -= cost -            A[mi] -= cost -            A[i] += cost -        else: -            margins.pop() -            A[mi] -= margin -            A[i] += margin -ans = 0 -for a, b, x in zip(A, B, X): -    if b - a > 0: -        print((-1)) -        break -    if a != x: -        ans += 1 +surplus = [(a - b) for a, b in zip(A, B) if (a - b) > 0] +surplus.sort(reverse=True) +surplus_acc = [0] + list(accumulate(surplus)) +short = [(b - a) for a, b in zip(A, B) if (b - a) > 0] +need = sum(short) +short_num = len(short) +if need > sum(surplus): +    print((-1)) +    exit() -    print(ans) +    for i in range(len(surplus_acc)): +        if surplus_acc[i] >= need: +            print((i + short_num)) +            exit()