CodeEff/ECCO huggingface dataset:
# Original solution
N = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

d_pls = []
d_mns = []
s = 0
for i in range(N):
    t = a[i] - b[i]
    s += t
    if t > 0:
        d_pls.append(t)
    elif t < 0:
        d_mns.append(t)
# 準備不足なら負

if s < 0:
    print((-1))
    exit()

d_pls = sorted(d_pls, reverse=True)

d_mns = sorted(d_mns)
m_sum = sum(d_mns)
ans = len(d_mns)

i = 0
while m_sum < 0:
    m_sum += d_pls[i]
    ans += 1
    i += 1
print(ans)


# Optimized solution
N = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

d = list(aa - bb for aa, bb in zip(a, b))
d = sorted(d)

p = tuple([x for x in d if x >= 0])
p = sorted(p, reverse=True)
m = tuple([x for x in d if x < 0])

s = sum(m)

i = 0
while s < 0 and i < len(p):
    s += p[i]
    i += 1

print((len(m) + i if s >= 0 else -1))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt, nega, posi = 0, 0, []
for x, y in zip(a, b):
    if x < y:
        nega += y - x
        cnt += 1
    else:
        posi.append(x - y)
if nega > 0:
    posi.sort(reverse=True)
    for i, x in enumerate(posi):
        nega -= x
        if nega <= 0:
            cnt += i + 1
            break
    else:
        cnt = -1
print(cnt)

