Problem:
 Score : 400 points    Problem Statement A university student, Takahashi, has to take N examinations and pass all of them.
Currently, his readiness for the i -th examination is A_{i} , and according to his investigation, it is known that he needs readiness of at least B_{i} in order to pass the i -th examination.  Takahashi thinks that he may not be able to pass all the examinations, and he has decided to ask a magician, Aoki, to change the readiness for as few examinations as possible so that he can pass all of them, while not changing the total readiness.  For Takahashi, find the minimum possible number of indices i such that A_i and C_i are different, for a sequence C_1, C_2, ..., C_{N} that satisfies the following conditions:   The sum of the sequence A_1, A_2, ..., A_{N} and the sum of the sequence C_1, C_2, ..., C_{N} are equal.  For every i , B_i \leq C_i holds.   If such a sequence C_1, C_2, ..., C_{N} cannot be constructed, print -1 .      Constraints  1 \leq N \leq 10^5  1 \leq A_i \leq 10^9  1 \leq B_i \leq 10^9  A_i and B_i are integers.         Input Input is given from Standard Input in the following format:  N  A_1  A_2  ...  A_{N}  B_1  B_2  ...  B_{N}       Output Print the minimum possible number of indices i such that A_i and C_i are different, for a sequence C_1, C_2, ..., C_{N} that satisfies the conditions.
If such a sequence C_1, C_2, ..., C_{N} cannot be constructed, print -1 .        Sample Input 1 3
2 3 5
3 4 1      Sample Output 1 3  (A_1, A_2, A_3) = (2, 3, 5) and (B_1, B_2, B_3) = (3, 4, 1) . If nothing is done, he cannot pass the first and second exams.
The minimum possible number of indices i such that A_i and C_i are different, 3 , is achieved when:   (C_1, C_2, C_3) = (3, 5, 2)        Sample Input 2 3
2 3 3
2 2 1      Sample Output 2 0  In this case, he has to do nothing in order to pass all the exams.       Sample Input 3 3
17 7 1
25 6 14      Sample Output 3 -1  In this case, no matter what is done, he cannot pass all the exams.       Sample Input 4 12
757232153 372327760 440075441 195848680 354974235 458054863 463477172 740174259 615762794 632963102 529866931 64991604
74164189 98239366 465611891 362739947 147060907 118867039 63189252 78303147 501410831 110823640 122948912 572905212      Sample Output 4 5

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
leeway = sum(A) - sum(B)
if leeway < 0:
	print(-1)
else:
	cnt = N
	for i in sorted(range(N), key = lambda x: A[x] - B[x]):
		diff = A[i] - B[i]
		if diff >= 0:
			if diff <= leeway:
				leeway -= diff
				cnt -= 1
			else:
				break
	print(cnt)

Solution (Python):
N = int(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))

Solution (Python):
import sys
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0
tmp=[]
sum_tmp=0
if sum(a)<sum(b):
    print(-1)
    sys.exit()
for i in range(n):
    if a[i]>=b[i]:
        tmp.append(a[i]-b[i])
    else:
        cnt+=1
        sum_tmp+=abs(a[i]-b[i])
tmp.sort(reverse=True)
for i in range(len(tmp)):
    if sum_tmp<=0:
        break
    sum_tmp-=tmp[i]
    cnt+=1

print(cnt)

Solution (Python):
N = raw_input()
A_list = map(int, raw_input().split())
B_list = map(int, raw_input().split())
if sum(A_list) < sum(B_list):
    print(-1)
else:
    import numpy as np
    diff = [x - y for (x, y) in zip(A_list, B_list)]
    neg_list = [i for i in diff if i < 0]
    neg_sum = sum(neg_list)
    pos_list = [i for i in diff if i > 0]
    pos_list.sort(reverse=True)
    pos_list = np.cumsum(pos_list).tolist()
    for j,k in enumerate(pos_list):
        if len(neg_list) == 0:
            print(0)
            break
        elif neg_sum + k >= 0:
            print(j+1+len(neg_list))
            break 
        else:
            continue

