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:
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
supply_index_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_index_list.append(i)

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

supply = 0
supply_cnt = 0

for i in supply_index_list:
    supply += a_list[i] - b_list[i]
    supply_cnt += 1
    if supply >= lack:
        break

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

print(lack_cnt + supply_cnt)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = input()
a = input().split()
b = input().split()
ans = 0
aa = 0
plus = []
# if not min(map(int,a)) >= min(map(int,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)
print(ans)
for i in plus:
    aa = aa - i
    ans += 1
    if aa <= 0:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
a = input().split()
b = input().split()
ans = 0
aa = 0
plus = []
if not min(map(int,a)) >= min(map(int,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)

Submission status: Wrong Answer

Solution code:
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 all([a >= b for a, b in zip(a_list, b_list)]):
#      print(0)
#  # 準備度が足りていない試験がある場合
#  else:
# そもそも準備度の総量が足りない場合
if sum(a_list) < sum(b_list):
    print(-1)
else:
    # 準備度を移動すれば受かる場合
    # 一番数の大きいところから足りていないところに割り振る戦略
    # a_listをcopy
    # 準備度の余裕をリストに格納
    diff_list = a_list - b_list
    diff_list.sort()
    start = 0
    end = -1
    current_value = diff_list[end]
    while current_value < 0:
        current_value += diff_list[i]
        while current_value < 0:
            end -= 1
            current_value += diff_list[end]
        start += 1
    if start == 0:
        print(0)
    else:
        print(start - end)

Submission status: Wrong Answer

Solution code:
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 all([a >= b for a, b in zip(a_list, b_list)]):
#      print(0)
#  # 準備度が足りていない試験がある場合
#  else:
# そもそも準備度の総量が足りない場合
if sum(a_list) < sum(b_list):
    print(-1)
else:
    # 準備度を移動すれば受かる場合
    # 一番数の大きいところから足りていないところに割り振る戦略
    # a_listをcopy
    # 準備度の余裕をリストに格納
    diff_list = a_list - b_list
    diff_list.sort()
    start = 0
    end = -1
    current_value = diff_list[end]
    while current_value < 0:
        current_value += diff_list[i]
        while current_value < 0:
            end -= 1
            a += diff[end]
        start += 1
    if start == 0:
        print(0)
    else:
        print(i - j)

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

Solution code:
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.reverse()
while lack > 0:
    lack -= surp[cnt]
    cnt += 1
    ans += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
d = sorted([A[i]-B[i] for i in range(N)], reverse = True)
p, s = 0, -1
cnt = 0
for i in range(N):
  if d[i] >= 0:
    p += d[i]
    cnt += 1
    d[i] = 0
  else:
    s = i
    break
if p == 0:
  print(-1)
elif s == -1:
  print(0)
else:
  for i in range(s, N):
    p -= d[i]
    if p < 0:
      break
    else:
      cnt += 1
  print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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)
print(S, num_i, diff)
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)

Submission status: Wrong Answer

Solution code:
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()
if min(A) < min(B):
    print(-1)
    exit()
S = sum([b - a for a, b in zip(A, B) if a < b])
diff = sorted([a - b for a, b in zip(A, B)], reverse=True)
num_i = len([d for d in diff if d < 0])
for i in range(N):
    if diff[i] < 0:
        break
    if sum(diff[:i]) >= S:
        break
print(num_i + i)

Submission status: Wrong Answer

Solution code:
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 all([a >= b for a, b in zip(a_list, b_list)]):
#      print(0)
#  # 準備度が足りていない試験がある場合
#  else:
# そもそも準備度の総量が足りない場合
if sum(a_list) < sum(b_list):
    print(-1)
else:
    # 準備度を移動すれば受かる場合
    # 一番数の大きいところから足りていないところに割り振る戦略
    # a_listをcopy
    # 準備度の余裕をリストに格納
    diff_list = [c - b for c, b in zip(a_list, b_list)]
    # 一度減算し始めたら対象が0になるまで続ける
    selected_biggest_idx = diff_list.index(max(diff_list))
    count = 0
    while not all([c >= b for c, b in zip(a_list, b_list)]):
        if diff_list[selected_biggest_idx] == 0:
            selected_biggest_idx = diff_list.index(max(diff_list))
        min_idx = diff_list.index(min(diff_list))

        # 最大と最小で移し替えを行う
        if diff_list[selected_biggest_idx] < abs(diff_list[min_idx]):
            # 足りていない値のほうが大きい場合
            a_list[selected_biggest_idx] -= diff_list[selected_biggest_idx]
            a_list[min_idx] += diff_list[selected_biggest_idx]
        else:
            # 足りていない値のほうが小さい場合
            a_list[selected_biggest_idx] -= abs(diff_list[min_idx])
            a_list[min_idx] += abs(diff_list[min_idx])
        # diff_listを更新
        diff_list = [c - b for c, b in zip(a_list, b_list)]
        count += 1
    print(count)

