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



Sample input:
3
2 3 5
3 4 1


Sample output:
3

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#キーエンス C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
b = list(map(int,sys.stdin.readline().split()))
c = []
d = []
for i in range(n):
    if a[i] / b[i] < 1:
        c.append([a[i],b[i],a[i]/b[i]])
    else:
        d.append([a[i],b[i],a[i]/b[i]])
c.sort(key = itemgetter(2))
d.sort(key = itemgetter(2),reverse = True)
c = c + d
x = 0
ans = 0
for i in range(n):
    if c[i][0] < c[i][1]:
        x += c[i][1] - c[i][0]
        ans += 1
    else:
        if x > 0:
            x -= min(x,c[i][0]-c[i][1])
            ans += 1
if x != 0:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mp = 0
ans = 0
for i in range(n):
    if a[i] < b[i]:
        mp -= b[i] - a[i]
    else:
        ans += 1
for i in range(n):
    if a[i] > b[i]:
        mp += min(a[i] - b[i], -mp)
        ans -= 1
    if mp == 0:
        break
else:
    print(-1)
    exit(0)
print(n - ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
diff = []
for a, b in zip(A, B):
    diff.append(a - b)
if sum(diff) < 0:
    print(-1)
else:
    positive = [i for i in diff if i > 0]
    negative = [i for i in diff if i < 0]
    print(sorted(positive, reverse=True))
    if len(negative):
        numNegative = count = len(negative)
        sumNegative = sum(negative)
        totalPositive = 0
        for p in sorted(positive, reverse=True):
            totalPositive += p
            count += 1
            if totalPositive >= -sumNegative:
                break
        print(count)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
diff = []
for a, b in zip(A, B):
    diff.append(a - b)
if sum(diff) < 0:
    print(-1)
else:
    negative = [i for i in diff if i < 0]
    if not len(negative):
        print(0)
    else:
        positive = [i for i in diff if i > 0]
        numNegative = count = len(negative)
        sumNegative = sum(negative)
        for p in sorted(positive, reverse=True):
            count += 1
            if p >= sumNegative:
                break
            else:
                sumNegative -= p
        print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
C - Exam and Wizard
https://atcoder.jp/contests/keyence2019/tasks/keyence2019_c

"""
import sys


def solve(N, A, B):
    total_A = sum(A)
    total_B = sum(B)
    if total_A < total_B:
        return -1
    r = total_A - total_B
    margins = sorted([a-b for a, b in zip(A, B) if a-b >= 0], reverse=True)
    ans = 0
    while margins and margins[0] <= r:
        r -= margins.pop()
        ans += 1
    return N-ans


def main(args):
    N = int(input())
    A = [int(a) for a in input().split()]
    B = [int(b) for b in input().split()]
    ans = solve(N, A, B)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

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

d = []

p = 0
m = 0

ans = 0
for i in range(n):
    d.append(a[i]-b[i])
    if d[-1]>0:
        p+= d[-1]
    if d[-1]<0:
        m-= d[-1]
        ans +=1

if p<m:
    print(-1)
    exit()

d.sort()
d.reverse()

i = 0
while m>0:
    m-=d[i]
    ans += 1
print(ans)

Submission status: Wrong Answer

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

if sum(a) < sum(b):
    print(-1)
else:
    c = list(a[i]-b[i] for i in range(n))
    c.sort()
    extra = sum(c)
    cnt = 0
    for i in range(n):
        if c[i] > 0 and c[i] <= extra:
            extra -= c[i]
            cnt += 1
    print(n-cnt)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


surplus = [(a - b) for a, b in zip(A, B) if (a - b) > 0]
surplus.sort(reverse=True)
surplus = [0] + list(accumulate(surplus))

short = [(b - a) for a, b in zip(A, B) if (b - a) > 0]
need = sum(short)
short_num = len(short)


if need > sum(surplus):
    print(-1)
    exit()
else:
    for i in range(len(surplus)):
        if surplus[i] >= need:
            print(i + short_num)
            exit()

Submission status: Wrong Answer

Solution code:
if __name__=="__main__":
    n = int(input())
    A = [int(i) for i in input().split(' ')]
    B = [int(i) for i in input().split(' ')]
    C = sorted(A)
    D = sorted(B)
    for i in range(n):
        if (C[i] < D[i]):
            print(-1)
            exit(0)
    C = []
    D = []
    for i in range(n):
      if (A[i] < B[i]):
          C.append(A[i])
          D.append(B[i])
    C = sorted(C)
    D = sorted(D)
    l = 0
    ans = len(C)
    for i in range(len(C)):
        if (C[i] < D[l]):
            ans += 1
        else:
            l += 1
    print(ans)

Submission status: Wrong Answer

Solution 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)
D.sort()

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
SA = sum(A)
SB = sum(B)
if SA < SB:
  print(-1)
else:
  under = []
  over = []
  cnt = 0
  for i in range(N):
    if A[i] < B[i]:
      under.append(abs(A[i]-B[i]))
      cnt += 1
    elif A[i] > B[i]:
      over.append(abs(A[i]-B[i]))
  over.sort()
  over.reverse()
  un_cnt = 0
  ov_cnt = 0
  if len(under) != 0:
    cnt += 1
    while un_cnt < len(under):
      if over[ov_cnt] > under[un_cnt]:
        over[ov_cnt] -= under[un_cnt]
        un_cnt += 1
      else:
        over[ov_cnt] = 0
        over[ov_cnt+1] -= (under[un_cnt]-over[ov_cnt])
        ov_cnt += 1
        un_cnt += 1
        cnt += 1
  print(cnt)

Submission status: Wrong Answer

Solution 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(0,n,-1):
        if ne>0:
            ans+=1
        if c[i]>0:
            ne=ne-c[i]
        
    print(nc+ans)

Submission status: Wrong Answer

Solution 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
    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
            ne-=c[i]
    print(n-ans-ze)

Submission status: Wrong Answer

Solution 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
    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
            ne-=c[i]
    print(n-ans)

Submission status: Wrong Answer

Solution 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
            ne-=c[i]
    print(n-ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution 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
    for i in range(n):
        c[i]=a[i]-b[i]
    ans=0
    c=sorted(c)
    for i in range(n):
        if s>=c[i] and c[i]>=0:
            ans+=1
            s-=c[i]
    print(n-ans)

Submission status: Wrong Answer

Solution 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
    for i in range(n):
        c[i]=a[i]-b[i]
    ans=0
    c=sorted(c)
    for i in range(n):
        if s>=c[i]:
            ans+=1
            s-=c[i]
    print(n-ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

#N = input()
#a = input().split()
#b = input().split()
#A = []
#B = []
#for k in range(0,len(a)):
#    A.append(int (a[k]))
#    B.append(int (b[k]))

A = [2,3,5]
B = [3,4,1]

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

#print(sum_A)
#print(sum_B)

sub_AB = []
List = []

if (sum_A>sum_B) :
    for i in range(0,len(A)) :
        sub = A[i]-B[i]
        sub_AB.append(sub)
        if (sub<0) :
            List.append(sub)
        else :
            continue
    sum_List = sum(List)            
    Max = max(sub_AB)
    delta = Max + sum_List
    
    sub_AB.sort()
    sub_AB.reverse()
    count_a = 0
    while (sub_AB[-1]<0):
        sub_AB.pop()
        count_a+=1 
    if (count_a==0):
        print(0)
        exit()

    count_b = 1

    while (sum_List+max(sub_AB)<=0):
        sub_AB.remove(max(sub_AB))
        count_b+=1

    count = count_a+count_b
    print(count)

else :
    print(-1)
    exit()

"""
    sub_AB.sort()
    sub_AB.reverse()
    count_a = 0
    while (sub_AB[-1]<0):
        sub_AB.pop()
        count_a+=1 
    if (count_a==0):
        print(0)
        exit()
    
    count_b = 0

    print(max(sub_AB))

    if (max(sub_AB)==None):
        pass
    else :
        while (sum_List+max(sub_AB)>=0):
            sub_AB.remove(max(sub_AB))
            count_b+=1

        count = count_a+count_b
        print(len(A)-count)

else :
    print(-1)
"""

Submission status: Wrong Answer

Solution code:
import numpy as np

N = input()
a = input().split()
b = input().split()
A = []
B = []
for k in range(0,len(a)):
    A.append(int (a[k]))
    B.append(int (b[k]))

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

#print(sum_A)
#print(sum_B)

sub_AB = []
List = []

if (sum_A>sum_B) :
    for i in range(0,len(A)) :
        sub = A[i]-B[i]
        sub_AB.append(sub)
        if (sub<0) :
            List.append(sub)

    sum_List = sum(List)            
    Max = max(sub_AB)
    delta = Max + sum_List

    sub_AB.sort()
    sub_AB.reverse()
    count = 0
    while (sub_AB[-1]<0):
        sub_AB.pop()
        count+=1 
    if (count==0):
        print(0)
        exit()

    sub_AB.remove(max(sub_AB))

    if (delta>=0):
        print(len(sub_AB))
        print("num:",len(A)-len(sub_AB))
        exit()

#     if (delta >= 0):
#         while (delta==0):
#             sum_List = sum(List)
#             Max = max(sub_AB)            
#             delta = Max + sum_List
else:
    print(-1)

Submission status: Wrong Answer

Solution 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)):
    d=c[i]+e
    print(d)
    count += 1
    if d <= 0:
      print(count)
      exit()
    else:
      continue

Submission status: Wrong Answer

Solution 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)):
    d=c[i]+e
    count += 1
    if d >= 0:
      print(count)
      exit()
    else:
      continue

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution 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

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
pos = []
total = 0
count = 0

if sum(B) > sum(A):
	count = -1
else:
	for i in range(n):
		if A[i] < B[i]:
			total += A[i] - B[i]
			count += 1
		else:
			pos.append(A[i] - B[i])

	pos_new = sorted(pos, reverse=True)
	
	while total < 0:
		for i in pos_new:
			count += 1
			total += i


print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = input()
N = int(N)
exam = []
for i in range(2):
    x = input()
    exam.append([int(x.split()[i]) for i in range(N)])

diff = [exam[0][n] - exam[1][n] for n in range(N)]
diff.sort(reverse=True)

print(diff)
if sum(diff) < 0:
    print(-1)
    quit()

i = N - 1
minsum = 0
_counter = 0
while diff[i] < 0:
    minsum = minsum + diff[i]
    i = i - 1
    _counter = _counter + 1

counter = 0
while minsum < 0:
    minsum = minsum + diff[counter]
    counter = counter + 1

print(counter + _counter)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python
import sys
from functools import reduce

def main():
    line = sys.stdin.readlines()
    index = int(line[0].strip())
    line1 = line[1].strip()
    line2 = line[2].strip()
    listA = [int(x) for x in line1.split(' ')]
    listB = [int(x) for x in line2.split(' ')]
    
    maxA = max(listA)
    maxB = max(listB)

    if maxA < maxB:
        print(-1)
        return

    diff = [listA[i] - listB[i] for i in range(index)] 
    diff.sort()

    if not checkBeMinus(diff):
        print(0)
        return

    # Split minus and plus item
    plus = [x for x in diff if x >= 0]
    plus.sort(reverse=True)
    minus = [x for x in diff if x < 0]

    changeCount = len(minus)
    allMinus = reduce((lambda x, y: x + y), minus)
    accm = 0
    for p in plus:
        accm += p
        changeCount += 1
        if accm > abs(allMinus):
            break

    print(changeCount)
    

def checkBeMinus(list):
    return min(list) < 0

main()

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python
import sys
from functools import reduce

def main():
    line = sys.stdin.readlines()
    index = int(line[0].strip())
    line1 = line[1].strip()
    line2 = line[2].strip()
    listA = [int(x) for x in line1.split(' ')]
    listB = [int(x) for x in line2.split(' ')]
    
    maxA = max(listA)
    maxB = max(listB)

    if maxA < maxB:
        print(-1)
        return

    diff = [listA[i] - listB[i] for i in range(index)] 
    diff.sort()

    if not checkBeMinus(diff):
        print(0)
        return

    # Split minus and plus item
    plus = [x for x in diff if x >= 0]
    plus.sort(reverse=True)
    minus = [x for x in diff if x < 0]

    changeCount = len(minus)
    allMinus = reduce((lambda x, y: x + y), minus)
    accm = 0
    for p in plus:
        accm += p
        changeCount += 1
        if accm >= abs(allMinus):
            break

    print(changeCount)
    

def checkBeMinus(list):
    return min(list) < 0

main()

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))
    minus = 0
    num_minus = 0
    plus = []
    for i, (a, b) in enumerate(zip(aa,bb)):
        judge = b-a
        if judge>0:
            minus+=judge
            num_minus += 1
        else:
            plus.append(-judge)
    if minus==0:
        print(0)
        exit()
    for i, num in enumerate(plus,1):
        minus-=num
        if minus<=0:
            print(i+num_minus)
            exit()
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np


def parse(inp):
    N = int(next(inp).split()[0])
    #     print(N)
    A = np.array(next(inp).split(), dtype=int)
    #     print(A)
    B = np.array(next(inp).split(), dtype=int)
    #     print(B)
    return N, A, B


def magic(N, D):
    moved = np.full(N, False)
    #     print(np.max(D),np.argmax(D))
    #     print(np.min(D),np.argmin(D))

    while any(np.sign(D) == -1):
        D[np.argmax(D)] += np.min(D)
        moved[np.argmax(D)] = True
        D[np.argmin(D)] += np.max(D)
        moved[np.argmin(D)] = True
    #         print(D)

    #    print(moved)
    return moved


def main(inp):
    N = inp[0]
    A = inp[1]
    B = inp[2]
    D = np.empty(N, dtype=int)
    for i in range(N):
        D[i] = A[i] - B[i]
    #    print(N,A,B,D)

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

    #     moved=magic(N,A,B,D)
    #     print(moved)

    return magic(N, D).sum()


print(main(parse(sys.stdin)))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
a = []
a=np.array(list(map(int, input().split())))
b = []
b=np.array(list(map(int, input().split())))

if a.sum() < b.sum():
    print(-1)

plus_lis=[]
count=0
minus=0
for i in range(N):
    if a[i]-b[i]<0:
        count+=1
        minus+=a[i]-b[i]
    else:
        plus_lis.append(a[i]-b[i])
        
if count ==0:
  print(0)
        
    

plus_lis.sort(reverse=True)

index=0
for i in plus_lis:
    minus+=i
    index+=1
    if minus>0:
        break
        
print(count+index)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
a = []
a=np.array(list(map(int, input().split())))
b = []
b=np.array(list(map(int, input().split())))

if a.sum() < b.sum():
    print(-1)

plus_lis=[]
count=0
minus=0
for i in range(N):
    if a[i]-b[i]<0:
        count+=1
        minus+=a[i]-b[i]
    else:
        plus_lis.append(a[i]-b[i])
        
    

plus_lis.sort(reverse=True)

index=0
for i in plus_lis:
    minus+=i
    index+=1
    if minus>0:
        break
        
print(count+index)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
a = []
a=np.array(list(map(int, input().split())))
b = []
b=np.array(list(map(int, input().split())))

if a.sum() < b.sum():
    print(-1)

plus_lis=[]
count=0
minus=0
for i in range(N):
    if a[i]-b[i]<0:
        count+=1
        minus+=a[i]-b[i]
    else:
        plus_lis.append(a[i]-b[i])
        
    

plus_lis.sort(reverse=True)

index=0
for i in plus_lis:
    minus+=i
    index+=1
    if minus>=0:
        break
        
print(count+index)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A =  []
l1 = input().split()
for i in l1:
    A.append(int(i))
B = []
l2 = input().split()
for i in l2:
    B.append(int(i))
if sum(A) < sum(B):
    print(-1)
else:
    z = 0
    ar1 = []
    ar2 = []
    for i in range(N):
        if A[i] < B[i] :
            ar1.append(B[i] - A[i])
        if A[i] > B[i]:
            ar2.append(A[i] - B[i])
    ar1.sort(reverse = True)
    ar2.sort(reverse = True)
    b = 0
    for a in ar1:
        while a > ar2[b]:
            ar2[b] = 0
            a -= ar2[b]
            b += 1
        ar2[b] -= a
        ar2.sort(reverse = True)
        if a == ar1[-1] and ar2[b] != 0:
            z = 1
    ans = 0
    for i in ar2:
        if i == 0:
            z +=1
    ans = len(ar1) + z
    print(ans)

Submission status: Wrong Answer

Solution code:
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 neg_list == 0:
            print(0)
            break
        elif neg_sum + k >= 0:
            print(j+1+len(neg_list))
            break 
        else:
            continue

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding:utf-8
import copy
n = int(input())
a = list(map(int,input().split(' ')))
b = list(map(int,input().split(' ')))
lbl = []

for idx in range(0,n):
  if a[idx] < b[idx]:
    lbl.append(a[idx] - b[idx])
  elif a[idx] > b[idx]:
    lbl.append(a[idx] - b[idx])
  else:
    lbl.append(0)

sum = 0
for x in lbl:
  sum+=x

if sum < 0:
  print(-1)
  exit()
else:
  slbl = sorted(lbl)
  oslbl = copy.copy(slbl)
  cnt = 0
  for idx in range(0,n):
    if slbl[idx] < 0:
      if slbl[idx] + slbl[-idx-1] > 0:
        slbl[-idx-1] = slbl[idx] + slbl[-idx-1]
        slbl[idx] = 0
      else:
        i = 1 
        while slbl[idx] != 0:
          if i > n:
            print(-1)
            exit()
          slbl[idx] = slbl[idx] + slbl[-idx-i]
          slbl[-idx-i] = 0
          i+=1

  cnt = 0
  for (x,y) in zip(oslbl,slbl):
    if x - y != 0:
      cnt+=1
  print(cnt)

Submission status: Wrong Answer

Solution code:
num = int(input())
power = [int(x) for x in input().split()]
exam = [int(y) for y in input().split()]
 
lack = []
has = []
for i in range(num):
  if power[i] < exam[i]:
    lack.append(exam[i] - power[i])
  else:
    has.append(power[i] - exam[i])
    
has.reverse()

if sum(has) < sum(lack):
  exit(print(-1))
  
p = 0
sl = sum(lack)

while sl > 0:
  sl -= has[p]
  p += 1
print(p+len(lack))

Submission status: Wrong Answer

Solution code:
num = int(input())
power = [int(x) for x in input().split()]
exam = [int(y) for y in input().split()]
 
lack = []
has = []
for i in range(num):
  if power[i] < exam[i]:
    lack.append(exam[i] - power[i])
  else:
    has.append(power[i] - exam[i])
    
has.reverse()

if sum(has) < sum(lack):
  exit(print(-1))
  
p = 0
sl = sum(lack)

while sl > 0:
  sl -= has[p]
  p += 1
print(p+len(lack))

print('TEST')
print('lack: ' + str(lack))
print('has: ' + str(has))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
num = int(input())
power = [int(x) for x in input().split()]
exam = [int(y) for y in input().split()]
 
lack = []
has = []
for i in range(num):
  if power[i] < exam[i]:
    lack.append(exam[i] - power[i])
  else:
    has.append(power[i] - exam[i])
has.reverse()
if sum(has) < sum(lack):
  exit(print(-1))
p = 0
sl = sum(lack)
while sl > 0:
  sl -= has[p]
  p += 1
print(p+1+len(lack))

Submission status: Wrong Answer

Solution code:
num = int(input())
power = [int(x) for x in input().split()]
exam = [int(y) for y in input().split()]
 
lack = []
has = []
for i in range(num):
	if power[i] < exam[i]:
		lack.append(exam[i] - power[i])
	else:
		has.append(power[i] - exam[i])
has.reverse()
if sum(has) < sum(lack):
	exit(print(-1))
p = 0
sl = sum(lack)
while sl > 0:
  sl -= has[p]
  p += 1
print(p+1+len(lack))

Submission status: Wrong Answer

Solution code:
num = int(input())
power = [int(x) for x in input().split()]
exam = [int(y) for y in input().split()]
 
lack = []
has = []
for i in range(num):
	if power[i] < exam[i]:
		lack.append(exam[i] - power[i])
	else:
		has.append(power[i] - exam[i])
has.reverse()
if sum(has) < sum(lack):
	exit(print(-1))
p = 0
sl = sum(lack)
while sl > 0:
  sl -= has[p]
  p += 1
print(p+1)

Submission status: Wrong Answer

Solution code:
num = int(input())
power = [int(x) for x in input().split()]
exam = [int(y) for y in input().split()]
 
lack = []
has = []
for i in range(num):
	if power[i] < exam[i]:
		lack.append(exam[i] - power[i])
	else:
		has.append(power[i] - exam[i])
has.reverse()
if sum(has) < sum(lack):
	exit(print(-1))
p = 0
sl = sum(lack)
while sl > 0:
  sl -= has[p]
  p += 1
print(p)