qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
diff_AB = sum(A) - sum(B)

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

Diff = []	
for i in range(n):
	diff = A[i] - B[i]
	Diff.append(diff)

Diff = sorted(Diff)
print(Diff)
res = 0
for i in range(n):
	if Diff[i] < 0:
		res += 1
	else:
			if Diff[i] <= diff_AB:
				diff_AB -= Diff[i]
			else:
				diff_AB = 0
				res += 1

if diff_AB > 0:
	res += 1

print(res)


Fixed code:
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
diff_AB = sum(A) - sum(B)

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

Diff = []	
for i in range(n):
	diff = A[i] - B[i]
	Diff.append(diff)

Diff = sorted(Diff)

res = 0
for i in range(n):
	if Diff[i] < 0:
		res += 1
	else:
			if Diff[i] <= diff_AB:
				diff_AB -= Diff[i]
			else:
				diff_AB = 0
				res += 1

if diff_AB > 0:
	res += 1

print(res)
Buggy code:
from collections import deque
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [ai - bi for ai, bi in zip(a, b)]
if sum(c) < 0:
    print(-1)
    exit()
c.sort()
minus = deque()
for ci in c:
    if ci >= 0:
        break
    minus.append(ci)
ans = len(minus)
s = sum(minus) * (-1)
plus = 0
idx = -1
while s >= plus:
    plus += c[idx]
    ans += 1
    idx -= 1
print(ans)

Fixed code:
from collections import deque
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [ai - bi for ai, bi in zip(a, b)]
if sum(c) < 0:
    print(-1)
    exit()
c.sort()
minus = deque()
for ci in c:
    if ci >= 0:
        break
    minus.append(ci)
ans = len(minus)
s = sum(minus) * (-1)
plus = 0
idx = -1
while s > plus:
    plus += c[idx]
    ans += 1
    idx -= 1
print(ans)
Buggy code:
from math import fabs
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
tarinai = []
amari = []
for i in range(n):
    if a[i] - b[i] < 0:
        tarinai.append(a[i] - b[i])
    elif a[i] - b[i] > 0:
        amari.append(a[i] - b[i])
tarinai.sort()
amari.sort()
amari.reverse()

ans = 0
if fabs(sum(tarinai)) > sum(amari):
    print('-1')
else:
    ans += len(tarinai)
    val = fabs(sum(tarinai))
    for i in range(n+1):
        print(val)
        if val <= 0:
            break
        val -= amari[i]
        ans += 1

    print(ans)

Fixed code:
from math import fabs
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
tarinai = []
amari = []
for i in range(n):
    if a[i] - b[i] < 0:
        tarinai.append(a[i] - b[i])
    elif a[i] - b[i] > 0:
        amari.append(a[i] - b[i])
tarinai.sort()
amari.sort()
amari.reverse()

ans = 0
if fabs(sum(tarinai)) > sum(amari):
    print('-1')
else:
    ans += len(tarinai)
    val = fabs(sum(tarinai))
    for i in range(n+1):
        #print(val)
        if val <= 0:
            break
        val -= amari[i]
        ans += 1

    print(ans)
Buggy code:
N=int(input())
A=list(map(int,input().split(' ')))
B=list(map(int,input().split(' ')))
plus=[]
minus = 0
ans = 0
if sum(A)<sum(B):
    print(-1)
    exit()
for a,b in zip(A,B):
    if a-b >=0:
        plus.append(a-b)
    elif a-b<0:
        minus += a-b
        ans += 1
if minus==0:
    print(0)
    exit()
sorted(plus,reverse=True)
for i in sorted(plus,reverse=True):
    print(i)
    minus += i
    ans += 1
    if minus >=0:
        print(ans)
        break

Fixed code:
N=int(input())
A=list(map(int,input().split(' ')))
B=list(map(int,input().split(' ')))
plus=[]
minus = 0
ans = 0
if sum(A)<sum(B):
    print(-1)
    exit()
