CodeEff/ECCO huggingface dataset:
# Original solution
def main():
  n = int(eval(input()))
  a = input_list()
  b = input_list()
  c = [a[i] - b[i] for i in range(n)]
  s = sum(c)
  if s < 0:
    print((-1))
    exit(0)
  c.sort()
  ans = 0
  for i in range(n):
    if c[i] < 0:
      pass
    elif c[i] <= s:
      ans += 1
      s -= c[i]
    else:
      break
  print((n-ans))
    
  
def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return list(map(str, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

import math
import fractions
import collections
from functools import reduce
main()

# Optimized solution
def main():
    n = int(eval(input()))
    A = input_list()
    B = input_list()
    C = [A[i] - B[i] for i in range(n)]
    s = sum(C)
    if s < 0:
        print((-1))
        exit()
    C.sort()
    ans = 0
    for i in range(n):
        if C[i] < 0:
            continue
        elif C[i] <= s:
            ans += 1
            s -= C[i]
        else:
            break
    print((n-ans))
    

def input_list():
    return list(map(int, input().split()))

if __name__ == "__main__":
    main()
# Original solution
from itertools import accumulate

n=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))

if sum(a)<sum(b):
 print((-1))
 exit()

c=[]
lack=0
cnt=0
for i,j in zip(a,b):
  t=i-j
  if i-j>=0:
    c.append(t)
  else:
    lack+=abs(t)
    cnt+=1

if cnt==0:
  print((0))
  exit()

c=sorted(c,reverse=True)
ru=list(accumulate(c))
for i in range(len(ru)):
  if ru[i]>=lack:
    cnt+=i+1
    break

print(cnt)

# Optimized solution
from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(eval(input()))
a=lnii()
b=lnii()

plus=[]
minus=0
ans=0
for i in range(n):
  if a[i]<b[i]:
    minus+=b[i]-a[i]
    ans+=1
  else:
    plus.append(a[i]-b[i])

if minus==0:
  print((0))
  exit()

plus.sort(reverse=True)
for i in range(len(plus)):
  minus-=plus[i]
  ans+=1
  if minus<=0:
    print(ans)
    exit()

print((-1))
# Original solution
n = int(eval(input()))
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
if sum(a_list)<sum(b_list):
    print((-1))
else:
    diff_list = [a_list[i]-b_list[i] for i in range(n)]
    cnt=0
    for diff in diff_list:
        if diff<0:
            cnt+=1
    while min(diff_list)<0:
        M = max(diff_list)
        for i in range(n):
            dif = diff_list[i]
            if dif<0 and M+dif>=0:
                M+=dif
                diff_list[i]=0
            elif M+dif<0:
                break
        cnt+=1
    print(cnt)

# Optimized solution
n = int(eval(input()))
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
if sum(a_list)<sum(b_list):
    print((-1))
else:
    diff_list = [a_list[i]-b_list[i] for i in range(n)]
    posi_list=[]
    cnt,diff_sum = 0,0
    for diff in diff_list:
        if diff<0:
            cnt+=1
            diff_sum+=diff
        elif diff>0:
            posi_list.append(diff)
    diff_sum*=(-1)
    posi_list.sort(reverse=True)
    i,S=0,0
    while S<diff_sum:
        S+=posi_list[i]
        i+=1
    print((i+cnt))
# Original solution
from bisect import bisect_right
n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if sum(a) == sum(b):
    print(n)
mp = 0
ans = 0
l = []
for i in range(n):
    if a[i] < b[i]:
        mp -= b[i] - a[i]
    elif a[i] >= b[i]:
        mp += a[i] - b[i]
        l.append(a[i] - b[i])
l.sort()
if mp < 0:
    print((-1))
else:
    for i in range(len(l) - 1):
        l[i + 1] += l[i]
    print((n - bisect_right(l, mp)))

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if sum(a)<sum(b):
  print((-1))
  exit(0)
t=sum(a)-sum(b)
l=[]
for i in range(n):
  if a[i] >= b[i]:
    l.append(a[i]-b[i])
l.sort()
ans=0
for x in l:
  t-=x
  if t<0:
    break
  ans+=1
