qyliang/CodeNanoFix huggingface dataset:
Buggy code:
# coding:utf-8
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)
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)


Fixed code:
# coding:utf-8
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)
Buggy code:
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])
if num == 0:
  print("0")
l = sorted(l, reverse=True)
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")
else:
  print(num)

Fixed code:
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)
Buggy code:
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:
        aa = aa - i
        ans += 1
        if aa <= 0:
            break
    print(ans)

Fixed code:
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)
Buggy code:
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]

num_m = len(M)
sum_m = sum(M)

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


Fixed code:
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)
Buggy code:
i = input()
n = int(i)
a = list(map(int, i.split()))
b = list(map(int, i.split()))
if sum(a) < sum(b):
  print(-1)
  exit()
  
c = [x-y for x,y in zip(a,b)]
p = [i for i in c if i > 0]
m = [i for i in c if i < 0]

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

Fixed code:
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)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
d=[]
for i in range(n):
  if a[i]>b[i]:
    c.append(a[i]-b[i])
  elif a[i]<b[i]:
    d.append(b[i]-a[i])
c.sort(reverse=True)
if sum(c)<sum(d):
  print(-1)
else:
  ans=0
  for i in range(len(c)):
    if sum(c[:i])>=sum(d):
      ans=i
      break
print(ans+len(d))

Fixed code:
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
Buggy code:
import numpy as np
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

mi = []
pl = []
sum = 0
if (sum(B) > sum(A)):
    print('-1')
    exit()

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

            
pl.sort(reverse=True)
p = sum(mi)
if (p != 0) and (len(pl) != 0):
    count = 1
    for i in pl:
        if p-i > 0:
            p -= i
            count += 1
        else:
            break
        
    else:
        print('-1')
        exit()
elif(p == 0) and (len(pl) != 0):
    print('0')
else:
    count = 0

print(len(mi)+count)
        
    
    
    
    

Fixed code:
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()
Buggy code:
import numpy as np

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

A=np.array(A)
B=np.array(B)
E=A-B
e=sum(E)

if e<0:
    print(-1)

else:

    Eminus=[]
    Ezero=[]
    Eplus=[]
    nn=0
    n0=0

    for n in range(N):
        if E[n]<0:
            Eminus.append(E[n])
        
        elif E[n]>0:
            Eplus.append(E[n])
            nn=nn+1
        
        else:
            Ezero.append(E[n])
            n0=n0+1
    
    Eplus.sort()
    sumup=0

    for n in range(nn):
        sumup=sumup+Eplus[n]

        if sumup>e:
            break

    if n==nn-1:
        n=nn

    print(N-n0-n)

Fixed code:
import numpy as np

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

A=np.array(A)
B=np.array(B)
E=A-B
e=sum(E)

if e<0:
    print(-1)

else:

    Eminus=[]
    Ezero=[]
    Eplus=[]
    nn=0
    n0=0
    nminus=0

    for n in range(N):
        if E[n]<0:
            Eminus.append(E[n])
            nminus=nminus+1
        
        elif E[n]>0:
            Eplus.append(E[n])
            nn=nn+1
        
        else:
            Ezero.append(E[n])
            n0=n0+1
    
    Eplus.sort()
    sumup=0

    for n in range(nn):
        sumup=sumup+Eplus[n]

        if sumup>e:
            break

    if nminus==0:
        print(0)
    else:
        print(N-n0-n)
Buggy code:
import numpy as np
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A = np.array(A)
B = np.array(B)
if np.sum(A) < np.sum(B):
    print(-1) 
else:
    sub_a_b = A-B
    p_sub = sorted(list(sub_a_b[sub_a_b>0]),reverse = True)
    # print(p_sub)  
    m_sub = list(sub_a_b[sub_a_b<0])
    max_counter = max(p_sub)
    m_sub_sum = abs(sum(m_sub))
    count = 1 + len(m_sub) 
    # print(p_sub[0:1])
    for i in range(len(p_sub)):
        if sum(p_sub[0:i+1]) >= m_sub_sum:
            print(count)
            exit()
        else:
            count += 1


Fixed code:
import numpy as np
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A = np.array(A)
B = np.array(B)
if np.sum(A) < np.sum(B):
    print(-1) 
