Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = -1

not_enough = []
enough = []

for i in range(N):
    if A[i] - B[i] < 0:
        not_enough.insert(0, abs(A[i] - B[i]))
    else:
        enough.insert(0, abs(A[i] - B[i]))

enough.sort()
enough.reverse()
not_enough.sort()
not_enough.reverse()

#print(enough)
#print(not_enough)

count = 0
whre = 0
res_eno = 0
res_not_eno = 0

if len(not_enough) == 0:
    print('0')
elif len(enough) == 0:
    print('-1')
else:
    for i in range(len(enough)):

        res_eno = enough[i]
        count += 1

        while res_eno > 0:
            #print("count" + (str)(count))
            #print("whre" + (str)(whre))
            #print("res_eno" + (str)(res_eno))
            #print("res_not_eno" + (str)(res_not_eno))

            if res_not_eno == 0:
                if res_eno >= not_enough[whre]:
                    #print('A')
                    res_eno -= not_enough[whre]
                    count += 1
                    whre += 1
                    if whre == len(not_enough):
                        break
                else:
                    #print('B')
                    res_not_eno = not_enough[whre] - res_eno
                    res_eno = 0
            else:
                if res_eno >= res_not_eno:
                    #print('C')

                    res_eno -= res_not_eno
                    res_not_eno = 0
                    count += 1
                    whre += 1
                    if whre == len(not_enough):
                        break
                else:
                    #print('D')

                    res_not_eno = res_not_eno - res_eno
                    res_eno = 0
        if whre == len(not_enough):
            break

    if res_not_eno == 0 and whre == len(not_enough):
        print(count)
    else:
        print('-1')

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

ans = -1

not_enough = []
enough = []

for i in range(N):
    if A[i] - B[i] < 0:
        not_enough.append(abs(A[i] - B[i]))
    else:
        enough.append(A[i] - B[i])

enough.sort()
enough.reverse()

#print(enough)
#print(not_enough)

count = 0
whre = 0
res_eno = 0
res_not_eno = 0

if len(not_enough) == 0:
    print('0')
elif len(enough) == 0:
    print('-1')
else:
    for i in enough:

        res_eno = i
        count += 1

        while res_eno > 0:
            #print("count" + (str)(count))
            #print("whre" + (str)(whre))
            #print("res_eno" + (str)(res_eno))
            #print("res_not_eno" + (str)(res_not_eno))

            if res_not_eno == 0:
                if res_eno >= not_enough[whre]:
                    #print('A')
                    res_eno -= not_enough[whre]
                    count += 1
                    whre += 1
                    if whre == len(not_enough):
                        break
                else:
                    #print('B')
                    res_not_eno = not_enough[whre] - res_eno
                    res_eno = 0
            else:
                if res_eno >= res_not_eno:
                    #print('C')

                    res_eno -= res_not_eno
                    res_not_eno = 0
                    count += 1
                    whre += 1
                    if whre == len(not_enough):
                        break
                else:
                    #print('D')

                    res_not_eno = res_not_eno - res_eno
                    res_eno = 0
        if whre == len(not_enough):
            break

    if res_not_eno == 0 and whre == len(not_enough):
        print(count)
    else:
        print('-1')