print((n-ans))
# Original solution
N=eval(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
unmatch=[]
need=0

for i in range(N):
    if A[i]<B[i]:
        unmatch.append(i)
        need+=B[i]-A[i]

Gap=[A[i]-B[i] for i in range(N) if i not in unmatch]
Gap.sort(reverse=True)
Ans=len(unmatch)

while need>0:
    if Ans>=N:
        print("-1")
        exit()
    need-=Gap[Ans-len(unmatch)]
    Ans+=1
print(Ans)

# Optimized solution
N=eval(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
need=0
Ans=0

for a,b in zip(A,B):
    if b>a:
        need+=b-a
        Ans+=1
        
index=0

Gap=[a-b for a,b in zip(A,B)]
Gap.sort(reverse=True)

while need>0:
    if Ans+index>=N:
        break
    need-=Gap[index]
    index+=1
    
if need<=0:
    print(Ans+index)
else:
    print("-1")
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

if sum(A) < sum(B):
    print((-1))
else:
    before = [A[i] - B[i] for i in range(N)]
    before.sort()
    diff = [A[i] - B[i] for i in range(N)]
    # print(diff)
    diff.sort()
    left = 0
    right = N - 1
    while not all([x >= 0 for x in diff]):
        if diff[left] < 0:
            temp = diff[left]
            diff[left] = min(0, diff[left] + diff[right])
            diff[right] -= diff[left] - temp
        if diff[left] == 0:
            if diff[left + 1] < 0:
                left += 1
        if diff[right] == 0:
            if diff[left] < 0:
                right -= 1
    # print(diff)
    cnt = 0
    for i in range(N):
        if before[i] != diff[i]:
            cnt += 1
    print(cnt)

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

if sum(A) < sum(B):
    print((-1))
else:
    before = [A[i] - B[i] for i in range(N)]
    before.sort()
    diff = [A[i] - B[i] for i in range(N)]
    # print(diff)
    diff.sort()
    left = 0
    right = N - 1
    while True:
        if diff[left] < 0:
            temp = diff[left]
            diff[left] = min(0, diff[left] + diff[right])
            diff[right] -= diff[left] - temp
        if diff[left] == 0:
            if diff[left + 1] < 0:
                left += 1
        if diff[right] == 0:
            if diff[left] < 0:
                right -= 1
        if diff[left] == 0:
            break
    # print(diff)
    cnt = 0
    for i in range(N):
        if before[i] != diff[i]:
            cnt += 1
    print(cnt)
# Original solution
N = int(eval(input()))
A =  []
l1 = input().split()
for i in l1:
    A.append(int(i))
B = []
l2 = input().split()
for i in l2:
    B.append(int(i))
if sum(A) < sum(B):
    print((-1))
else:
    z = 0
    ar1 = []
    ar2 = []
    for i in range(N):
        if A[i] < B[i] :
            ar1.append(B[i] - A[i])
        if A[i] > B[i]:
            ar2.append(A[i] - B[i])
    if len(ar1) == 0:
        print((0))
    else:
        ar2.sort(reverse = True)
        temp = 0
        b = 0
        for  i in range(len(ar2)):
            temp += ar2[i]
            if temp >= sum(ar1):
                b = i+1
                break
        print((len(ar1)+b))


# Optimized solution
N = int(eval(input()))
A =  []
l1 = input().split()
for i in l1:
    A.append(int(i))
B = []
l2 = input().split()
for i in l2:
    B.append(int(i))
if sum(A) < sum(B):
    print((-1))
else:
    z = 0
    ar1 = []
    ar2 = []
    for i in range(N):
        if A[i] < B[i] :
            ar1.append(B[i] - A[i])
        if A[i] > B[i]:
            ar2.append(A[i] - B[i])
    if len(ar1) == 0:
        print((0))
    else:
        s = sum(ar1)
        ar2.sort(reverse = True)
        temp = 0
        b = 0
        for  i in range(len(ar2)):
            temp += ar2[i]
            if temp >= s:
                b = i+1
                break
        print((len(ar1)+b))
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
if sum(B) > sum(A):
  print("-1")
  exit()
D = []
for i in range(N):
  D.append(A[i]-B[i])
D.sort()
#print(D)
num = 0
s = 0; t = -1
yoyu = 0
while D[s] < 0:
  if yoyu+D[s] <0:
    num += 1 #ここで一番余裕があるのを取り出す。
    yoyu += D[t]
    t -= 1
  num += 1 #ここで足りない分が足された試験
  yoyu += D[s]
  s += 1
print(num)  

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))