else:
    sub_a_b = A-B
    p_sub = sorted(list(sub_a_b[sub_a_b>0]),reverse = True)
    # print(p_sub)  
    m_sub = list(sub_a_b[sub_a_b<0])
    max_counter = p_sub[0]
    m_sub_sum = abs(sum(m_sub))
    count = len(m_sub) 
    # print(p_sub[0:1])
    # print(type(list(np.where(sub_a_b<0)[0])))
    # print(np.array([]))
    if list(np.where(sub_a_b<0)[0]) == [] :
        print(0)
        exit()
    else:
        count+=1

        for i in range(len(p_sub)):
            if max_counter >= m_sub_sum:
                print(count)
                exit()
            else:
                max_counter += p_sub[i+1]
                count += 1
Buggy code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
df = list([0 for i in range(n)])
ans = -1

if sum(a) < sum(b):
    ans = -1
else:
    for i in range(n):
        df[i] = a[i] - b[i]
    minus = list(filter(lambda x: x < 0, df))
    plus = list(filter(lambda x: x > 0, df))
    m_count = len(minus)
    m_sum = sum(minus)
    plus.sort(reverse=True)

    if m_count == 0:
        ans = 0
    else:
        print(minus)
        print(plus)
        for i in range(len(plus)):
            m_sum += plus[i]
            if m_sum >= 0:
                break

        if m_sum>=0:
            ans = m_count + i + 1
print(ans)


Fixed code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
df = list([0 for i in range(n)])
ans = -1

if sum(a) < sum(b):
    ans = -1
else:
    for i in range(n):
        df[i] = a[i] - b[i]
    minus = list(filter(lambda x: x < 0, df))
    plus = list(filter(lambda x: x > 0, df))
    m_count = len(minus)
    m_sum = sum(minus)
    #print("m_count=%d"%(m_count))
    #print("m_sum=%d"%(m_sum))
    plus.sort(reverse=True)
    #print(df)
    #print(plus)

    if m_count == 0:
        ans = 0
    else:
        for i in range(len(plus)):
            m_sum += plus[i]
            if m_sum >= 0:
                break

        if m_sum>=0:
            ans = m_count + i + 1
print(ans)
Buggy code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

diff_m = 0
diff_p = []
mcount = 0

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

else:
    for i in range(N):
        difftmp = A[i] - B[i]
        
        if difftmp < 0:
            diff_m += difftmp
            mcount += 1
        
        else:
            diff_p.append(difftmp)

    if diff_m == 0:
        print(0)
        
    else:
        diff_p.sort(reverse = True)

        for j in range(1,N):
            print(sum(diff_p[:j]))
            if diff_m <= sum(diff_p[:j]):
                print(j+1 + mcount)
                break
            else:
                continue

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

diff_m = 0
diff_p = []
mcount = 0

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

else:
    for i in range(N):
        difftmp = A[i] - B[i]
        
        if difftmp < 0:
            diff_m += difftmp
            mcount += 1
        
        else:
            diff_p.append(difftmp)
    

    if diff_m == 0:
        print(0)

    else:
        diff_p.sort(reverse = True)

        for j in range(0,N):
            diff_m = diff_m + diff_p[j]
 

            if diff_m >= 0:
                print(j+1 + mcount)
                break

            else:
                continue
Buggy code:
n = int(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:
    husoku += i
    count += 1
    if husoku >= 0:
        break
 
print(len([x for x in sabun if x<0]) + count)        




Fixed code:
n = int(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)
Buggy code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Diff = [None]*N

#print(A)
#print(B)

for i in range(N):
  Diff[i] = A[i] - B[i]
  
#print(Diff)
sort_Diff= sorted(Diff,reverse=True)
#print(sort_Diff)

flag=0
plus_sum=0
ans=0
zero=0
minus=N

for i in range(N):
  if sort_Diff[i]==0:
    if flag==0:
      flag ==1
      zero = i
  if sort_Diff[i]<0:
    minus = i
    break
  plus_sum += sort_Diff[i]

if sum(sort_Diff)<0:
  print(-1)
else:
  ans = N - minus
  minus_sum = sum(Diff)-plus_sum
#print(plus_sum)
#print(minus_sum)

  ans = N - minus
  if minus_sum + abs(sort_Diff[0]) >= 0:
    ans = ans - 1
    
  for i in range(N):
    if minus_sum + abs(sort_Diff[i]) < 0:
      minus_sum = minus_sum + abs(sort_Diff[i]) 
      ans += 1
    else:
      ans = ans+1
      break

  print(ans)
    

Fixed code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Diff = [None]*N

for i in range(N):
  Diff[i] = A[i] - B[i]
  
sort_Diff= sorted(Diff,reverse=True)

flag=0
plus_sum=0
ans=0
minus=N+1

for i in range(N):
  if sort_Diff[i]<0:
    minus = i
    break
  plus_sum += sort_Diff[i]

if sum(sort_Diff)<0:
  print(-1)
else:
  ans = N - minus
  minus_sum = sum(sort_Diff)-plus_sum
#print(plus_sum)
#print(minus_sum)
    
  for i in range(N):
    if minus_sum + abs(sort_Diff[i]) < 0:
      minus_sum = minus_sum + abs(sort_Diff[i]) 
      if minus_sum ==0:
        break
      ans += 1
    else:
      ans = ans+1
      break

  print(ans)
Buggy code:
n=int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))


