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(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(A)
D = sorted(B)
e = 0
f = 0
for i in range(len(A)):
	C[i] >= D[i]
	e = e + 1
if e == len(A):
	for i in range(len(A)):
		if A[i] != C[i]:
			f = f + 1
	print(f)
else:
	print("-1")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = 0
if sum(a) < sum(b):
    print(-1)
else:
    for i in range(n):
        if a[i] <  b[i]:
            cnt += 1
    print(max(cnt,min(2*cnt-1,n)))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(A)
D = sorted(B)
e = 0
f = 0
for i in range(len(A)):
	C[i] >= D[i]
	e = e + 1
if e == len(A):
	for i in range(len(A)):
		if A[i] != C[i]:
			f = f + 1
	print(f)
else:
	print("0")

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 = 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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(A)
D = sorted(B)
e = 0
f = 0
for i in range(len(A)):
	A[i] >= B[i]
	e = e + 1
if e == len(A):
	for i in range(len(A)):
		if A[i] != C[i]:
			f = f + 1
	print(f)
else:
	print("0")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import sys
n = int(input())
a = list(map(int, input().rstrip().split()))
b = list(map(int, input().rstrip().split()))
if sum(a) < sum(b):
    print(-1)
    sys.exit()
min_i = 0
residue = 0
repos = defaultdict(int)
for i in range(n):
    tmp = a[i] - b[i]
    if tmp < 0:
        min_i += 1
        residue = -tmp
    elif tmp > 0:
        repos[tmp] += 1
repo_keys = sorted(repos.keys(), reverse=True)
while residue > 0:
    k = repo_keys.pop(0)
    v = repos[k]
    if k * v >= residue:
        min_i += int(residue / k) + (residue % k > 0)
        break
    else:
        residue -= k * v
        min_i += v
print(min_i)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = 0
if sum(a) < sum(b):
    print(-1)
else:
    for i in range(n):
        if a[i] <  b[i]:
            cnt += 1
    print(max(cnt,2*cnt-1))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(A)
D = sorted(B)
e = 0
f = 0
for i in range(len(A)):
	A[i] >= B[i]
	e = e + 1
if e == len(A):
	for i in range(len(A)):
		if A[i] != B[i]:
			f = f + 1
	print(e)
else:
	print("-1")

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

Submission status: Wrong Answer

Solution code:
"""
C - Exam and Wizard
"""
import numpy as np

#メイン処理
if __name__ == '__main__':
    #入力
    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)
        exit()

    c = b - a

    #不足リスト
    cm = c[c > 0]
    #print(cm)
    count = cm.size
    #print(count)
    if(count == 0):
        print(0)
        exit()
    point = np.sum(cm)
    #print('point:{0}'.format(point))

    #あまりリスト
    cp = np.sort(c[c < 0])[::-1]
    #print(cp)

    for i in range(cp.size):
        point = point - cp[i]
        count = count + 1
        if(point < 0):
            #終了
            print(count)
            exit()

Submission status: Wrong Answer

Solution code:
import sys

test_num = int(input())
prep = [int(i) for i in input().split()]
gokaku = [int(i) for i in input().split()]
prep_sum = sum(prep)
gokaku_sum = sum(gokaku)

ans = [0 for i in range(test_num)]

# -1
if gokaku_sum > prep_sum:
    print(-1)
    sys.exit()

amari = prep_sum-gokaku_sum

diff = [prep[i]-gokaku[i] for i in range(test_num)]
amari_idx = []
husoku_idx = []
for i, item in enumerate(diff):
    if item < 0:
        husoku_idx.append(i)
    else:
        amari_idx.append(i)

# 0
if len(husoku_idx) == 0:
    print(0)
    sys.exit()

# >0
husoku = [diff[husoku_idx_item] for husoku_idx_item in husoku_idx]
husoku_sum = sum(husoku)
output = len(husoku_idx)
ordered_amari = [diff[amari_idx_item] for amari_idx_item in amari_idx]
ordered_amari.reverse()
ct = len(ordered_amari)
for i in range(ct):
    output += 1
    if sum(ordered_amari[:(i+1)]) > husoku_sum:
        break