for a,b in zip(A,B):
    if a-b >=0:
        plus.append(a-b)
    elif a-b<0:
        minus += a-b
        ans += 1
if minus==0:
    print(0)
    exit()
for i in sorted(plus,reverse=True):
    minus += i
    ans += 1
    if minus >=0:
        print(ans)
        break
Buggy code:
import sys
def input(): return sys.stdin.readline().rstrip()

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

    sum = 0
    ans = 0
    rest = []
    for a, b in zip(A, B):
        if b > a:
            sum += b - a
            ans += 1
        else:
            rest.append(a - b)
    rest.sort(reverse=True)

    for r in rest:
        sum -= r
        ans += 1
        if sum <= 0:
            break
    if sum > 0:
        print(-a)
    else:
        print(ans)
    
if __name__ == '__main__':
    main()


Fixed code:
import sys
def input(): return sys.stdin.readline().rstrip()

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

    sum = 0
    ans = 0
    rest = []
    for a, b in zip(A, B):
        if b > a:
            sum += b - a
            ans += 1
        else:
            rest.append(a - b)
    rest.sort(reverse=True)

    if sum <= 0:
        print(0)
        exit()

    for r in rest:
        sum -= r
        ans += 1
        if sum <= 0:
            break
    if sum > 0:
        print(-1)
    else:
        print(ans)
    
if __name__ == '__main__':
    main()
Buggy code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
if sum(A) < sum(B):
    print(-1)
    quit()
C = []
c = 0
for i in range(N):
    if A[i] < B[i]:
        c += B[i] - A[i]
    else:
        C.append(A[i] - B[i])
C.sort()
while c > 0:
    x = C.pop()
    c -= x
print(len(C))

Fixed code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
if sum(A) < sum(B):
    print(-1)
    quit()
C = []
c = 0
for i in range(N):
    if A[i] < B[i]:
        c += B[i] - A[i]
    else:
        C.append(A[i] - B[i])
C.sort()
while c > 0:
    x = C.pop()
    c -= x
print(N-len(C))
Buggy code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
ans=0
d=0

if sum(a)<sum(b):
    print(-1)
else:
    for i in range(n):
        c.append(a[i]-b[i])
        if a[i]<b[i]:
            d-=a[i]-b[i]
            ans+=1
            
c.sort()
c.reverse()
e=0

for i in range(n):
    if e>=d:
        break
    else:
        e+=c[i]
        ans+=1

print(ans)


Fixed code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
ans=0
d=0
flag=True
if sum(a)<sum(b):
    print(-1)
else:
    flag=False
    for i in range(n):
        c.append(a[i]-b[i])
        if a[i]<b[i]:
            d-=a[i]-b[i]
            ans+=1
            
c.sort()
c.reverse()
e=0

for i in range(n):
    if e>=d:
        break
    else:
        e+=c[i]
        ans+=1
if not flag:
    print(ans)
Buggy code:
n = int(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)

Fixed code:
n = int(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)
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()
chsum = 0
ans = 0
for i in range(n):
  if c[i] < 0:
    chsum -= c[i]
    c[i] = 0
    ans += 1
for i in range(n-1,-1,-1):
  if chsum > 0:
    chsum -= c[i]
    c[i] -= (min(chsum,c[i]))
    ans += 1
print(ans)
    

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()
chsum = 0
ans = 0
if sum(c)<0:
  print(-1)
  exit()
for i in range(n):
  if c[i] < 0:
    chsum -= c[i]
    c[i] = 0
    ans += 1
for i in range(n-1,-1,-1):
  if chsum > 0:
    chsum -= c[i]
    c[i] -= (min(chsum,c[i]))
    ans += 1
print(ans)
Buggy code:
import numpy as np
import sys
input = sys.stdin.buffer.readline

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

c = a - b
m = np.sum(c[c < 0])
p = np.sort(c[c >= 0])[::-1]
cnt = n - p.size

for i in p:
    if m >= 0:
        print(cnt)
        exit()
    m += i
    cnt += 1