if sum(B)>sum(A):
  print((-1))
  exit()

amari = []
fusoku = []
for i in range(N):
  if A[i] < B[i]:
    fusoku.append(B[i]-A[i])
  elif A[i] > B[i]:
    amari.append(A[i]-B[i])
amari.sort(reverse=True)
ans = len(fusoku)
nokori = sum(fusoku)
now = 0
while nokori > 0:
  nokori -= amari[now]
  now += 1
  ans += 1
print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
K = 0
S = 0
T = []
if sum(A) < sum(B):
    print('-1')
else:
    for i in range(N):
        if A[i] < B[i]:
            K += 1
            S = S + B[i] - A[i]
        elif A[i] > B[i]:
            T.append(A[i] - B[i])
        else:
            continue
    while S > 0:
        S -= max(T)
        T.remove(max(T))
        K += 1
    print(K)

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
K = 0
S = 0
T = []
if sum(A) < sum(B):
    K = -1
else:
    for i in range(N):
        if A[i] < B[i]:
            K += 1
            S = S + B[i] - A[i]
        elif A[i] > B[i]:
            T.append(A[i] - B[i])
        else:
            continue
T.sort()
L = 0
while S > L:
    L += T.pop()
    K += 1
print(K)
# Original solution
# -*- coding: utf-8 -*-