Solution (Python):

n = int(input())
a = list(map(int,input().split(' ')))
b = list(map(int,input().split(' ')))
d = [ a - b for a,b in zip(a,b)]
m = [ di for di in d if di < 0]
p = [ di for di in d if di > 0]

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

p.sort(reverse=True)
for i,pi in enumerate(p):
  sum_m += pi
  if sum_m >= 0:
    print(len(m) + i + 1)
    exit()

print(-1)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

stack = []
lack = 0
count = 0

if  sum(A) >= sum(B) :
    for i in range(N) :
        if A[i] < B[i] :
            count += 1
            lack += B[i] - A[i]

        elif A[i] > B[i] :
            stack.append(A[i] - B[i])
    stack.sort(reverse=True)
    if count != 0 :
        for j in range(len(stack)) :
            lack -= stack.pop(0)
            count += 1
            if lack <= 0 :
                break
    print(count)

else :
    print(-1)

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
num = 0
s = 0
l = []
for i in range(n):
  if a[i] < b[i]:
    s += b[i]-a[i]
    num += 1
  if a[i] > b[i]:
    l.append(a[i]-b[i])
l = sorted(l, reverse=True)
if num == 0:
  print("0")
else:
  for i,j in enumerate(l):
    s -= l[i]
    num += 1
    if s <= 0:
      break

if num != 0 and sum(a) < sum(b):
  print("-1")
elif num != 0 and sum(a) >= sum(b):
  print(num)

Solution (Python):
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
supply_list = []
lack = 0
lack_cnt = 0

for i in range(n):
    if a_list[i] < b_list[i]:
        lack += b_list[i] - a_list[i]
        lack_cnt += 1
    elif a_list[i] > b_list[i]:
        supply_list.append(a_list[i] - b_list[i])

if lack_cnt == 0:
    print(0)
    exit()
elif len(supply_list) == 0:
    print(-1)
    exit()

supply = 0
supply_cnt = 0

for i in sorted(supply_list, reverse=True):
    supply += i
    supply_cnt += 1
    if supply >= lack:
        break

if supply < lack:
    print(-1)
    exit()

print(lack_cnt + supply_cnt)

Solution (Python):
n = input()
a = input().split()
b = input().split()
ans = 0
aa = 0
plus = []
def list_sum(l):
    r = 0
    for i in l:
        r += int(i)
    return r

if not list_sum(a) >= list_sum(b):
    print(-1)
else:
    for i in range(int(n)):
        if int(a[i]) < int(b[i]):
            ans += 1
            aa += int(b[i]) - int(a[i])
        else:
            plus.append(int(a[i]) - int(b[i]))
    plus = sorted(plus,reverse=True)
    for i in plus:
        if aa <= 0:
            break
        aa = aa - i
        ans += 1
    print(ans)

Solution (Python):
N = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())

C = []
D = []
for i in range(N):
    if A[i] < B[i]:
        C.append(B[i]-A[i])
    elif A[i] > B[i]:
        D.append(A[i]-B[i])

C.sort()
D.sort(reverse=1)

rest = 0
j = 0
ans = 0
for c in C:
    while j < len(D) and rest < c:
        rest += D[j]
        ans += 1
        j += 1
    if rest < c:
        ans = -1
        break
    ans += 1
    rest -= c
print(ans)

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

def f():
    if sum(A) < sum(B):
        return -1
    
    d = [a - b for a,b in zip(A, B)]
    d.sort()
    
    ret = 0
    tl = len(d) - 1
    hd = 0
    stock = 0
    while d[hd] < 0:
        stock += d[hd]
        hd += 1
        ret += 1
        while stock < 0:
            stock += d[tl]
            tl -= 1
            ret += 1
    
    return ret

print(f())

Solution (Python):
n = int(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):
    print(-1)
    exit()
mABs = [ab for ab in ABs if ab < 0]
ans, t = len(mABs), sum(mABs)
for ab in sorted(ABs, reverse=True):
    if t >= 0:
        break
    ans += 1
    t += ab
print(ans)