# Optimized solution
def main():
    n = int(eval(input()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    cnt, nega, posi = 0, 0, []
    for x, y in zip(a, b):
        if x < y:
            nega += y - x
            cnt += 1
        else:
            posi.append(x - y)
    if sum(posi) - nega < 0:
        print((-1))
        exit()
    posi.sort(reverse=True)
    i = 0
    while nega > 0:
        nega -= posi[i]
        cnt += 1
        i += 1
    print(cnt)

if __name__ == "__main__":
    main()
# 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))
    exit(0)

t = 0
m = 0
L = []
for k in range(N):
    if A[k] > B[k]:
        L.append(A[k]-B[k])
    else:
        m += B[k] - A[k]
        t += 1

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

L = (sorted(L))[::-1]
for e in L:
    m -= e
    t += 1
    if m <= 0:
        break
print(t)

# 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)

C = [A[k]-B[k] for k in range(N)]
C.sort()
t = 0
ans = 0
for k in range(N):
    if C[k] >= 0:
        break
    else:
        t -= C[k]
        ans += 1

for k in range(N-1,-1,-1):
    if t <= 0:
        break
    else:
        t -= C[k]
        ans += 1

print(ans)
# Original solution
n=int(eval(input()))
Alist=[int(i) for i in input().split(" ")]
Blist=[int(i) for i in input().split(" ")]
sumA=sum(Alist)
sumB=sum(Blist)
Dlist=[]
muinus=0
muinus_num=0
count=0
if sumA<sumB:
    print((-1))
else:
    for i in range(n):
        AB=Alist[i]-Blist[i]
        Dlist.append(AB)
        if AB<0:
            muinus+=AB
            muinus_num+=1
    while muinus<0:
        muinus+=max(Dlist)
        Dlist.remove(max(Dlist))
        count+=1
    print((muinus_num+count))

# Optimized solution
n=int(eval(input()))
Alist=[int(i) for i in input().split(" ")]
Blist=[int(i) for i in input().split(" ")]
sumA=sum(Alist)
sumB=sum(Blist)
Dlist=[]
muinus=0
muinus_num=0
count=0
if sumA<sumB:
    print((-1))
else:
    for i in range(n):
        AB=Alist[i]-Blist[i]
        Dlist.append(AB)
        if AB<0:
            muinus+=AB
            muinus_num+=1
    Dlist.sort(reverse=True)
    while muinus<0:
        muinus+=Dlist[count]
        count+=1
    print((muinus_num+count))
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
diff = [a - b for a, b in zip(A, B)]
upper = sorted([x for x in diff if x > 0])
lower = sorted([x for x in diff if x < 0], reverse=True)
ans = N - len([x for x in diff if x == 0])
while upper and lower:
    rest = upper.pop()
    while lower:
        tgt = lower.pop()       # negative value
        if rest + tgt >= 0:
            rest += tgt
        else:
            lower.append(tgt + rest)
            break
if lower:
    print((-1))
else:
    print((ans - len(upper)))

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
diff = [a - b for a, b in zip(A, B)]
upper = sorted([x for x in diff if x > 0])
lower = sorted([x for x in diff if x < 0])
ans = N - len([x for x in diff if x == 0])
while upper and lower:
    rest = upper.pop()
    while lower:
        tgt = lower.pop()       # negative value
        if rest + tgt >= 0:
            rest += tgt
        else:
            lower.append(tgt + rest)
            break
if lower:
    print((-1))
else:
    print((ans - len(upper)))
# Original solution
def main():
  n = int(eval(input()))
  As = list(map(int, input().split()))
  Bs = list(map(int, input().split()))

  diffs = [a - b for a, b in zip(As, Bs)]
  positives = list(sorted([x for x in diffs if x>0], reverse=True))
  negatives = list(sorted([x for x in diffs if x<0]))
  if abs(sum(negatives)) > sum(positives):
    print((-1))
    return
  max_i = -1
  for neg in negatives:
    for i, pos in enumerate(positives):
      neg += pos
      max_i = max(i, max_i)
      if neg >= 0:
        positives[i] = neg
        break
      else:
        positives[i] = 0
  print((len(negatives) + max_i + 1))


if __name__ == '__main__':
  main()


# Optimized solution
from itertools import accumulate


def main():
  n = int(eval(input()))
  As = list(map(int, input().split()))
  Bs = list(map(int, input().split()))

  diffs = [a - b for a, b in zip(As, Bs)]
  pos_acc = list(accumulate(sorted([x for x in diffs if x>0], reverse=True)))
  negatives = list([x for x in diffs if x<0])
  neg_sum = abs(sum(negatives))
  num_negs = len(negatives)
  if num_negs == 0:
    print((0))
    return
  for i, pa in enumerate(pos_acc):
    if neg_sum <= pa:
      print((num_negs + i + 1))
      return
  print((-1))


if __name__ == '__main__':
  main()
# Original solution
import sys

def main():
    N = int(eval(input()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    AB = list(zip(A, B))
    bigger_diff = list([max(ab[0] - ab[1], 0) for ab in AB])
    lesser_diff = list([min(ab[0] - ab[1], 0) for ab in AB])
    exceeded = sum(bigger_diff)
    shortage = sum(lesser_diff)

    if exceeded < abs(shortage):
        print((-1))
        sys.exit()

    if all([ab[0] > ab[1] for ab in AB]):
        print((0))
        sys.exit()



    ans = len(list([d for d in lesser_diff if d<0]))

    bigger_diff = sorted(bigger_diff, reverse=True)

    for i in range(len(bigger_diff)):
        if sum(bigger_diff[:i]) >= abs(shortage):
            ans += i
            break
    print(ans)



if __name__=='__main__':
    main()


# Optimized solution
import sys

def main():
    N = int(eval(input()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    AB = list(zip(A, B))
    bigger_diff = list([max(ab[0] - ab[1], 0) for ab in AB])
    lesser_diff = list([min(ab[0] - ab[1], 0) for ab in AB])
    exceeded = sum(bigger_diff)
    shortage = sum(lesser_diff)

    if exceeded < abs(shortage):
        print((-1))
        sys.exit()

    if all([ab[0] >= ab[1] for ab in AB]):
        print((0))
        sys.exit()



    ans = len(list([d for d in lesser_diff if d<0]))

    bigger_diff = sorted(bigger_diff, reverse=True)

    ss = 0
    for i in range(len(bigger_diff)):
        ss += bigger_diff[i]
        if ss >= abs(shortage):
            ans += i + 1
            break
    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 = sorted([A[i]-B[i] for i in range(N)])
tot = sum(C)
cnt = 0
if tot<0:
    cnt = -1
else:
    a = 0
    for i in range(N):
        if C[i]<0:
            a += C[i]
            cnt += 1
        else:
            break
    for i in range(N-1,-1,-1):
        if a>=0:break
        a += C[i]
        cnt += 1
print(cnt)

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
P = sorted([A[i]-B[i] for i in range(N) if A[i]-B[i]>0],reverse=True)
C = [0 for _ in range(N+1)]
for i in range(1,len(P)+1):
    C[i] = C[i-1]+P[i-1]
M = [B[i]-A[i] for i in range(N) if B[i]-A[i]>0]
p = sum(P)
m = sum(M)
if m>p:
    ans = -1
else:
    if len(M)==0:
        ans = 0
    else:
        for i in range(1,len(P)+1):
            if C[i]>=m:
                ans = i
                break
        ans += len(M)
print(ans)
# Original solution
import copy
siken_kazu=int(eval(input()))
junbido=[int(i) for i in input().split(" ")]
goukakudo=[int(i) for i in input().split(" ")]
yoyudo=[junbido[i]-goukakudo[i] for i in range(siken_kazu)]
shoki_yoyudo=copy.deepcopy(yoyudo)
k=0
hantei=2
if sum(junbido)<sum(goukakudo):
    k=-1
elif min(yoyudo)>=0:
    pass
else:
    while hantei>1:
        hantei=0
        a=max(yoyudo)
        for i in range(siken_kazu):
            if yoyudo[i]==a:
                kiroku=i
                break
        for i in range(siken_kazu):
            if yoyudo[kiroku]==0:
                break
            elif yoyudo[i]<0:
                hantei=2
                if yoyudo[kiroku]>=-yoyudo[i]:
                    yoyudo[kiroku]-=-yoyudo[i]
                    yoyudo[i]=0
                elif yoyudo[kiroku]<-yoyudo[i]:
                    yoyudo[kiroku]=0
                    yoyudo[i]+=-yoyudo[kiroku]
for i in range(siken_kazu):
    if shoki_yoyudo[i]!=yoyudo[i]:
        k+=1
print(k)

# Optimized solution
import copy
siken_kazu=int(eval(input()))
junbido=[int(i) for i in input().split(" ")]
goukakudo=[int(i) for i in input().split(" ")]
yoyudo=[junbido[i]-goukakudo[i] for i in range(siken_kazu)]
counter=0
shakkin=0
tyokin=0
if sum(junbido)<sum(goukakudo):
    counter=-1
else:
    for i in yoyudo:
        if i<0:
            counter+=1
            shakkin-=i
    yoyudo=sorted(yoyudo,reverse=True)
    for i in yoyudo:
        if tyokin>=shakkin:
            break
        else:
            tyokin+=i
            counter+=1
print(counter)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split(' ')))
B = list(map(int, input().split(' ')))

sum_A = sum(A)
sum_B = sum(B)

diff = []
neg = 0
count = 0

if sum_B > sum_A:
    print((-1))
    exit()

for a, b in zip(A, B):
    diff += [a-b]
    if a < b:
        count += 1
        neg += a - b

for d in sorted(diff, reverse=True):
    if neg >= 0:
        break
    count += 1
    neg += d

print(count)

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

diff = []
neg = 0
count = 0

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

for a, b in zip(A, B):
    diff += [a-b]
    if a < b:
        count += 1
        neg += a - b

for d in sorted(diff, reverse=True):
    if neg >= 0:
        break
    count += 1
    neg += d

print(count)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

surplus = []
short = []

for i in range(n):
    if a[i] > b[i]:
        surplus.append(a[i]-b[i])
    elif b[i] > a[i]:
        short.append(b[i]-a[i])

surplus = sorted(surplus)
taken = False
cnt = 0
for i in range(len(short)):
    cost = short.pop()
    cnt += 1

    while cost > 0:
        if len(surplus) == 0:
            print((-1))
            exit()

        take = min(cost, surplus[-1])
        cost -= take
        surplus[-1] -= take

        if not taken:
            taken = True
            cnt += 1

        if surplus[-1] == 0:
            surplus.pop()
            taken = False

print(cnt)

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

surplus = []
short = 0
cnt = 0

for i in range(n):
    if a[i] > b[i]:
        surplus.append(a[i]-b[i])
    elif b[i] > a[i]:
        short += b[i]-a[i]
        cnt += 1

surplus = sorted(surplus)
s = 0

while s < short:
    if len(surplus) == 0:
        print((-1))
        exit()

    s += surplus.pop()
    cnt += 1

print(cnt)
# Original solution
N= int(eval(input()))
A  = list(map(int,input().split()))
B  = list(map(int,input().split()))
short = []
margine = []
for a,b in zip(A,B):
    if a > b :
        margine.append(a-b)
    elif b > a:
        short.append(b-a)
        
ss = sum(short)
sc = len(short)
margine.sort()
if sum(short)>sum(margine):
    print((-1))
    exit()
while ss>0:
    ss -= margine.pop()
    sc += 1
print(sc)



# Optimized solution
N= int(eval(input()))
A  = list(map(int,input().split()))
B  = list(map(int,input().split()))
short = []
margine = []
for a,b in zip(A,B):
    if a > b :
        margine.append(a-b)
    elif b > a:
        short.append(b-a)
        
ss = sum(short)
sc = len(short)
margine.sort()
if ss>sum(margine):
    print((-1))
    exit()
while ss>0:
    ss -= margine.pop()
    sc += 1
print(sc)
# Original solution
from bisect import bisect_left

def main():
    N = int(eval(input()))
    A = tuple(map(int, input().split()))
    B = tuple(map(int, input().split()))

    surplus = []
    need = 0
    ans = 0
    for a, b in zip(A, B):
        diff = a - b
        if diff > 0:
            surplus.append(diff)
        if diff < 0:
            need += -diff
            ans += 1

    surplus.sort(reverse=True)
    cusum = [0] * (len(surplus) + 1)
    for i, sur in enumerate(surplus):
        cusum[i+1] = cusum[i] + sur

    plus = bisect_left(cusum, need)
    ans += plus
    if need and plus == len(cusum):
        print((-1))
    else:
        print(ans)
    
if __name__ == "__main__":
    main()

# Optimized solution
from bisect import bisect_left

def main():
    N = int(eval(input()))
    A = tuple(map(int, input().split()))
    B = tuple(map(int, input().split()))

    surplus = []
    need = 0
    ans = 0
    for a, b in zip(A, B):
        diff = a - b
        if diff >= 0:
            surplus.append(diff)
        else:
            need += -diff
            ans += 1

    surplus.sort(reverse=True)
    cusum = [0] * (len(surplus) + 1)
    for i, sur in enumerate(surplus):
        cusum[i+1] = cusum[i] + sur

    ans += bisect_left(cusum, need)
    if ans > N:
        print((-1))
    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()))

if sum(A) < sum(B):
    print((-1))
    exit()
if all(a>=b for a,b in zip(A,B)):
    print((0))
    exit()

lack_v = lack_n = 0
gains = []
for a,b in zip(A,B):
    if a<b:
        lack_n += 1
        lack_v += b-a
    else:
        gains.append(a-b)

ans = lack_n
for g in sorted(gains, reverse=True):
    lack_v -= g
    ans += 1
    if lack_v <= 0:
        print(ans)
        exit()
print((-1))

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
D = [a-b for a,b in zip(A,B)]
D.sort()

lack = sum(d for d in D if d<0)

ans = 0
for d in D[::-1]:
    if lack < 0 and d > 0:
        ans += 1
        lack += d
    if d < 0:
        ans += 1
print((-1 if lack < 0 else ans))
# 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))
else:
    diff = [a-b for a,b in zip(A,B)]
    plus = []
    minus = []
    equal = []
    for d in diff:
        if d >= 0:
            plus.append(d)
        elif d < 0:
            minus.append(d)
    lack = sum(minus)
    while lack < 0:
        lack += max(plus)
        plus.remove(max(plus))
    print((N-len(plus)))

# 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))
else:
    diff = [a-b for a,b in zip(A,B)]
    plus = []
    minus_num = 0
    lack = 0
    for d in diff:
        if d >= 0:
            plus.append(d)
        elif d < 0:
            minus_num += 1
            lack += d
    plus.sort(reverse=True)
    i = 0
    while lack < 0:
        lack += plus[i]
        i += 1
        
    print((N-len(plus)+i))
# Original solution
N=int(eval(input()))
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
count=0
if sum(A)<sum(B):
    print((-1))
else:
    dif=[A[i]-B[i] for i in range(N)]
    if min(dif)>=0:
        print((0))
    else:
        difsort=sorted(dif)
        pluslist=[i for i in difsort if i>=0]
        zero=difsort.index(pluslist[0])
        minum=len(difsort[:zero])
        maxsort=difsort[::-1]
        absum=abs(sum(difsort[:zero]))
        sumlist=[sum(maxsort[0:i+1]) for i in range(len(pluslist))]
        while sumlist[count]<absum:
            count+=1
        
        print((count+1+minum))

# Optimized solution
N=int(eval(input()))
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
count=0
if sum(A)<sum(B):
    print((-1))
else:
    dif=[A[i]-B[i] for i in range(N)]
    if min(dif)>=0:
        print((0))
    else:
        difsort=sorted(dif)
        plist=[i for i in difsort if i>=0][::-1]
        mlist=[i for i in difsort if i<0]
        mnum=len(mlist)
        msum=sum(mlist)
        for i in range(len(plist)):
            if msum>=0:
                break
            msum+=plist[i]
            count+=1
            
        
        print((count+mnum))
# Original solution
import sys

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

if sum(A)<=sum(B):
    print((-1))
    sys.exit()

Y=0
K=0
Q=[]

for i in range(N):
    k=A[i]-B[i]
    if k>0:
        Q.append(k)
    elif k<0:
        K+=1
        Y+=-k

Q.sort(reverse=True)

while Y>0:
    q=Q.pop(0)
    Y-=q
    K+=1

print(K)    


# Optimized solution
import sys

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

if sum(A)<=sum(B):
    print((-1))
    sys.exit()

Y=0
K=0
Q=[]

for i in range(N):
    k=A[i]-B[i]
    if k>0:
        Q.append(k)
    elif k<0:
        K+=1
        Y+=-k

Q.sort()

while Y>0:
    q=Q.pop()
    Y-=q
    K+=1

print(K)
# Original solution
import sys
input=sys.stdin.readline
mii=lambda:list(map(int,input().split()))

n=int(eval(input()))
a=list(mii())
b=list(mii())
k = []
j = 0
na= 0
c = 0
for i in range(n):
    if a[i]<b[i]:
        na +=b[i]-a[i]
        c+=1
    elif a[i] > b[i]:
        k.append(a[i]-b[i])
    k.sort()
while na > 0 and k:
    na -=k[-1]
    k.pop(-1)
    c +=1
if na > 0:print((-1))
else:print(c)

# Optimized solution
import sys
input=sys.stdin.readline
mii=lambda:list(map(int,input().split()))

n=int(eval(input()))
a=list(mii())
b=list(mii())
k = []
j = 0
na= 0
c = 0
for i in range(n):
    if a[i]<b[i]:
        na +=b[i]-a[i]
        c+=1
    elif a[i] > b[i]:
        k.append(a[i]-b[i])
k.sort()
while na > 0 and k:
    na -=k[-1]
    k.pop(-1)
    c +=1
if na > 0:print((-1))
else:print(c)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

diff = [0] * (N)
diffsum = 0
for i in range(N):
    diff[i] = A[i] - B[i]
    diffsum += diff[i]
if diffsum < 0:
    print("-1")
    exit()
diff.sort()
change = [0] * (N)
for i in range(N):
    if diff[i] < 0:
        change[i] = 1
        for j in range(N)[::-1]:
            if diff[j] > 0:
                change[j] = 1
                ch = min(-diff[i], diff[j])
                diff[i] += ch
                diff[j] -= ch
                if diff[i] == 0:
                    break
print((sum(change)))

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

diff = [0] * (N)
diffsum = 0
for i in range(N):
    diff[i] = A[i] - B[i]
    diffsum += diff[i]
if diffsum < 0:
    print("-1")
    exit()
diff.sort()
count = 0
sumn = 0
for i in range(N):
    if diff[i] < 0:
        count += 1
        sumn -= diff[i]
    else:
        break
for j in range(N)[::-1]:
    if sumn > 0:
        count += 1
        sumn -= diff[j]
print(count)
# Original solution
N = int(eval(input()))

A = list(map(int,input().split()))
B = list(map(int,input().split()))
L = [A[i] - B[i] for i in range(N)]
ans = 0
if sum(A) < sum(B) :
    ans = -1
else :
    debt = []
    deposit = []
    for i in range(N) :
        if L[i] < 0 :
            debt.append(-L[i])
        elif L[i] > 0 :
            deposit.append(L[i])
        
    debt = sorted(debt)
    deposit = sorted(deposit,reverse=True)
    
    debt_duplicated = debt.copy()
    deposit_duplicated = deposit.copy()
    
    deposit_trash = []
    
    #print(debt)
    #print(deposit)
    
    for i in range(len(debt)) :
        
        while True :
            if debt[i] == 0 :
                break
            else :
                if debt[i] <= deposit[0] :
                    deposit[0] -= debt[i]
                    debt[i] = 0
                else :
                    debt[i] -= deposit[0]
                    deposit[0] = 0
                    deposit_trash.append(deposit.pop(0))
        
            
        
#        for j in range(len(deposit)) :
#            if debt[i] <= deposit[j] :
#                deposit[j] -= debt[i]
#                debt[i] = 0
#                break
#            else :
#                debt[i] -= deposit[j]
#                deposit[j] = 0
    deposit = deposit_trash + deposit
    for i in range(len(debt)) :
        if debt[i] != debt_duplicated[i] :
            ans += 1
    for i in range(len(deposit)) :
        if deposit[i] != deposit_duplicated[i] :
            ans += 1

print(ans)
#print(debt)
#print(deposit)



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

L = [A[i] - B[i] for i in range(N)]
ans = 0

if sum(A) < sum(B) :
    ans = -1
else :
    debt = []
    deposit = []
    
    for i in range(N) :
        if L[i] < 0 :
            debt.append(-L[i])
        elif L[i] > 0 :
            deposit.append(L[i])
    
    deposit = sorted(deposit,reverse=True)
    debt_sum = sum(debt)
    
    ans += len(debt)
    
    while debt_sum > 0 :
        if debt_sum <= deposit[0] :
            deposit[0] = 0
            debt_sum = 0
        else :
            debt_sum -= deposit.pop(0)
        ans += 1
        
print(ans)
#print(debt)
#print(deposit)
# Original solution
N = int(eval(input()))
A = sorted(list(map(int,input().split())))
B =list(map(int,input().split()))
if(sum(A) < sum(B)):
  print((-1))
  exit()
cnt = 0
for i in range(N):
  if(A[i] >= B[i]):
    cnt += 1
if(cnt == N):
  print((0))
  exit()
C = []
tmp = []
for b in B:
  for a in A:
    if(a not in tmp):
      tmp.append(a)
    if(a >= b):
      C.append(a)
      A.remove(a)
      break
ans = 0
for i in range(len(C)):
  if(C[i] != tmp[i]):
    ans += 1
print(ans)

# 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:
  C = [A[i] - B[i] for i in range(N)]
  D = sorted([c for c in C if c > 0])
  E = [c for c in C if c < 0]
  ans = 0
  num = sum(E)
  while num < 0:
    num += D.pop()
    ans += 1
  print((ans + len(E)))