print(output)
sys.exit()

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 = list(sub_a_b[sub_a_b>0])  
    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) 
    for i in range(len(p_sub)):
        if max_counter >= m_sub_sum:
            print(count)
            exit()
        else:
            # p_sub = np.delete(p_sub, index((max(p_sub))),0)
            p_sub.pop(p_sub.index(max(p_sub)))
            # print(p_sub)
            max_counter += max(p_sub)
            count += 1

Submission status: Wrong Answer

Solution 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):
            a = sum(diff_p[:j])

            if diff_m - a <= 0:
                print(j+1 + mcount)
                break

            else:
                continue

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
sys.setrecursionlimit(10**8)

def nibutan(r, target): # r:sorted list
    l = len(r)
    if l==2:
        if r[0]<target<=r[1]:
            return 1
        elif r[0]>=target:
            return 0
        else:
            return -2
    if r[0]==target:
        return 0
    elif r[-1]==target:
        return l-1
        
    tmp = l//2
    if r[tmp]<target<=r[tmp+1]:
        return tmp+1
    elif target <= r[tmp]:
        return nibutan(r[:tmp+1], target)
    elif target > r[tmp+1]:
        return tmp+nibutan(r[tmp:], target)


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

x = a-b
negative = x[x<0]
positive = sorted(x[x>0])
negative_sum = -negative.sum()

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

if len(positive)==0:
    print(-1)
    exit()

sub_sum = []
tmp = 0
for i in range(len(positive)):
    tmp += positive[i]
    sub_sum.append(tmp)

#print(positive, negative, sub_sum)

if negative_sum > sub_sum[-1]:
    print(-1)
    exit()
if negative_sum <= sub_sum[0]:
    print(1+len(negative))
    exit()

print(nibutan(sub_sum, negative_sum)+len(negative)-1)

# l = len(positive)
# s = 0
# f = l

# for i in range(l):
#     #print(f,s)
#     tmp = (f+s)//2
#     if sub_sum[max(0,tmp-1)]<negative_sum<=sub_sum[tmp]:
#         print(tmp-1+len(negative))
#         exit()
#     # elif sub_sum[tmp] < negative_sum <= sub_sum[min(tmp+1, l-1)]:
#     #     print(tmp+1+len(negative),tmp)
#     #     exit()
#     elif sub_sum[tmp]>negative_sum:
#         f = min(tmp+1, l)
#     elif sub_sum[tmp]<negative_sum:
#         s = tmp

Submission status: Wrong Answer

Solution code:
import sys

test_num = int(input())
prep = [int(i) for i in input().split()]
gokaku = [int(i) for i in input().split()]
prep_sum = sum(prep)
gokaku_sum = sum(gokaku)

ans = [0 for i in range(test_num)]

# -1
if gokaku_sum > prep_sum:
    print(-1)
    sys.exit()

amari = prep_sum-gokaku_sum

diff = [prep[i]-gokaku[i] for i in range(test_num)]
amari_idx = []
husoku_idx = []
for i, item in enumerate(diff):
    if item < 0:
        husoku_idx.append(i)
    else:
        amari_idx.append(i)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
count=0
if sum(A)<sum(B):
    print(-1)
else:
    dif=[A[i]-B[i] for i in range(N)]
    if min(dif)>=0:
        print(0)
    else:
        difsort=sorted(dif)
        pluslist=[i for i in difsort if i>=0]
        zero=difsort.index(pluslist[0])
        minum=len(difsort[:zero])
        maxsort=difsort[:-1]
        while sum(maxsort[0:count+1])<sum(difsort[:zero]):
            count+=1
        
        print(count+1+minum)

Submission status: Wrong Answer

Solution code:
"""
C - Exam and Wizard
"""
import numpy as np

#メイン処理
if __name__ == '__main__':
    #入力
    n = int(input())
    a = np.array(list(map(int, input().split())))
    b = np.array(list(map(int, input().split())))
    
    c = b - a

    #不足リスト
    cm = c[c > 0]
    #print(cm)
    count = cm.size
    #print(count)
    if(count == 0):
        print(0)
        exit()
    point = np.sum(cm)
    #print('point:{0}'.format(point))

    #あまりリスト
    cp = np.sort(c[c < 0])[::-1]
    #print(cp)

    for i in range(cp.size):
        point = point - cp[i]
        count = count + 1
        if(point < 0):
            #終了
            print(count)
            exit()

    #出力
    print(-1)