Solution (Python):
n = int(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):
    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)

Solution (Python):
n = int(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)

Solution (Python):
N = int(input())

def compare(lstA, lstB):
    lst_fail = [b - a for a, b in zip(lstA, lstB) if a<b]
    lst_pass = sorted([a - b for a, b in zip(lstA, lstB) if a>=b], reverse=True)
    return lst_fail, lst_pass

def change_count(lst_fail, lst_pass):
    sum_short = sum(lst_fail)
    cnt = 0
    scores = 0
    for score in lst_pass:
        if scores >= sum_short:
            break
        else:
            scores += score
            cnt += 1
    return cnt


lst_A = list(map(int, input().split()))
lst_B = list(map(int, input().split()))

lst_fail, lst_pass = compare(lst_A, lst_B)

cnt_f = len(lst_fail)
cnt_p_change = change_count(lst_fail, lst_pass)

if sum(lst_A) < sum(lst_B):
    print(-1)
else:
    print(cnt_f + cnt_p_change)

Solution (Python):

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

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

if all(map(lambda x: x[0] >= x[1], zip(A,B))):
    print(0)
    exit(0)

residual = []
required = []
ans_num_changed = 0


for i in range(N):
    if A[i] > B[i]:
        residual.append(A[i]-B[i])
    elif A[i] < B[i]:
        required.append(B[i]-A[i])

tarinai_all = sum(required)
ans_num_changed += len(required)

residual = sorted(residual, reverse=True)

for e,r in enumerate(residual, 1):
    tarinai_all -= r
    ans_num_changed += 1
    if tarinai_all <= 0:
        break
print(ans_num_changed)

Solution (Python):
import numpy as np

N = input()
a_list = np.array(list(map(int, input().split())))
b_list = np.array(list(map(int, input().split())))







if sum(a_list) < sum(b_list):
    print(-1)
else:
    
    
    
    
    diff_list = a_list - b_list
    
    diff_list.sort()
    start = 0
    end = -1
    current_value = diff_list[end]
    while diff_list[start] < 0:
        
        current_value += diff_list[start]
        while current_value < 0:
            end -= 1
            current_value += diff_list[end]
        start += 1
    if start == 0:
        print(0)
    else:
        print(start - end)

Solution (Python):
N=input()
A= map(int, raw_input().split())
B= map(int, raw_input().split())


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

ans=0
L=[]
short_sum=0

for a,b in zip(A,B):
	if a<b:
		short_sum+=(b-a)
		ans+=1
	elif a>b:
		L.append(a-b)

L.sort(reverse=True)

if short_sum ==0:
	print 0
	quit()


for i, x in  enumerate(L):
	short_sum-=x
	if short_sum<=0:
		ans+=i+1
		break

print ans

Solution (Python):
n = int(input())

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

plus_list = []
minus_list = []
count = 0

for i in range(n):
    if a[i] < b[i]:
        count += 1
        minus_list.append(b[i]-a[i])
    elif a[i] > b[i]:
        plus_list.append(a[i]-b[i])

c = sum(minus_list)
plus_list.sort(reverse = True)

for num in plus_list:
    if c <= 0:
        break
    else:
        c -= num
        count += 1

if c > 0:
    print(-1)
else:
    print(count)

Solution (Python):

N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]




def zeros(n): return [0 for i in range(n)]

m = 0
count = 0
for i in range(N):
    if A[i]<B[i]: 
        count += 1
        m += A[i] - B[i]

D = zeros(N)
for i in range(N): D[i] = [max(A[i] - B[i], 0), i]
D.sort()
D.reverse()


for i in range(N):
    if m>=0: break
    m += D[i][0]
    count += 1
else: count = -1
print(count)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
surp = []
lack = 0
cnt = 0
ans = 0
if sum(a) < sum(b):
    print(-1)
    exit()
for i in range(n):
    if a[i] >= b[i]:
        surp.append(a[i] - b[i])
    else:
        lack += b[i] - a[i]
        ans += 1