a_sum=sum(a)
b_sum=sum(b)

c = a[:]

if a_sum< b_sum:
    print(-1)

    
else:
    sub_ab=[0 for i in range(n)]
    for i in range(n):
        sub_ab[i]=c[i]-b[i]

    if sum(1 for i in range(n) if sub_ab[i] > 0) == n:
        print(0)
              
    else:
        minus_value=sum(sub_ab[i] for i in range(n) if sub_ab[i] < 0)
        minus_number=sum(1 for i in range(n) if sub_ab[i] < 0)
        surplas=0
        m=0
        sub_ab_sorted=sorted(sub_ab, reverse=True)

        while surplas<abs(minus_value):
            surplas=sum(sub_ab_sorted[0:m+1])
            m+=1
        
        print(m)
        print(m+minus_number)

    
    



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


a_sum=sum(a)
b_sum=sum(b)

c = a[:]

if a_sum< b_sum:
    print(-1)

    
else:
    sub_ab=[0 for i in range(n)]
    for i in range(n):
        sub_ab[i]=c[i]-b[i]

    if sum(1 for i in range(n) if sub_ab[i] > 0) == n:
        print(0)
              
    else:
        minus_value=sum(sub_ab[i] for i in range(n) if sub_ab[i] < 0)
        minus_number=sum(1 for i in range(n) if sub_ab[i] < 0)
        surplas=0
        m=0
        sub_ab_sorted=sorted(sub_ab, reverse=True)

        while surplas<abs(minus_value):
            surplas=sum(sub_ab_sorted[0:m+1])
            m+=1
        
        print(m+minus_number)
Buggy code:
#!/Users/takahiro.kida/git/atcorder/venv/bin/python

import numpy
import scipy

from collections import defaultdict
from pprint import pprint

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

diff = [0 for x in range(N)]

for i in range(N):
    diff[i] = A[i] - B[i]

if (sum(diff) < 0):
    print (-1)
else:
    shakkin = 0
    ans = 0
    for d in diff:
        if d < 0:
            shakkin += d
            ans += 1
    for d in sorted(diff, reverse=True):
        if shakkin >= 0:
            break
        print("diff: %s", d)
        ans += 1
        shakkin += d
        if shakkin >= 0:
            break
    print(ans)

Fixed code:
#!/Users/takahiro.kida/git/atcorder/venv/bin/python

import numpy
import scipy

from collections import defaultdict
from pprint import pprint

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

diff = [0 for x in range(N)]

for i in range(N):
    diff[i] = A[i] - B[i]

if (sum(diff) < 0):
    print (-1)
else:
    point = 0
    ans = 0
    for d in diff:
        if d < 0:
            point += d
            ans += 1
    for d in sorted(diff, reverse=True):
        if point >= 0:
            break
        ans += 1
        point += d
    print(ans)
Buggy code:
import sys

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

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

    if all(map(lambda ab: ab[0] > ab[1], AB)):
        print(0)
        sys.exit()



    ans = len(list(filter(lambda d: d<0, lesser_diff)))

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


Fixed code:
import sys

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

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

    if all(map(lambda ab: ab[0] >= ab[1], AB)):
        print(0)
        sys.exit()



    ans = len(list(filter(lambda d: d<0, lesser_diff)))

    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()