print(-1)

Fixed code:
import numpy as np
import sys
input = sys.stdin.buffer.readline

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

c = a - b
m = np.sum(c[c < 0])
p = np.sort(c[c >= 0])[::-1]
cnt = n - p.size

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

for i in p:
    m += i
    cnt += 1
    if m >= 0:
        print(cnt)
        exit()
print(-1)
Buggy code:
import numpy as np
from collections import deque
import sys 
N=int(input())
A=np.array([int(i) for i in input().split()])
B=np.array([int(i) for i in input().split()])
C = A-B
minus_idx=np.where(C<0)
plus_idx=np.where(C>0)
minus = np.sum(C[minus_idx])
plus = deque(np.sort(C[plus_idx]))
len_plus = len(plus)
if len_plus == 0:
    print(-1)
    sys.exit()
count = 0
while minus<0:
    minus += plus.pop()
    count += 1
    len_plus -= 1
    if len_plus == 0:
        print(-1)
        sys.exit()
print(len(minus_idx[0])+count)

Fixed code:
import numpy as np
from collections import deque
import sys 
N=int(input())
A=np.array([int(i) for i in input().split()])
B=np.array([int(i) for i in input().split()])
C = A-B
minus_idx=np.where(C<0)
plus_idx=np.where(C>=0)
minus = np.sum(C[minus_idx])
plus = deque(np.sort(C[plus_idx]))
len_plus = len(plus)

if len(minus_idx[0]) == 0:
    print(0)
    sys.exit()
if len_plus == 0:
    print(-1)
    sys.exit()
count = 0
while minus<0:
    try:
        minus += plus.pop()
        count += 1
        len_plus -= 1
    except:
        print(-1)
        sys.exit()
print(len(minus_idx[0])+count)
Buggy code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AB=sorted([i-m for i,m in zip(A,B)])

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

data=[i for i in AB if i<0]
count=len(data)
value=sum(data)
_N=N-1

while value<0:
    print(_N)
    value+=AB[_N]
    count+=1
    _N-=1
print(count)


Fixed code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AB=sorted([i-m for i,m in zip(A,B)])

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

data=[i for i in AB if i<0]
count=len(data)
value=sum(data)
_N=N-1

while value<0:
    value+=AB[_N]
    count+=1
    _N-=1
print(count)
Buggy code:
# keyence2019C - Exam and Wizard
def main():
    N, *AB = map(int, open(0).read().split())
    ans, shortage, pos = 0, 0, []
    for i, j in zip(AB[:N], B[N:]):
        x = i - j
        if x >= 0:
            pos.append(x)
        else:
            ans += 1
            shortage += x
    for i in sorted(pos, reverse=1):
        if shortage >= 0:
            break
        ans += 1
        shortage += i
    flg = shortage >= 0
    print(ans if flg else -1)  # -1: shoratage still remains


if __name__ == "__main__":
    main()

Fixed code:
# keyence2019C - Exam and Wizard
def main():
    N, *AB = map(int, open(0).read().split())
    ans, shortage, pos = 0, 0, []
    for i, j in zip(AB[:N], AB[N:]):
        x = i - j
        if x >= 0:
            pos.append(x)
        else:
            ans += 1
            shortage += x
    for i in sorted(pos, reverse=1):
        if shortage >= 0:
            break
        ans += 1
        shortage += i
    flg = shortage >= 0
    print(ans if flg else -1)  # -1: shoratage still remains


if __name__ == "__main__":
    main()
Buggy code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

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

idx=-1
for i in range(N):
  while(diff[i]<0):
    if diff[idx]< 0:
      print("-1")
      exit(0)
    if abs(diff[i]) >= diff[idx]:
      diff[i]+=diff[idx]
      diff[idx]=0
      idx-=1
    else:
      diff[idx]+=diff[i]
      diff[i]=0
      
C=[B[i]+diff[i] for i in range(N)]
ans=0
for i in range(N):
  if A[i]!=C[i]:
    ans+=1