surp.sort(reverse = True)
while lack > 0:
    lack -= surp[cnt]
    cnt += 1
    ans += 1
print(ans)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    
    S = 0
    count = 0
    list_A = []
    
    for i in range(N):
        d = B[i] - A[i] 
        if (0 < d):
            S += d
            count += 1
        else:
            if (d < 0):
                list_A.append(-d)
    list_A.sort()

    if (count == 0):
        return 0

    for s in reversed(list_A):
        S -= s
        count += 1
        if (S < 0):
            return count
    return -1
print(main())

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

avail = []
need = 0
res = 0
sumA = 0
sumB = 0

for i in range(N):
	sumA += A[i]
	sumB += B[i]
	if A[i] > B[i]:
		avail.append(A[i] - B[i])
	if A[i] < B[i]:
		need += B[i] - A[i]
		res += 1

if sumA < sumB:
	print(-1)

else:
	avail.sort(reverse=True)
	avail.append(0)
	for i in avail:
		if need <= 0:
			print(res)
			break
		res += 1
		need -= i

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

C = []
for i in range(len(A)):
    C.append(B[i] - A[i])

if sum(C) > 0:
    print(-1)

else:
    ans = 0
    dif = 0
    for i in C:
        if i > 0:
            ans += 1
            dif += i

    for i in sorted(C):
        if dif <= 0:
            break

        ans += 1
        dif += i

    print(ans)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

D = [ai - bi for ai, bi in zip(A, B)]
M = [di for di in D if di < 0]
P = [di for di in D if di > 0]

sum_m = sum(M)
if sum_m == 0:
    print(0)
    exit()

P.sort(reverse=True)
for i, pi in enumerate(P):
    sum_m += pi
    if sum_m >= 0:
        print(len(M) + i + 1)
        exit()
print(-1)

Solution (Python):
from itertools import accumulate

N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

D = [ai - bi for ai, bi in zip(A, B)]
M = [di for di in D if di < 0]
P = [di for di in D if di > 0]

sum_m = sum(M)
if sum_m == 0:
    print(0)
    exit()

P.sort(reverse=True)
for i, pi in enumerate(P):
    sum_m += pi
    if sum_m >= 0:
        print(len(M) + i + 1)
        exit()
print(-1)

Solution (Python):
from itertools import accumulate
import sys
input = sys.stdin.readline

N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

D = [ai - bi for ai, bi in zip(A, B)]
M = [di for di in D if di < 0]
P = [di for di in D if di > 0]

sum_m = sum(M)
if sum_m == 0:
    print(0)
    exit()

P = accumulate(sorted(P, reverse=True))
for i, pi in enumerate(P):
    if pi + sum_m >= 0:
        print(len(M) + i + 1)
        exit()
print(-1)

Solution (Python):
from itertools import accumulate

N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

D = [ai - bi for ai, bi in zip(A, B)]
M = [di for di in D if di < 0]
P = [di for di in D if di > 0]

sum_m = sum(M)
if sum_m == 0:
    print(0)
    exit()

P = accumulate(sorted(P, reverse=True))
for i, pi in enumerate(P):
    if pi + sum_m >= 0:
        print(len(M) + i + 1)
        exit()
print(-1)

Solution (Python):
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    if sum(A) < sum(B):
        return -1

    C = [a-b for a,b in zip(A,B)]
    plus = [x for x in C if x > 0]
    minus = [x for x in C if x < 0]
    change = sum(minus)
    count = 0
    if change == 0:
        return 0

    for i in sorted(plus,reverse=True):
        if change >= 0:
            break
        change += i
        count += 1
    return count + len(minus)

print(solve())

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if sum(a) < sum(b):
  print(-1)
  exit()
  
c = [x-y for x,y in zip(a,b)]
p = [z for z in c if z > 0]
m = [z for z in c if z < 0]

f = sum(m)
l = len(m)
for k in sorted(p, reverse=True):
  if f >= 0:
    break
  f += k
  l += 1
print(l)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
if sum(A)<sum(B):
    print(-1)