Submission status: Wrong Answer

Solution 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

Submission status: Wrong Answer

Solution code:
import sys

s = [input() for i in range(3)] #3回繰り返し s に値を取得
lists = []
for l in s:
  lists.append(list(map(int, l.split())))
print (lists) #出力:['s_1', 's_2', 's_3']
if(sum(lists[1]) > sum(lists[2])):
  print(-1)
  sys.exit()

Submission status: Wrong Answer

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

z = 0
for i in range(N):
    if A[i] >= B[i]:
        z += 1
if z == N:
    print(0)
    exit()
if sum(A) < sum(B):
    print(-1)
    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 = 0
for val in p:
    if sa <= 0:
        break
    if val == -1:
        continue
    elif val == 0:
        ans += 1
        continue

    sa -= val
    if sa >= 0:
        ans += 1

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

Submission status: Wrong Answer

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

if sum(a) < sum(b):
  print(-1)
else:
  k = sum(x < 0 for x in c)
  neg = sum(c[:k])
  
  for i in range(n):
    if k == 0:
      print(0)
    elif sum(c[len(c) - 1 - i:]) >= abs(neg):
      print(k + i + 1)
      break

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c=[x-y for (x, y) in zip(a, b)]
if sum(c)<0:
    print(-1)
else:
    plus=[]
    minus=[]
    for k in range(n):
        if c[k]>0:
            plus.append(c[k])
        elif c[k]<0:
            minus.append(c[k])
    if len(minus)+len(plus)==0:
        print(0)
    plus.sort(reverse=True)
    e=0
    for l in range(len(plus)):
        e+=plus[l]
        if e+sum(minus)>0:
            print(len(minus)+l+1)
            break

Submission status: Wrong Answer

Solution code:
n = int(input())
ali = list(map(int, input().split()))
bli = list(map(int, input().split()))

asum = sum(ali)
bsum = sum(ali)
if asum < bsum:
  print('-1')
  exit()

ng = 0
dif = 0
plus = []

for (a,b) in zip(ali,bli):
  if a < b:
    ng += 1
    dif += (b-a)
  elif a > b:
    plus.append(a-b)
    
if ng == 0:
  print('0')
  exit()
  
if ng >= n-1:
  print(n)
  exit()

plus.sort(reverse=True)

n = 1
for z in plus:
  if z < dif:
    dif -= z
    n += 1
  else:
    break

print(ng+n)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    if sum(A) < sum(B):
        return -1

    d = [0]*N
    for i in range(N):
        d[i] = A[i] - B[i]
    d.sort()
    e = 1
    s = 0
    ans = 0
    amari = 0
    fusoku = d[s]
    while s <= N:
        if fusoku >= 0:
            break
        if amari == 0 and d[-e] > 0:
            amari = d[-e]
            e += 1
            ans += 1
        elif d[-e] < 0:
            break
        if fusoku + amari < 0:
            amari = 0
            fusoku += amari
        else:
            ans += 1
            amari += fusoku
            s += 1
            fusoku = d[s]
    return ans
        

if __name__ == "__main__":
    print(main())

Submission status: Wrong Answer

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

z = 0
for i in range(N):
    if A[i] >= B[i]:
        z += 1
if z == N:
    print(0)
    exit()
if sum(A) < sum(B):
    print(-1)
    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 = 0
for val in p:
    if sa <= 0:
        break
    if val == -1:
        continue
    elif val == 0:
        ans += 1

    sa -= val
    if sa >= 0:
        ans += 1

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
ali = list(map(int, input().split()))
bli = list(map(int, input().split()))

asum = sum(ali)
bsum = sum(ali)
if asum < bsum:
  print('-1')
  exit()

ng = 0
dif = 0
plus = []

for (a,b) in zip(ali,bli):
  if a < b:
    ng += 1
    dif += (b-a)
  else:
    plus.append(a-b)
    
if ng == 0:
  print('0')
  exit()
  
if ng >= n-1:
  print(n)
  exit()

plus.sort(reverse=True)

n = 1
for z in plus:
  if z <= dif:
    dif -= z
    n += 1
  else:
    break

print(ng+n)

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())

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

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

if sum_A < sum_B:
    print(-1)
    exit()


def check(a):
    for i in range(n):
        if a[i] < 0:
            return False
    return True