Submission status: Wrong Answer

Solution code:
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 all([a >= b for a, b in zip(a_list, b_list)]):
#      print(0)
#  # 準備度が足りていない試験がある場合
#  else:
# そもそも準備度の総量が足りない場合
if sum(a_list) < sum(b_list):
    print(-1)
else:
    # 準備度を移動すれば受かる場合
    # 一番数の大きいところから足りていないところに割り振る戦略
    # a_listをcopy
    c_list = [a for a in a_list]
    # 準備度の余裕をリストに格納
    diff_list = [c - b for c, b in zip(c_list, b_list)]
    # 一度減算し始めたら対象が0になるまで続ける
    selected_biggest_idx = diff_list.index(max(diff_list))
    while not all([c >= b for c, b in zip(c_list, b_list)]):
        if diff_list[selected_biggest_idx] == 0:
            selected_biggest_idx = diff_list.index(max(diff_list))
        min_value = min(diff_list)
        if min_value <= 0:
            break
        else:
            min_idx = diff_list.index(min_value)

        # 最大と最小で移し替えを行う
        if diff_list[selected_biggest_idx] < abs(diff_list[min_idx]):
            # 足りていない値のほうが大きい場合
            c_list[selected_biggest_idx] -= diff_list[selected_biggest_idx]
            c_list[min_idx] += diff_list[selected_biggest_idx]
        else:
            # 足りていない値のほうが小さい場合
            c_list[selected_biggest_idx] -= abs(diff_list[min_idx])
            c_list[min_idx] += abs(diff_list[min_idx])
        # diff_listを更新
        diff_list = [c - b for c, b in zip(c_list, b_list)]
    result_count = len([1 for a, c in zip(a_list, c_list) if a != c])
    print(result_count)

Submission status: Wrong Answer

Solution code:
N = input()
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

# すべての準備度が必要度を上回っている場合
if all([a >= b for a, b in zip(a_list, b_list)]):
    print(0)
# 準備度が足りていない試験がある場合
else:
    # そもそも準備度の総量が足りない場合
    if sum(a_list) < sum(b_list):
        print(-1)
    else:
        # 準備度を移動すれば受かる場合
        # 一番数の大きいところから足りていないところに割り振る戦略
        # a_listをcopy
        c_list = [a for a in a_list]
        # 準備度の余裕をリストに格納
        diff_list = [c - b for c, b in zip(c_list, b_list)]
        # 一度減算し始めたら対象が0になるまで続ける
        selected_biggest_idx = diff_list.index(max(diff_list))
        while not all([c >= b for c, b in zip(c_list, b_list)]):
            if diff_list[selected_biggest_idx] == 0:
                selected_biggest_idx = diff_list.index(max(diff_list))
            min_value = min(diff_list)
            if min_value <= 0:
                break
            else:
                min_idx = diff_list.index(min_value)

            # 最大と最小で移し替えを行う
            if diff_list[selected_biggest_idx] < abs(diff_list[min_idx]):
                # 足りていない値のほうが大きい場合
                c_list[selected_biggest_idx] -= diff_list[selected_biggest_idx]
                c_list[min_idx] += diff_list[selected_biggest_idx]
            else:
                # 足りていない値のほうが小さい場合
                c_list[selected_biggest_idx] -= abs(diff_list[min_idx])
                c_list[min_idx] += abs(diff_list[min_idx])
            # diff_listを更新
            diff_list = [c - b for c, b in zip(c_list, b_list)]
        result_count = len([1 for a, c in zip(a_list, c_list) if a != c])
        print(result_count)

Submission status: Wrong Answer

Solution code:
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()
k = 0

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

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

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    sorted_a = sorted(a, reverse=True)
    sorted_b = sorted(b, reverse=True)
    ans = 0
    shortage = 0
    remainders = []
    for i in range(n):
        if sorted_a[i] < sorted_b[i]:
            ans = -1
            break
        if a[i] < b[i]:
            shortage += b[i] - a[i]
            ans += 1
        else:
            remainders.append(a[i] - b[i])
    else:
        remainders.sort(reverse=True)
        for remainder in remainders:
            if shortage > 0:
                shortage -= remainder
                ans += 1
            else:
                break
        else:
            ans = -1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
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
print Ans,need
Gap=[a-b for a,b in zip(A,B)]
Gap.sort(reverse=True)
index=0
print Gap
while need>0 and Ans+index<=N:
    need-=Gap[index]
    index+=1
    
if Ans+index<=N:
    print Ans+index