else:
    D=[]
    d=0
    a=0
    for i in range(len(A)):
        c=A[i]-B[i]
        D.append(c)
        if c<0:
            a+=1
            d-=c
    D.sort()
    j=1
    while d>0:
        if d>D[-j]:
            a+=1
            d-=D[-j]
            j+=1
        else:
            a+=1
            break
    print(a)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
win=[]
lose=[]
if sum(a)<sum(b):
  print(-1)
else:
  for i in range(n):
    if a[i]<b[i]:
      lose.append(b[i]-a[i])
    else:
      win.append(a[i]-b[i])
  if len(lose)==0:
    print(0)
  else:
    win.sort()
    win.reverse()
    x=sum(lose)
    ct=0
    for j in range(len(win)):
      ct+=win[j]
      if ct>=x:
        break
    print(j+len(lose)+1)

Solution (Python):
from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if sum(a) < sum(b):
	print(-1)
else:
	excess = []
	needed_num = 0
	needed_score = 0
	for i in range(n):
		if a[i] > b[i]:
			excess.append(a[i]-b[i])
		elif a[i] < b[i]:
			needed_num += 1
			needed_score += b[i]-a[i]

	if needed_num == 0:
		print(0)
	else:
		excess.sort(reverse=True)
		e_sum = [excess[0]]
		for i in range(1, len(excess)):
			e_sum.append(e_sum[-1]+excess[i])
		ind = bisect_left(e_sum, needed_score)
		print(needed_num + ind+1)

Solution (Python):
def solve():
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    if sum(A) < sum(B):
        return -1
    AB = [a - b for a, b in zip(A, B)]
    plus = [x for x in AB if x > 0]
    minus = [x for x in AB if x < 0]
    t = sum(minus)
    ans = len(minus)
    for m in sorted(plus, reverse=True):
        if t >= 0:
            break
        t += m
        ans += 1
    return ans
print(solve())

Solution (Python):
import sys

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


N = ii()
A = il()
B = il()
S = 0
diff = []
num_i = 0
for a, b in zip(A, B):
    if a < b:
        S += b - a
        num_i += 1
    else:
        diff.append(a - b)
diff.sort(reverse=True)
if num_i == 0:
    print(0)
    exit()
c = 0
for i in range(len(diff)):
    S -= diff[i]
    c += 1
    if S < 0:
        break
else:
    print(-1)
    exit()
print(num_i + c)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

dif = [ 0 for i in range(N)]


if sum(A) < sum(B):
    print(-1)
else :
    for i in range(N):
        dif[i] = A[i] - B[i]
    if all( 0<=n for n in dif): 
        print(0)
    else:
        dif.sort(reverse=True)
        
        sum_minus = 0
        ans = 0 
        for d in dif:
            if d < 0:
                ans += 1
                sum_minus += d
        for d in dif:
            sum_minus += d
            ans += 1
            if sum_minus >= 0:
                print(ans)
                break

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

if sum(a) < sum(b):
    print(-1)
else:
    cnt = 0
    total = 0
    c = []
    for i in range(n):
        if a[i] < b[i]:
            cnt += 1
            total += (b[i]-a[i])
        else:
            c.append(a[i]-b[i])
    
    if cnt == 0:
        print(0)
    else:
        c.sort(reverse=True)
        d = 0
        for i in range(len(c)):
            d += c[i]
            if d >= total:
                print(cnt+i+1)
                break

Solution (Python):
def c_exam_and_wizard(N, A, B):
    ans = 0
    sum_of_shortage_for_passing_mark = 0
    campensation_for_shortage = []
    for a, b in zip(A, B):
        if a < b:
            ans += 1
            sum_of_shortage_for_passing_mark += b - a
        elif a > b:
            campensation_for_shortage.append(a - b)

    if sum_of_shortage_for_passing_mark == 0:
        return 0  

    campensation_for_shortage.sort(reverse=True)  
    for pts in campensation_for_shortage:
        sum_of_shortage_for_passing_mark -= pts
        ans += 1
        if sum_of_shortage_for_passing_mark < 0:
            break
    else:
        ans = -1
    return ans