def countDiff(a, b):
    ret = 0
    for i in range(n):
        if a[i] != b[i]:
            ret += 1
    return ret


ans = 0
diff = (list)(map(lambda x, y: x - y, A, B))
init_diff = copy.deepcopy(diff)

while not check(diff):
    max_val = max(diff)
    max_ind = diff.index(max_val)
    while max_val > 0:
        min_val = min(diff)
        min_ind = diff.index(min_val)
        sub = min_val + max_val
        if sub > 0:
            diff[min_ind] = 0
            diff[max_ind] -= sub
            max_val -= sub
        else:
            diff[min_ind] += max_val
            diff[max_ind] = 0
            max_val = 0
print(countDiff(init_diff, diff))

Submission status: Wrong Answer

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

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 = []
amari_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])
    s1 = sum(lack_list)
    
    for i in range(n):#2-1　余っているやつと必要分の差分を抜き出す、大きい順に並び替え
        if now[i]>after[i]:
            amari2_list.append(now[i]-after[i])
    amari2_list.reverse()
    count = 0
    t = 0
    while s1 > t:    #2-2　差分何個が必要か計算
        t += amari2_list[count] 
        count += 1 
    ans = len(lack_list)  + count
    print(ans)

Submission status: Wrong Answer

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

z = 0
for i in range(N):
    if A[i] >= B[i]:
        z += 1
if z == N:
    print(0)
    exit()
if sum(A) < sum(B):
    print(-1)
    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 = 0
for val in p:
    if sa <= 0:
        break
    if val == -1:
        continue
    elif val == 0:
        ans += 1

    sa -= val
    if sa >= 0:
        ans += 1

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

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    if sum(A) < sum(B):
        return -1

    d = [0]*N
    for i in range(N):
        d[i] = A[i] - B[i]
    d.sort()
    e = 1
    s = 0
    ans = 0
    amari = 0
    fusoku = d[s]
    while s <= N:
        if fusoku >= 0:
            break
        if fusoku + amari < 0:
            amari = 0
            fusoku += amari
        else:
            ans += 1
            amari += fusoku
            s += 1
            fusoku = d[s]
        if fusoku >= 0:
            break
        if amari == 0:
            amari = d[-e]
            e += 1
            ans += 1
    return ans
        

if __name__ == "__main__":
    print(main())

Submission status: Wrong Answer

Solution code:
n = int(input())
score = list(map(int, input().split()))
score_sorted = sorted(score)
target = list(map(int, input().split()))
target_sorted = sorted(target)
sub = list(map(lambda x: score[x] - target[x], range(n)))
sub_sorted = list(map(lambda x: score_sorted[x] - target_sorted[x], range(n)))

score_new =[]
target_new = []
for i in range(n):
    if(sub[i] < 0):
        score_new.append(score[i])
        target_new.append(target[i])
score_new = sorted(score_new)
target_new = sorted(target_new)

n = sum(1 for x in sub if x < 0)
n_sorted = sum(1 for x in sub_sorted if x < 0)

n_new = 0
l = len(target_new)
i = 0
if(n_sorted > 0): print(-1)
else:
    for i in range(l):
        sub_new = list(map(lambda x: score_new[x+i] - target_new[x], range(l)))
        n_new = sum(1 for x in sub_new if x < 0)
        score_new.append(score_sorted[-(i+1)])
        #print(score_new, target_new)
        if(n_new <= 0): break
    print(n + i)

Submission status: Wrong Answer

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

if sum(a) < sum(b):
  print(-1)
else:
  for i in range(n):
    if c[i] >= 0:
      k = i
      break
  neg = sum(c[:k])
  
  for i in range(n):
    if k == 0:
      print(0)
    elif sum(c[len(c) - 1 - i:]) >= abs(neg):
      print(k + i + 1)
      break

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys

N = int(input())
A = [int(s) for s in input().split(' ')]
B = [int(s) for s in input().split(' ')]
cnt = 0
t_diff = 0

if sum(A) < sum(B):
    print(-1)
    sys.exit()
    
for i in range(len(A)):
    if A[i] < B[i]:
        cnt = cnt + 1
        t_diff = t_diff + (B[i] - A[i])