else:
    print "-1"

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    sorted_a = sorted(a, reverse=True)
    sorted_b = sorted(b, reverse=True)
    ans = 0
    shortage = 0
    remainders = []
    for i in range(n):
        if sorted_a[i] < sorted_b[i]:
            ans = -1
            break
        if a[i] < b[i]:
            shortage += b[i] - a[i]
            ans += 1
        else:
            remainders.append(a[i] - b[i])
    else:
        remainders.sort(reverse=True)
        for remainder in remainders:
            if shortage > 0:
                shortage -= remainder
                ans += 1
            else:
                break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
def main():
    n = int(input())
    a_list = np.array([int(x) for x in input().split()])
    b_list = np.array([int(x) for x in input().split()])
    y = 0
    if np.any((np.sort(a_list) - np.sort(b_list))<0):
        return -1
    elif  sum(((a_list - b_list) < 0) * 1) == 0:
        return 0
    else:
        return sum(((b_list - a_list) > 0) * 1) * 2 -1
print(main())

Submission status: Wrong Answer

Solution 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 nn==N:
        print(0)
    else:
        print(N-n0-n)

Submission status: Wrong Answer

Solution code:
def main():
    num = int(input())
    ability = [int(x) for x in input().split()]
    exam = [int(y) for y in input().split()]
    sa = sorted(ability)
    se = sorted(exam)
    for i in range(0,num):
        if sa[i] < se[i]:
            return -1
    a = 0
    for x in range(num):
        if ability[x] < exam[x]:
            a += 1
    return a * 2

print(main())

Submission status: Wrong Answer

Solution code:
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
        
Gap=[a-b for a,b in zip(A,B)]
Gap.sort(reverse=True)
index=0
while need>0 and Ans+index<=N:
    need-=Gap[index]
    index+=1
    
if Ans+index<N:
    print Ans+index
else:
    print "-1"

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
e = [[int(i) for i in input().split()] for i in range(2)]

sa = [e[0][i] - e[1][i] for i in range(len(e[0]))]
pura = np.array([a for a in sa if a > 0])
pura.sort()
pura = pura[::-1]
mai = np.array([a for a in sa if a < 0])
mai = -mai

kai = 0
point = 0
if mai.sum() > pura.sum():
    print(-1)
else:
    sum_mai = mai.sum()
    kai = mai.size
    while sum_mai > 0:
        sum_mai -= pura[point]
        point += 1
    print(kai)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    num = int(input())
    ability = [int(x) for x in input().split()]
    exam = [int(y) for y in input().split()]
    sa = sorted(ability)
    se = sorted(exam)
    for i in range(0,num):
        if sa[i] < se[i]:
            return -1
    a = 0
    for x in range(num):
        if ability[x] < exam[x]:
            a += 1
    return a

print(main())

Submission status: Wrong Answer

Solution code:
def main():
    num = int(input())
    ability = [int(x) for x in input().split()]
    exam = [int(y) for y in input().split()]
    sa = sorted(ability)
    se = sorted(exam)
    for i in range(0,num):
        if sa[i] < se[i]:
            return -1
    a = 0
    for x in range(num):
        if ability[x] > exam[x]:
            a += 1
    return a

print(main())

Submission status: Wrong Answer

Solution code:
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
        
Gap=[a-b for a,b in zip(A,B)]
Gap.sort(reverse=True)
index=0
while need>0 and Ans+index<N:
    if Gap[index]<=0:
        Ans=N
        break
    need-=Gap[index]
    index+=1
    
if Ans<N:
    print Ans+index
else:
    print "-1"

Submission status: Wrong Answer

Solution code:
from itertools import permutations
thisinput=str(input())
thisinput2=str(input()).split()
thisinput3=str(input()).split()
print(thisinput2,thisinput3)
count=[]
for p in permutations(thisinput2):
    for x in range(int(thisinput)):
        if p[x]>=thisinput3[x] and x!=int(thisinput)-1:
            continue
        if p[x]>=thisinput3[x] and x==int(thisinput)-1:
            sum=0
            for y in range(int(thisinput)):
                if p[x]!=thisinput2[x]:
                    sum+=1
            count.append(sum)
        else:
            break
if len(count)==0:
    print("-1")
else:
    count.sort()
    print(count[0])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

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

if np.sum(A) <= np.sum(B):
  print(-1)
else:
  print( np.sum(A < B))

Submission status: Wrong Answer

Solution code:
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+=max(b-a,0)
        Ans+=1

Gap=[a-b for a,b in zip(A,B)]
Gap.sort(reverse=True)

while need>0 and Ans<N:
    if Gap[Ans]<0:
        Ans=N
        break
    need-=Gap[Ans]
    Ans+=1
    
if Ans<N:
    print Ans
else:
    print "-1"

Submission status: Wrong Answer

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