N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
print(c_exam_and_wizard(N, A, B))

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

C=[a-b for a,b in zip(A,B)]

plus=[i for i in C if i>=0]
minus=[i for i in C if i<0]
plus.sort(reverse=True)

sum_minus=sum(minus)
ans=len(minus)

for i in plus:
    if sum_minus>=0:
        break
    sum_minus+=i
    ans+=1

if sum_minus<0:
    ans=-1

print(ans)

Solution (Python):
N=int(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)

Solution (Python):
import operator

def solve(A, B):
  diff = list(map(operator.sub, A, B))
  shortage  = list(filter(lambda d: d < 0, diff))
  remainder = list(filter(lambda d: d > 0, diff))
  remainder.sort(reverse=True)
  short_sum = sum(shortage)
  if short_sum == 0: return 0
  counter = len(shortage)
  for r in remainder:
    short_sum += r
    counter += 1
    if short_sum >= 0: return counter
  return -1

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

print(solve(A, B))

Solution (Python):
def c_exam_and_wizard(N, A, B):
    ans = 0
    sum_of_shortage_for_passing_mark = 0
    campensation_for_shortage = []
    for a, b in zip(A, B):
        if a < b:
            ans += 1
            sum_of_shortage_for_passing_mark += b - a
        elif a > b:
            campensation_for_shortage.append(a - b)

    if sum_of_shortage_for_passing_mark == 0:
        return 0  

    campensation_for_shortage.sort(reverse=True)  
    for pts in campensation_for_shortage:
        if pts >= sum_of_shortage_for_passing_mark:
            ans += 1
            break

        sum_of_shortage_for_passing_mark -= pts
        ans += 1
    else:
        ans = -1
    return ans

N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
print(c_exam_and_wizard(N, A, B))

Solution (Python):
N = int(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(filter(lambda x: x >= 0, d))
p = sorted(p, reverse=True)
m = tuple(filter(lambda x: x < 0, d))

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)

Solution (Python):
def plus(x, y):
    return x+y
def minus(x, y):
    return x-y

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

can = True
if sum(a) < sum(b):
    can = False
    
dif = list(map(minus, a, b))
dif.sort()

count = 0
shortage = list((filter(lambda x: x<0, dif)))
sumofshortage = sum(shortage)
count += len(shortage)

sumofsurplus = 0
for i in dif[::-1]:
    if sumofsurplus+sumofshortage < 0:
        sumofsurplus += i
        count += 1
    else:
        break

if can:
    print(count)
else:
    print(-1)

Solution (Python):
a = int(input())
b = list(map(int,input().split()))
c = list(map(int,input().split()))
d = []
su  = 0
kk = 0
for i in range(a):
	d.append(b[i]-c[i])
	if b[i]-c[i] < 0:
		su += b[i]-c[i]
		kk += 1

d.sort()
d.reverse()
k = 0

j = 1

for i in range(a):
	if d[i] > 0:
		su += d[i]
		while kk:
			if d[-j] < 0:
				if abs(d[-j]) <= d[i]:
					d[i] +=  d[-j]
					d[-j] = 0
					j += 1
					k += 1
					kk -= 1
					if d[i] == 0 or d[-j] > 0:
						k += 1
						break
					if i == a - j:
						k += 1
						break
				else:
					d[-j] += d[i]
					d[i] = 0
					k += 1
					break
			else:
				break
	if su >= 0:
		break

if su < 0:
	print(-1)
else:
	print(k)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

sumBA = 0
sumAB = []
cntBA = 0

for i in range(n):
    if b[i] > a[i]:
        sumBA += b[i] - a[i]
        cntBA += 1
    elif b[i] < a[i]:
        sumAB.append(a[i] - b[i])

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

if sumBA > sum(sumAB):
    print(-1)
    exit()

sumAB.sort(reverse = True)
count = 0
check = 0
for i in range(len(sumAB)):
    count += 1
    check += sumAB[i]
    if check >= sumBA:
        print(count + cntBA)
        exit()