for i in range(len(A)):

    if A[i] > B[i]:
        cnt = cnt + 1
        t_diff = t_diff - (A[i] - B[i])
    
    if t_diff <= 0:
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
ali = list(map(int, input().split()))
bli = list(map(int, input().split()))

asum = sum(ali)
bsum = sum(ali)
if asum < bsum:
  print('-1')
  exit()

ng = 0
dif = 0
plus = []

for (a,b) in zip(ali,bli):
  if a < b:
    ng += 1
    dif += (b-a)
  else:
    plus.append(a-b)
    
if ng == 0:
  print('0')
  exit()
  
if ng >= n-1:
  print(n)
  exit()

plus.sort(reverse=True)

n = 1
for z in plus:
  if z < dif:
    dif -= z
    n += 1
  else:
    break

print(ng+n)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

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

else:
    a_n = np.array(a)
    b_n = np.array(b)

    d = a_n - b_n
    d_min = d[d < 0]
    d_max = np.sort(d[d > 0])[::-1]
    num = len(d_min)
    for i in range(len(d_max)+1):

        if np.sum(d_min) + np.sum(d_max[:i]) > 0:
            print(num + i)
            exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

z = 0
for i in range(N):
    if A[i] >= B[i]:
        z += 1
if z == N:
    print(0)
    exit()
if sum(A) < sum(B):
    print(-1)
    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)
print(p)
ans = 0
for val in p:
    if val == -1:
        continue
    elif val == 0:
        ans += 1

    sa -= val
    if sa >= 0:
        ans += 1
print(N - ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(float, input().split())))
b = np.array(list(map(float, input().split())))

x = a-b
negative = x[x<0]
positive = sorted(x[x>0])
negative_sum = -negative.sum()

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

if len(positive)==0:
    print(-1)
    exit()

sub_sum = []
tmp = 0
for i in range(len(positive)):
    tmp += positive[i]
    sub_sum.append(tmp)

#print(positive, negative, sub_sum)

if negative_sum > sub_sum[-1]:
    print(-1)
    exit()
if negative_sum <= sub_sum[0]:
    print(1+len(negative))
    exit()

l = len(positive)
s = 0
f = l

for i in range(l):
    #print(f,s)
    tmp = (f+s)//2
    if sub_sum[max(0,tmp-1)]<negative_sum<=sub_sum[tmp]:
        print(tmp-1+len(negative))
        exit()
    # elif sub_sum[tmp] < negative_sum <= sub_sum[min(tmp+1, l-1)]:
    #     print(tmp+1+len(negative),tmp)
    #     exit()
    elif sub_sum[tmp]>negative_sum:
        f = min(tmp+1, l)
    elif sub_sum[tmp]<negative_sum:
        s = tmp

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
data = input()
comp_s = ['k', 'e', 'y', 'e', 'n', 'c', 'e']

flag = False
ng_flag = False
count = 0
s_count = 0
for s in data:
    if 1 < count:
        break
        
    if s == comp_s[s_count]:
        s_count += 1
        ng_flag = False
    else:
        if not ng_flag:
            count += 1
            ng_flag = True

if len(comp_s) == s_count and count <= 1:
    flag = True

if flag:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

D = [A[i] - B[i] for i in range(N)]
P = sorted([d for d in D if d >= 0], reverse=True)
M = [d for d in D if d < 0]
M_sum = sum(M)

ans = len(M)
for p in P:
    M_sum += p
    ans += 1
    if M_sum >= 0:
        break
        
if M_sum < 0:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
finalcheck = 0
moji = 'keyence'
for i in range(1,8):
    check = 0;front = False
    for j in range(len(s)-i+1):
        if moji[:i] == s[j:j+i]:
            check = j+i
            if j == 0:front = True
            if i == 7:
                if len(s[:j]) == 0 or len(s[j+i:]) == 0: finalcheck = 1
            break
    if check != 0:
        if front:
            if moji[i:] == s[check:check+len(s)-i]:
                finalcheck = 1
            break
        for j in range(check,len(s)-i+1):
            if moji[i:] == s[j:j+len(s)-i]:
                if check != j:
                    if len(s[j+len(s)-i:]) != 0:
                        continue
                finalcheck = 1
                break
    if finalcheck == 1:break
if finalcheck:print('YES')
else:print('NO')

Submission status: Wrong Answer

Solution 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