Buggy code:
import numpy as np

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


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

print(solve(A, B))

Fixed code:
import numpy as np

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

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

print(solve(A, B))
Buggy code:
# -*- coding: utf-8 -*-

import numpy as np

def solve():
    N = int(input())
    A = np.array(list(map(int,input().split())))
    B = np.array(list(map(int,input().split())))
    if A.sum() < B.sum():
        res = -1
    else:
        C = B-A
        d = np.maximum(C,0).sum()
        M = np.minimum(np.maximum(C,0),1).sum()
        C.sort()
        for c in C:
            d += c
            M += 1
            if d <= 0:
                break
        res = M
    return str(res)

if __name__ == '__main__':
    print(solve())

Fixed code:
# -*- coding: utf-8 -*-

import numpy as np

def solve():
    N = int(input())
    A = np.array(list(map(int,input().split())))
    B = np.array(list(map(int,input().split())))
    if A.sum() < B.sum():
        res = -1
    else:
        C = B-A
        d = np.maximum(C,0).sum()
        M = np.minimum(np.maximum(C,0),1).sum()
        C.sort()
        for c in C:
            if d <= 0:
                break
            d += c
            M += 1
        res = M
    return str(res)

if __name__ == '__main__':
    print(solve())
Buggy code:
N=input()
A=list(map(int, input().split()))
B=list(map(int, input().split()))

if sum(A) < sum(B) : 
    print(-1)
else :
    diff=[A[i] - B[i] for i in range(len(A))]
    pos=sorted([x for x in diff if x > 0])
    neg=[x for x in diff if x < 0]
    nes=sum(neg)
    if nes >= 0 :
        print(0)
    else:
        print(diff)
        items = 0
        total_pos = 0
        for p in reversed(pos):
            items += 1
            total_pos += p
            if(total_pos + nes >= 0) :
                print(items + len(neg))
                break


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

if sum(A) < sum(B) : 
    print(-1)
else :
    diff=[A[i] - B[i] for i in range(len(A))]
    pos=sorted([x for x in diff if x > 0])
    neg=[x for x in diff if x < 0]
    nes=sum(neg)
    if nes >= 0 :
        print(0)
    else:
        items = 0
        total_pos = 0
        for p in reversed(pos):
            items += 1
            total_pos += p
            if(total_pos + nes >= 0) :
                print(items + len(neg))
                break
Buggy code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

c = [a[i] - b[i] for i in range(n)]
c.sort()

neg = [v for v in c if v < 0]
total = sum(neg)
num = len(neg)

for i, v in enumerate(reversed(c[num:])):
    total += v
    if total >= 0:
        break

print(num + i + 1)

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

c = [a[i] - b[i] for i in range(n)]
c.sort()

neg = [v for v in c if v < 0]
total = sum(neg)
num = len(neg)

if sum(c) < 0:
    print(-1)
elif num == 0:
    print(0)
else:
    for v in reversed(c[num:]):
        total += v
        num += 1
        if total >= 0:
            break
    print(num)
Buggy code:
n = int(input())
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
dif = [a[i] - b[i] for i in range(n)]
dif_abs = [abs(dif[i]) for i in range(n)]
sorted_dif = sorted(dif)
dif_minus = [(dif_abs[i] - dif[i]) // 2 for i in range(n)]
total_minus = sum(dif_minus)
len_minus = sum(x>0 for x in dif_minus)

res = 0

if sum(a) < sum(b):
    print(-1)
else:
    if len_minus == 0:
        print(res)
    else:
        res += len_minus
        while True:
            if total_minus <= 0:
                break
            total_minus -= sorted_dif.pop()
            res += 1

    print(res)

Fixed code:
n = int(input())
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
dif = [a[i] - b[i] for i in range(n)]
dif_abs = [abs(dif[i]) for i in range(n)]
sorted_dif = sorted(dif)
dif_minus = [(dif_abs[i] - dif[i]) // 2 for i in range(n)]
total_minus = sum(dif_minus)
len_minus = sum(x>0 for x in dif_minus)

res = 0

if sum(a) < sum(b):
    print(-1)
else:
    if len_minus == 0:
        print(res)
    else:
        res += len_minus
        while True:
            if total_minus <= 0:
                break
            total_minus -= sorted_dif.pop()
            res += 1

        print(res)