print(ans)

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

diff=[[A[i]-B[i],i] for i in range(N)]
diff=sorted(diff,key=lambda x:x[0])

idx=-1
for i in range(N):
  while(diff[i][0]<0):
    if diff[idx][0]< 0:
      print("-1")
      exit(0)
    if abs(diff[i][0]) >= diff[idx][0]:
      diff[i][0]+=diff[idx][0]
      diff[idx][0]=0
      idx-=1
    else:
      diff[idx][0]+=diff[i][0]
      diff[i][0]=0
diff=sorted(diff,key=lambda x:x[1])
C=[B[i]+diff[i][0] for i in range(N)]
ans=0
for i in range(N):
  if A[i]!=C[i]:
    ans+=1
print(ans)
Buggy code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
diff=[]
d=0
ans=0
for i in range(N):
  if A[i]<B[i]:
    d+=B[i]-A[i]
    ans+=1
  elif A[i]>B[i]:
    diff.append(A[i]-B[i])

diff=sorted(diff,reverse=True)

#print(d)

f=False
for i in range(len(diff)):
  if d<=0:
    ans+=i
    f=True
    break
  d-=diff[i]
  

if f:
  print(ans)
else:
  print(-1)
#print(diff)

Fixed code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
diff=[]
d=0
ans=0
for i in range(N):
  if A[i]<B[i]:
    d+=B[i]-A[i]
    ans+=1
  elif A[i]>B[i]:
    diff.append(A[i]-B[i])

diff=sorted(diff,reverse=True)
diff.append(0)

#print(d)

f=False
for i in range(len(diff)):
  if d<=0:
    ans+=i
    f=True
    break
  d-=diff[i]
  
  

if f:
  print(ans)
else:
  print(-1)
#print(diff)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

c=sorted([a[i]-b[i] for i in range(n)],reverse=True)

if sum(c)<0:
    print(-1)
else:
    d=[i for i in c if i<0]
    cnt=len(d)
    d=abs(sum(d))
    print(c)
    i=0
    while d>0:
        d-=c[i]
        cnt+=1
        i+=1
    print(cnt)

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

c=sorted([a[i]-b[i] for i in range(n)],reverse=True)

if sum(c)<0:
    print(-1)
else:
    d=[i for i in c if i<0]
    cnt=len(d)
    d=abs(sum(d))
    i=0
    while d>0:
        d-=c[i]
        cnt+=1
        i+=1
    print(cnt)
Buggy code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
if sum(A) < sum(B):
    print(-1)
    exit()
diff = [A[i]-B[i] for i in range(N)]
m = 0
cnt = 0
for d in diff:
    if d < 0:
        m += d
        cnt += 1
diff.sort(reverse = 1)
for d in diff:
    m += d
    cnt += 1
    if m >= 0:
        break
print(cnt)


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()
diff = [A[i]-B[i] for i in range(N)]
m = 0
cnt = 0
for d in diff:
    if d < 0:
        m += d
        cnt += 1
diff.sort(reverse = 1)
for d in diff:
    if m >= 0:
        break
    m += d
    cnt += 1  
print(cnt)
Buggy code:
n = int(input())
a = [int(item) for item in input().split()]
b = [int(item) for item in input().split()]

asubb = []
for aa, bb in zip(a, b):
    asubb.append(aa - bb)
asubb.sort(reverse=True)

if sum(asubb) < 0:
    print(-1)
    exit()

minus_sum = 0
ans = 0
for item in asubb[::-1]:
    if item > 0:
        break
    minus_sum += item
    ans += 1

for item in asubb:
    minus_sum += item
    ans += 1
    if minus_sum >= 0:
        break

print(ans)

Fixed code:
n = int(input())
a = [int(item) for item in input().split()]
b = [int(item) for item in input().split()]

asubb = []
for aa, bb in zip(a, b):
    asubb.append(aa - bb)
asubb.sort(reverse=True)

if sum(asubb) < 0:
    print(-1)
    exit()