Solution (Python):
N = int(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)

Solution (Python):
N=int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

if sum(A)<sum(B):
    print(-1)
else:
    C = [B[i]-A[i] for i in range(N)]
    C.sort()
    ans=0
    task=0
    i=-1
    while C[i]>0:
        ans+=1
        task+=C[i]
        i-=1

    i=0
    while task>0:
        ans+=1
        task+=C[i]
        i+=1
    print(ans)

Solution (Python):
import numpy as np
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

mi = []
pl = []

for i in range(N):
    s = A[i] - B[i]
    if s < 0:
        mi.append(s)
    elif s > 0:
        pl.append(s)

            
pl.sort(reverse=True)
p = np.sum(mi)



if (len(pl)>0)and(len(mi)>0):
    count = 0
    for i in pl:
        if p + i < 0:
            p += i
            count += 1
            continue
        else:
            count += 1
            break
    else:
        print('-1')
        exit()

    print(count + len(mi))
    
        
elif len(mi) == 0:
    print('0')
    exit()
else:
    print('-1')
    exit()

Solution (Python):
n = int(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)

Solution (Python):
n=int(input())
*a,=map(int,input().split())
*b,=map(int,input().split())

l=sorted([j-i for i,j in zip(a,b)])[::-1]
t=0
ans=0

if sum(l)>0:
  print(-1)
else:
  for i in l:
    if i>0:
      t+=i
      ans+=1
    else:break

  for i in l[::-1]:
    if t+i>=0 and i<0:
      t=t+i
      ans+=1
    elif t:
      t=0
      ans+=1
    else:
      break

  print(ans)

Solution (Python):
def solve():
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    if sum(A) < sum(B):
        return -1
    AB = [a - b for a, b in zip(A, B)]
    plus = [x for x in AB if x > 0]
    minus = [x for x in AB if x < 0]
    t = sum(minus)
    cnt = 0
    for m in sorted(plus, reverse=True):
        if t >= 0:
            break
        t += m
        cnt += 1
    return cnt + len(minus)
    ans = 0
    return ans
print(solve())

Solution (Python):
N=input()
A=map(int,raw_input().split())
B=map(int,raw_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"

Solution (Python):
N = int(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)

Solution (Python):

import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))

if sum(A) < sum(B):
    re = -1

else:
    diff = A - B
    diff.sort()

    i = 0
    j = -1
    a = diff[j]
    while diff[i] < 0:
        a += diff[i] 
        while a<0:
            j -= 1
            a+= diff[j]
        i += 1

    if i == 0:
        re = 0
    else:
        re = i - j

print(re)

Solution (Python):

import numpy as np

n=int(input())
tmp=input()
a=[int(k) for k in tmp.split()]
tmp=input()
b=[int(k) for k in tmp.split()]
x=int(0)

a_arr = np.array(a)
b_arr = np.array(b)
c_arr = a_arr - b_arr
c_arr.sort()

if sum(a_arr) < sum(b_arr) :
    x=-1
elif c_arr[0]>=0:
    x=0
else:
    minus_arr= c_arr[c_arr<0]
    m_=len(minus_arr)
    pls_arr= c_arr[c_arr>0]
    m=sum(minus_arr)
    pls=pls_arr.tolist()
    pls.sort()
    pls.reverse()
    i=int(0)
    pls_=int(0)
    while i <= -m :
        i = i + pls.pop(0)
        pls_=pls_+1
    x=m_+pls_

print(x)

Solution (Python):
n=int(input())
*a,=map(int,input().split())
*b,=map(int,input().split())
c,d=[],[]
for s,t in zip(a,b):
    if s<t:
        c.append(t-s)
    elif s>t:
        d.append(s-t)
c.sort()
d.sort(reverse=1)
i=0
j=0
f=0
while i<len(c) and j<len(d):
    if c[i]<=d[j]:
        d[j]-=c[i]
        i+=1
        f=1
    elif c[i]>d[j]:
        c[i]-=d[j]
        j+=1
if i<len(c):
    print(-1)
else:
    print(i+j+f)