def main():
    from itertools import accumulate

    n = int(eval(input()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    plus = list()
    minus = list()

    for ai, bi in zip(a, b):
        diff = ai - bi

        if diff > 0:
            plus.append(diff)
        elif diff < 0:
            minus.append(diff)

    sorted_plus = list(accumulate([0] + sorted(plus, reverse=True)))
    summed_plus = sorted_plus[-1]
    summed_minus = sum(minus)
    ans = len(minus)

    if summed_plus < abs(summed_minus):
        print((-1))
        exit()

    for i in range(len(sorted_plus)):
        summed = sorted_plus[i] - sorted_plus[0]

        if summed + summed_minus >= 0:
            print(ans)
            exit()

        ans += 1

    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
# -*- coding: utf-8 -*-


def main():
    n = int(eval(input()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    if sum(a) < sum(b):
        print((-1))
    else:
        c = [a[i] - b[i] for i in range(n)]
        minus = [ci for ci in c if ci < 0]
        plus = sorted([ci for ci in c if ci > 0], reverse=True)
        ans = len(minus)
        total = sum(minus)

        if total != 0:
            for index, p in enumerate(plus, 1):
                total += p
                ans += 1

                if total >= 0:
                    print(ans)
                    exit()
        else:
            print(ans)


if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = [A[i] - B[i] for i in range(0,N)]
C.sort()
p = 0
ans = 0
for i in range(0,N):
  if C[i] < 0:
    p += C[i]
    ans += 1
  else:
    break
  if p < 0:
    for j in range(N - 1,0,-1):
      if C[j] > 0:
        p += C[j]
        ans += 1
        C[j] = 0
        break

if sum(A) < sum(B):
  print((-1))
else:
  print(ans)

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = [A[i] - B[i] for i in range(0,N)]
C.sort()
p = 0
ans = 0
j = len(A) - 1
for i in range(0,N):
  if C[i] < 0:
    p += C[i]
    ans += 1
  else:
    break
  if p < 0:
    if C[j] > 0:
      p += C[j]
      ans += 1
      C[j] = 0
      j -= 1

if sum(A) < sum(B):
  print((-1))
else:
  print(ans)
# Original solution
n = int(eval(input()))
score = list(map(int, input().split()))
sum_score = sum(score)
target = list(map(int, input().split()))
sum_target = sum(target)
sub = list([score[x] - target[x] for x in range(n)])
cnt = sum(1 for x in sub if x < 0)
sub.sort()
sub.reverse()

sub_new = [0]
for i in range(n):
    sub_new.append(sub_new[i] + sub[i])

if(sum_score > sum_target):
    if(cnt > 0):
        a, b, ans = 0, 0, 1
        tmp = sub_new[1+a]
        while sum(1 for x in sub if x < 0) > 0:
            if(tmp + sub[-(b+1)] >= 0): 
                tmp += sub[-(b+1)]
                sub[-(b+1)] = 0
                b+=1
            else: 
                sub[-(b+1)] -= tmp
                a+=1
                tmp = sub_new[1+a]
                ans += 1
            #print(tmp, sub, ans)
        print((cnt + ans))
    else: print((0))
else:
    print((-1))

# Optimized solution
n = int(eval(input()))
score = list(map(int, input().split()))
target = list(map(int, input().split()))

sub = [score[i] - target[i] for i in range(n)]
ans = 0

if sum(score) < sum(target): ans = -1
else:
    minus = []
    plus = []
    for i in range(n):
        if(sub[i] < 0): minus.append(-sub[i])
        elif(sub[i] > 0): plus.append(sub[i])
    plus = sorted(plus, reverse = True)
    sum_minus = sum(minus)

    ans += len(minus)
    while sum_minus > 0:
        if sum_minus <= plus[0]:
            plus[0] = 0
            sum_minus = 0
        else:
            sum_minus -= plus.pop(0)
        ans += 1

print(ans)
# Original solution
import collections
n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
plus = []
minus = []
for i in range(n):
    diff = a[i] - b[i]
    if diff >= 0:
        plus.append(diff)
    else:
        minus.append((-1) * diff)
plus.sort(reverse=True)
plus = collections.deque(plus)
if len(minus) == 0:
    print((0))
    exit()
if sum(plus) < sum(minus):
    print((-1))
    exit()
ans = len(minus)
total = sum(minus)
while total > 0:
    total -= plus.popleft()
    ans += 1
print(ans)

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
plus = []
total_minus = 0
for i in range(n):
    diff = a[i] - b[i]
    if diff >= 0:
        plus.append(diff)
    else:
        total_minus += (-1) * diff
plus.sort(reverse=True)
if total_minus == 0:
    print((0))
elif sum(plus) < total_minus:
    print((-1))
else:
    ans = n - len(plus)
    for i in range(n):
        if total_minus <= 0:
            break
        total_minus -= plus[i]
        ans += 1
    print(ans)
# Original solution
import bisect
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted([A[i] - B[i] for i in range(N)])
if sum(C) < 0:
    print((-1))
elif min(C) >= 0:
    print((0))
else:
    D = sorted([i for i in C if i > 0], reverse=True)
    r = [D[0]]
    for i in range(len(D)-1):
        r.append(r[i] + D[i+1])
    print((len([i for i in C if i < 0])+bisect.bisect_left(r, sum(-i for i in C if i < 0))+1))


# Optimized solution
import bisect
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted([A[i] - B[i] for i in range(N)])
if sum(C) < 0:
    print((-1))
elif min(C) >= 0:
    print((0))
else:
    D = [i for i in C if i < 0]
    m = sum(D)
    for i in range(N-1,-1,-1):
        m += C[i]
        if m >= 0:
            print((len(D)-i+N))
            break
# Original solution
N=int(eval(input()))
*A, = list(map(int,input().split()))
*B, = list(map(int,input().split()))
D = sorted(a-B[i] for i,a in enumerate(A))
S = 0
for ans,d in enumerate(D):
    if d>=0:break
    S += d
if S==0:ans = -1
for i,d in enumerate(D[::-1],1):
    S += d
    if S>=0:break
ans = (-1) if S<0 else (ans+i)
print(ans)

# Optimized solution
N=int(eval(input()))
*A,=list(map(int,input().split()))
*B,=list(map(int,input().split()))

C = sorted(a-b for a,b in zip(A,B))
ans = 0
S = 0
for c in C:
    if c>=0:break
    S += c
    ans += 1
for c in C[::-1]:
    if c<=0:break
    if S>=0:break
    S+=c
    ans += 1
if S<0:ans=-1
print(ans)
# Original solution
#!/usr/bin/env python3

# from numba import njit

# input = stdin.readline

# @njit
def solve(n,a,b):
  delta = [b[i] - a[i] for i in range(n)]
  need = list(sorted(x for x in delta if x > 0))
  amari = list(sorted((abs(x) for x in delta if x < 0),reverse=True))
  if sum(need) > sum(amari):
    return -1
  k = 0
  s = 0
  while s < sum(need):
    s += amari[k]
    k += 1
  return k + len(need)
  


def main():
  N = int(eval(input()))
  # N,M = map(int,input().split())
  a = list(map(int,input().split()))
  b = list(map(int,input().split()))
  print((solve(N,a,b)))
  return

if __name__ == '__main__':
  main()


# Optimized solution
#!/usr/bin/env python3

# from numba import njit

# input = stdin.readline

# @njit
def solve(n,a,b):
  delta = [b[i] - a[i] for i in range(n)]
  need = list(x for x in delta if x > 0)
  amari = list(sorted((abs(x) for x in delta if x < 0),reverse=True))
  needScore = sum(need)
  if needScore > sum(amari):
    return -1
  k = 0
  s = 0
  while s < needScore:
    s += amari[k]
    k += 1
  return k + len(need)
  


def main():
  N = int(eval(input()))
  # N,M = map(int,input().split())
  a = list(map(int,input().split()))
  b = list(map(int,input().split()))
  print((solve(N,a,b)))
  return

if __name__ == '__main__':
  main()
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Cm = []
Cp = []
for i in range(N):
	if(A[i]-B[i]<0):
		Cm.append(A[i]-B[i])
	elif(A[i]-B[i]>0):
		Cp.append(A[i]-B[i])
Cm.sort()
Cp.sort()

cnt = 0
nowCp = 0
j = 0

for i in range(len(Cp)):

	if(sum(Cp)<abs(sum(Cm))):
		print((-1))
		break
	elif(len(Cm) == 0):
		print((0))
		break

	nowCp += int(Cp[len(Cp)-(i+1)])
	while(j<len(Cm)):
		if(nowCp>=abs(Cm[len(Cm)-j-1])):
			nowCp -= abs(Cm[len(Cm)-j-1])
			cnt += 1
			j += 1
		else:
			break

	if(cnt == len(Cm)):
		print((cnt+i+1))
		break

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Cm = []
Cp = []
for i in range(N):
	if(A[i]-B[i]<0):
		Cm.append(A[i]-B[i])
	elif(A[i]-B[i]>0):
		Cp.append(A[i]-B[i])
Cm.sort()
Cp.sort()


if(len(Cm) == 0):
	print((0))
	exit(0)
if(sum(Cp)<abs(sum(Cm))):
	print((-1))
	exit(0)

j=0
i = 0
nowCp = int(Cp[len(Cp)-i-1])


while(j<len(Cm)):
	if(nowCp>=abs(Cm[j])):
		nowCp -= abs(Cm[j])
		j += 1
	elif(nowCp<abs(Cm[j]) and i<len(Cp)):
		i += 1
		nowCp += int(Cp[len(Cp)-i-1])

	else:
		break
	

if(j == len(Cm)):
	print((j+i+1))
else:
	print((-1))
# Original solution
N=int(eval(input()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[]
SA=sum(A)
SB=sum(B)
S=SA-SB
cnt=0
if SB>SA:
    print((-1))
    exit()
for a,b in zip(A,B):
    if a>b:
        C.append(a-b)
    elif a==b:
        cnt+=1
for c in sorted(set(C)):
    if S>=C.count(c)*c:
        cnt+=C.count(c)
        S-=C.count(c)*c
    else:
        cnt+=S//c
        S=0
    if S==0:
        break
print((N-cnt))

# Optimized solution
N=int(eval(input()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[]
SA=sum(A)
SB=sum(B)
S=SA-SB
cnt=0
ns=0
if SB>SA:
    print((-1))
    exit()
for a,b in zip(A,B):
    if a>b:
        C.append(a-b)
    elif a<b:
        ns+=b-a
        cnt+=1
C.sort(reverse=True)
for i in range(len(C)):
    if ns>0:
        cnt+=1
        ns-=C[i]
    else:break
print(cnt)
# Original solution
n = int(eval(input()))
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
ABs = sorted([a - b for a, b in zip(As, Bs)])
# print(As, Bs, ABs)
if sum(As) < sum(Bs):
    print((-1))
    exit()
if min(ABs) > 0:
    print((-1))
    exit()
mABs = [ab for ab in ABs if ab < 0]
msum, ans = sum(mABs), len(mABs)
# print(mABs, msum, ans)
now = -1
while msum < 0:
    msum += ABs[now]
    ans += 1
    now -= 1
print(ans)

# Optimized solution
n = int(eval(input()))
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
ABs = [a - b for a, b in zip(As, Bs)]
if sum(As) < sum(Bs) or min(ABs) > 0:
    print((-1))
    exit()
mABs = [ab for ab in ABs if ab < 0]
pABs = [ab for ab in ABs if ab > 0]
ans, t = len(mABs), sum(mABs)
for pab in sorted(pABs, reverse=True):
    if t >= 0:
        break
    ans += 1
    t += pab
print(ans)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted([a[i] - b[i] for i in range(n)])
k = sum(x < 0 for x in c)

if sum(c) < 0:
  print((-1))
elif k == 0:
  print((0))
else:
  for i in range(n):
    if sum(c[len(c) - 1 - i:]) >= -sum(c[:k]):
      print((k + i + 1))
      break

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted([a[i] - b[i] for i in range(n)])
k = sum(x < 0 for x in c)
neg = -sum(c[:k])
pos = c[len(c) - 1]

if sum(c) < 0:
  print((-1))
elif k == 0:
  print((0))
else:
  for i in range(n):
    if pos >= neg:
      print((k + i + 1))
      break
    else: pos += c[len(c) - 2 - i]
# Original solution
n = int(eval(input()))
a = [int(x) for x in input().split(' ')]
b = [int(x) for x in input().split(' ')]
 
if sum(a) < sum(b):
    print('-1')
    exit()
 
count = 0
sabun = [(i, a[i]-b[i]) for i, _ in enumerate(a) if a[i]<b[i]]
husoku = sum([x[1] for x in sabun])
a_sorted = sorted(a)
while husoku < 0:
    ma = a_sorted[-1]
    a_sorted = a_sorted[:-1]
    mai = a.index(ma)
    husoku += ma - b[mai]
    a[mai] = b[mai]
    count += 1
 
print((len(sabun) + count))   

# Optimized solution
n = int(eval(input()))
a = [int(x) for x in input().split(' ')]
b = [int(x) for x in input().split(' ')]
 
if sum(a) < sum(b):
    print('-1')
    exit()
 
count = 0
sabun = [a[i]-b[i] for i, _ in enumerate(a)]
husoku = sum([x for x in sabun if x<0])
sabun.sort(reverse=True)

for i in sabun:
    if husoku >= 0:
        break
    husoku += i
    count += 1
 
print((len([x for x in sabun if x<0]) + count))
# Original solution
import sys
input = sys.stdin.readline
from bisect import insort_left

def main():
    N = int(eval(input()))
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    
    if sum(A) < sum(B):
        print((-1))
        exit()

    ok = []
    ng_cnt = 0
    ng_num = 0
    for i in range(N):
        if A[i] - B[i] >= 0:
            insort_left(ok, A[i] - B[i])
        else:
            ng_cnt += 1
            ng_num += B[i] - A[i]
    ans = ng_cnt

    while ng_num > 0:
        ans += 1
        ng_num -= ok.pop()

    print(ans)

if __name__ == "__main__":
    main()

# Optimized solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
from bisect import insort_left

def main():
    N = int(eval(input()))
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    
    if sum(A) < sum(B):
        print((-1))
        exit()

    ok = []
    ng_cnt = 0
    ng_num = 0
    for i in range(N):
        if A[i] - B[i] >= 0:
            ok.append(A[i] - B[i])
        else:
            ng_cnt += 1
            ng_num += B[i] - A[i]
    ok.sort()

    ans = ng_cnt

    while ng_num > 0:
        ans += 1
        ng_num -= ok.pop()

    print(ans)

if __name__ == "__main__":
    main()