minus_sum = 0
ans = 0
for item in asubb[::-1]:
    if item >= 0:
        break
    minus_sum += item
    ans += 1

for item in asubb:
    if minus_sum >= 0:
        break
    minus_sum += item
    ans += 1

print(ans)
Buggy code:
N = int(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 reverse(diff):
    if neg >= 0:
        break
    count += 1
    neg += d

print(count)

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

D=[]
Asum=0
Bsum=0
Dnegative=0
Dnegative_n=0
Dsum=0
for i in range(N):
  D.append(A[i]-B[i])
  Asum += A[i]
  Bsum += B[i]
  if A[i]-B[i]<0:
    Dnegative += A[i]-B[i]
    Dnegative_n += 1
if(Asum < Bsum):
  print(-1)
  exit()
  
D.sort()

for i in range(N):
  Dsum -= D[N-i-1]
  if Dsum < Dnegative:
    print(Dnegative_n+i+1)
    exit()

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

D=[]
Asum=0
Bsum=0
Dnegative=0
Dnegative_n=0
Dsum=0
for i in range(N):
  D.append(A[i]-B[i])
  Asum += A[i]
  Bsum += B[i]
  if A[i]-B[i]<0:
    Dnegative += A[i]-B[i]
    Dnegative_n += 1
if Asum < Bsum:
  print(-1)
  exit()

if Dnegative_n==0:
  print(0)
  exit()
D.sort()

for i in range(N):
  Dsum -= D[N-i-1]
  if Dsum <= Dnegative:
    print(Dnegative_n+i+1)
    exit()
Buggy code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ov = []
un = 0
cnt = 0
for i in range(n):
  c = a[i]-b[i]
  if c >= 0:
    ov.append(c)
  else:
    un += c
    cnt += 1
if un == 0:
  print(0)
else:
  un *= -1
  ov.sort(reverse=True)
  ov2 = 0
  for i in range(n):
    ov2 += ov[i]
    if ov2 >= un:
      print(cnt+i+1)
      break
  else:
    print(-1)

Fixed code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ov = []
un = 0
cnt = 0
for i in range(n):
  c = a[i]-b[i]
  if c >= 0:
    ov.append(c)
  else:
    un += c
    cnt += 1
if un == 0:
  print(0)
else:
  un *= -1
  ov.sort(reverse=True)
  ov2 = 0
  for i in range(len(ov)):
    ov2 += ov[i]
    if ov2 >= un:
      print(cnt+i+1)
      break
  else:
    print(-1)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
s=sum(b)-sum(a)
if s<0:
    print(-1)
else:
    c=[0]*n
    po=0
    ze=0
    ne=0
    for i in range(n):
        c[i]=a[i]-b[i]
        if c[i]>0:
            po+=c[i]
        elif c[i]<0:
            ne-=c[i]
        else:
            ze+=1
    ans=0
    c=sorted(c)
    for i in range(n):
        if ne>=c[i] and c[i]>0:
            ans+=1
            s-=c[i]
    print(n-ans) 
        


Fixed code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
s=sum(a)-sum(b)
if s<0:
    print(-1)
else:
    c=[0]*n
    po=0
    ze=0
    ne=0
    nc=0
    for i in range(n):
        c[i]=a[i]-b[i]
        if c[i]>0:
            po+=c[i]
        elif c[i]<0:
            ne-=c[i]
            nc+=1
        else:
            ze+=1
    ans=0
    c=sorted(c)
    for i in range(n-1,-1,-1):
        if ne>0:
            ans+=1
        if c[i]>0:
            ne=ne-c[i]
        
    print(nc+ans)
Buggy code:
N = int(input())
A = input().split()
B = input().split()
count = 0
a = []
b = []
c = []
e = 0
for i in range(N):
  a.append(float(A[i]))
  b.append(float(B[i]))
su=sum(a)-sum(b)
if su <0:
  print(-1)
  exit()
else:
  for i in range(N):
    C=a[i]-b[i]
    if C >=0:
      c.append(C)
    else:
      e+=C
      count += 1

c.sort(reverse=True)
for i in range(len(c)):
  d=c[i]-e
  count += 1
  if d >= 0:
    print(count)
    exit()
  else:
    continue
print(-1)

Fixed code:
N = int(input())
A = input().split()
B = input().split()
count = 0
a = []
b = []
c = []
e = 0
for i in range(N):
  a.append(float(A[i]))
  b.append(float(B[i]))
su=sum(a)-sum(b)
if su <0:
  print(-1)
  exit()
else:
  for i in range(N):
    C=a[i]-b[i]
    if C >=0:
      c.append(C)
    else:
      e+=C
      count += 1
c.sort(reverse=True)
if e == 0:
  print(0)
  exit()
else:
  for i in range(len(c)):
    e=c[i]+e
    count += 1
    if e >= 0:
      print(count)
      exit()
    else:
      continue
Buggy code:
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [A[i]-B[i] for i in range(N)]
C = sorted(C)
if sum(C) < 0:
  print(-1)
else:
  if C[0] >= 0:
    print(0)
  else :
    cnt = 0
    point = 0
    for i in range(N):
      if C[i] < 0 :
        cnt+=1
        point += C[i]
      elif C[i] > 0 :
        cnt+=1
        point += C[i]
        if point >= 0:
          print(cnt)
          break

Fixed code:
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [A[i]-B[i] for i in range(N)]
C = sorted(C)
if sum(C) < 0:
  print(-1)
else:
  if C[0] >= 0:
    print(0)
  else :
    cnt = 0
    point = 0
    for i in range(N):
      if C[i] < 0 :
        cnt+=1
        point += C[i]
      else :
        break
    for i in range(N):
      cnt+=1
      point += C[-1-i]
      if point>=0:
        print(cnt)
        break
Buggy code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

total = 0
diff_list = []
smaller_num = 0
for n in range(N):
    if A[n] < B[n]:
        total += B[n] - A[n]
        smaller_num += 1
    else:
        diff_list.append(A[n] - B[n])

diff_list = sorted(diff_list, reverse = True)
diff_total = 0
diff_count = 0
for i, diff in enumerate(diff_list):
    if diff_total >= total:
        diff_count = i
        break
    diff_total += diff

if diff_total < total:
    print(-1)
else:
    print(smaller_num + diff_count)


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

total = 0
diff_list = []
smaller_num = 0
for n in range(N):
    if A[n] < B[n]:
        total += B[n] - A[n]
        smaller_num += 1
    else:
        diff_list.append(A[n] - B[n])

diff_list = sorted(diff_list, reverse = True)
diff_total = 0
diff_count = 0
for i, diff in enumerate(diff_list):
    diff_total += diff
    if diff_total >= total:
        diff_count = i + 1
        break

if smaller_num == 0:
    print(0)
elif diff_total < total:
    print(-1)
else:
    print(smaller_num + diff_count)
Buggy code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

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

s = 0
cnt = 0
delta = []
for i in range(N):
    if A[i] < B[i]:
        cnt += 1
        s = B[i] - A[i]
    else:
        delta.append(A[i] - B[i])
n = 0
for d in sorted(delta, reverse=True):
    if n < s:
      n += d
      cnt += 1
    else:
        break
print(cnt)


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

s = 0
cnt = 0
delta = []
for i in range(N):
    if A[i] < B[i]:
        cnt += 1
        s += B[i] - A[i]
    else:
        delta.append(A[i] - B[i])
n = 0
for d in sorted(delta, reverse=True):
    if n < s:
      n += d
      cnt += 1
    else:
        break
print(cnt)
Buggy code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
k = []
j = 0
na= 0
c = 0
if sum(a)<sum(b):
    print(-1)
else:
    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()
        k = k[::-1]
    while na > 0:
        na -=k[j]
        c +=1
        j+=1
    print(c)


Fixed code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
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)