if sum(a) < sum(b):
    res = -1
else:
    c = [a[i] - b[i] for i in range(n)]
    c1 = [i if i > 0 else 0 for i in c]
    c2 = sum([i if i < 0 else 0 for i in c])
    c3 = sum([1 if i < 0 else 0 for i in c])
    if c2 < 0:
        c1.sort(reverse=True)
        for i in range(n):
            d = d + c1[i]
            if d + c2 > 0:
                res = c3 + i
                break

print(res)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

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

if np.sum(A) < np.sum(B):
  print(-1)
else:
  print( np.sum(A < B))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def solve():
  #checks
  if(sum(A)<sum(B)):
    return -1
  if(check(A)):
    return 0
  for i in range(2,N+1):
    for comb in itertools.combinations(range(N), i):
      for replaced in replace(comb):
        temp = A
        for j in range(i):
          temp[comb[j]] = A[replaced[j]]
        if(check(temp)):
          return sum([not(comb[j] == replaced[j]) for j in range(i)])
  return 0

def check(_A):
  return sum([int(_A[i]>=B[i]) for i in range(N)]) == N

def replace(iter):
  return itertools.permutations(iter, len(iter))

print(str(solve()))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
d=[]
e=[]
dif=0
nsum=0
psum=0
cnt=0


for i in range(n):
  dif=a[i]-b[i]
#  c.append(dif)
  if dif<0:
    d.append(dif)
    nsum+=dif
  elif dif>0:
    e.append(dif)
#c.sort()
d.sort()
e.sort()
#print(nsum)
if abs(nsum)>sum(e):
  print(-1)
else:
  while abs(nsum)>psum:
    i=-1
    psum+=e[i]
    cnt+=1
    i-=1
  print(len(d)+cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

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

c = np.sort(A) > np.sort(B)
if np.sum(c) != N:
  print(-1)
else:
  print( np.sum(A < B))

Submission status: Wrong Answer

Solution 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])
    if max_counter > m_sub_sum:
        print(count)
    elif max_counter == m_sub_sum:
        print(count+1)
    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

Submission status: Wrong Answer

Solution code:
import itertools

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

def solve():
  #checks
  if(sum(A)<sum(B)):
    return -1
  if(check(A)):
    return 0
  for i in range(2,N+1):
    for comb in itertools.combinations(range(N), i):
      for replaced in replace(comb):
        temp = A
        for j in range(i):
          temp[comb[j]] = A[replaced[j]]
        if(check(temp)):
          return sum([not(comb[j] == replaced[j]) for j in range(i)])
  return 0
  
def check(_A):
  return sum([int(_A[i]>=B[i]) for i in range(N)]) == N

def replace(iter):
  return itertools.permutations(iter, len(iter))

print(str(solve()))

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

z = 0
for i in range(N):
    if A[i] >= B[i]:
        z += 1
if z == N:
    print(0)
    exit()


C = [ B[i] for i in range(N)]

p = [0] * N

for i in range(N):
    a = A[i] - C[i]
    if a < 0:
        p[i] = -1
    else:
        p[i] = a

sa = sum(A) - sum(C)
sorted(p,reverse=True)
ans = N
for val in p:
    if val == 0:
        ans -= 1
    elif val == -1:
        continue
    else:
        sa -= val
        if sa >= 0:
            ans -= 1

if sa <= 0:
    print(ans)
else:
    if -1 in p:
        print(ans)
    else:
        print(ans + 1)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

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

c = np.sort(A) > np.sort(B)
if np.sum(c) != N:
  print(-1)
else:
  print("YES")

Submission status: Wrong Answer

Solution 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])
    if max_counter >= m_sub_sum:
        print(count)
    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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
y = 0
for j in range(n):
  if a[j] < b[j]:
    y += 1
if y == 0:
  print("0")

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

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

c = np.sort(A) > np.sort(B)
if np.sum(c) != N:
  print("NO")
else:
  print("YES")

Submission status: Wrong Answer

Solution code:
n = int(input())
now = input().split()
after = input().split()
for i in range(n):
    now[i] = int(now[i])
    after[i] = int(after[i])
lack_list = []
amari2_list = []      
if sum(now) < sum(after):
    print(-1)
else:
    for i in range(n):
        if now[i]<after[i]:
            lack_list.append(after[i]-now[i])
        elif now[i]>after[i]:
            amari2_list.append(now[i]-after[i])
    s1 = sum(lack_list)
    amari2_list.reverse()
    count = 0;t = 0
    while s1 > t:    
        t += amari2_list[count] 
        count += 1 
    ans = len(lack_list)  + count
    print(ans)

Submission status: Wrong Answer

Solution 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 = 1 + len(m_sub) 
    # print(p_sub[0: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