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: Runtime Error

Solution code:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(int argc, char* argv[]) {
  int N;
  cin >> N;

  long long a[N];
  for (int i = 0; i < N; ++i)
    cin >> a[i];

  long long b[N];
  for (int i = 0; i < N; ++i)
    cin >> b[i];

  long long diff_total = 0;
  vector<long long> diff(N);
  bool changed[N];
  for (int i = 0; i < N; ++i) {
    diff_total += a[i] - b[i];
    diff[i] = a[i] - b[i];
    changed[i] = false;
  }

  if (diff_total < 0) {
    cout << -1 << endl;
    return 0;
  }

  sort(diff.begin(), diff.end());

  int last_provider = N - 1;
  int cursor = 0;
  while (true) {
    if (diff[cursor] >= 0)
      break;
    if (abs(diff[last_provider]) > abs(diff[cursor])) {
      diff[last_provider] += diff[cursor];
      diff[cursor] = 0;
      changed[cursor] = true;
      changed[last_provider] = true;
      ++cursor;
    } else {
      diff[cursor] += diff[last_provider];
      diff[last_provider] = 0;
      changed[cursor] = true;
      changed[last_provider] = true;
      if (diff[cursor] == 0)
        ++cursor;
      --last_provider;
    }
  }

  int ret = 0;
  for (int i = 0; i < N; ++i)
    if (changed[i])
      ++ret;

  cout << ret << endl;

  return 0;
}

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(int argc, char* argv[]) {
  int N;
  cin >> N;

  long long a[N];
  for (int i = 0; i < N; ++i)
    cin >> a[i];

  long long b[N];
  for (int i = 0; i < N; ++i)
    cin >> b[i];

  long long diff_total = 0;
  vector<int> indices(N);
  vector<long long> diff(N);
  bool changed[N];
  for (int i = 0; i < N; ++i) {
    diff_total += a[i] - b[i];
    diff[i] = a[i] - b[i];
    indices[i] = i;
    changed[i] = false;
  }

  if (diff_total < 0) {
    cout << -1 << endl;
    return 0;
  }

  sort(diff.begin(), diff.end());

  int last_provider = N - 1;
  int i = 0;
  while (true) {
    if (diff[i] >= 0)
      break;
    if (abs(diff[last_provider]) > abs(diff[i])) {
      diff[last_provider] += diff[i];
      changed[i] = true;
      changed[last_provider] = true;
      ++i;
    } else {
      diff[i] += diff[last_provider];
      diff[last_provider] = 0;
      changed[i] = true;
      changed[last_provider] = true;
      if (diff[i] == 0)
        ++i;
      --last_provider;
    }
  }

  int ret = 0;
  for (int i = 0; i < N; ++i)
    if (changed[i])
      ++ret;

  cout << ret << endl;

  return 0;
}

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
s=0
t=0
u=0
D=[]
for i in range(N):
  if A[i]<B[i]:
    s+=B[i]-A[i] #足りないものを合計する
    u+=1
  elif  A[i]>B[i]:
    D.append(A[i]-B[i])
  else:
    s=s
D=sorted(D,reverse=True)
i=0
while s>=0:
  s=s-D[i]
  i+=1
  t+=1
if s>0:
  print("-1")
elif all(A[i]>=B[i] for i in range(N)):
  print("0")
else:
  print(u+t)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
s=0
t=0
u=0
D=[]
for i in range(N):
  if A[i]<B[i]:
    s+=B[i]-A[i] #足りないものを合計する
    u+=1
  elif  A[i]>B[i]:
    D.append(A[i]-B[i])
  else:
    s=s
D=sorted(D,reverse=True)
while s>=0 for i in range(len(D)):
  s-=D[i]
  t+=1
if s>0:
  print("-1")
elif all(A[i]>=B[i] for i in range(N)):
  print("0")
else:
  print(u+t)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[]
v=0
SUM=0
s=sum(A)
t=sum(B)
if s<t:
  print("-1")
else:
  for i in range(N):
    if A[i]-B[i]<0:
      SUM+=B[i]-A[i]
      v+=1
    elif A[i]-B[i]==0:
      v=v
    else:
      v=v
      C.append(A[i]-B[i])
C=sorted(C,reverse="True")
u=0
while (SUM-C[i]>=0 for i in range(len(C))):
  SUM-=C[i]
  u+=1
print(u+v)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[]
sum=0
SUM=0
s=sum(A)
t=sum(B)
if s<t:
  print("-1")
else:
  for i in range(N):
    if A[i]-B[i]<0:
      SUM+=B[i]-A[i]
      sum+=1
    elif A[i]-B[i]==0:
      sum=sum
    else:
      sum=sum
      C.append(A[i]-B[i])
C=sorted(C,reverse="True")
u=0
while (SUM-C[i]>=0 for i in range(len(C))):
  SUM-=C[i]
  u+=1
print(u+sum)

Submission status: Runtime Error

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

if sum(a) < sum(b):
    print("-1")
    exit()
yobun_sum = []

for i in range(N):
    if a[i] > b[i]:
        yobun_sum.append(a[i]-b[i])

yobun_sum.sort()
yobun_sum.reverse()

yobun_cum_sum=[]
cum_sum=0
for i in yobun_sum:
    cum_sum+=i
    yobun_cum_sum.append(cum_sum)

yobun_ind = 0
lack_num=0
use_first=False

for i in range(N):
    if a[i] < b[i]:
        use_first=True
        lack_num+=1
        lack = abs(a[i] - b[i])
        if yobun_cum_sum[yobun_ind] >= lack: # can pay
            yobun_cum_sum[yobun_ind] -= lack
        else: # can't pay
            yobun_cum_sum[yobun_ind+1] -= lack - yobun_cum_sum[yobun_ind]
            yobun_cum_sum[yobun_ind] =0
            yobun_ind+=1

if use_first:
    yobun_ind+=1

print(yobun_ind+lack_num)

Submission status: Runtime Error

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
a = list(map(int,stdin.readline().rstrip().split()))
b = list(map(int,stdin.readline().rstrip().split()))

pra = []
mai = []
kosuu = 0
for i in range(n):
    if a[i]-b[i] < 0:
        mai.append(b[i]-a[i])
        continue
    elif a[i]-b[i] > 0:
        pra.append(a[i]-b[i])
    kosuu += 1

pra.sort(reverse=True)

if sum(pra) < sum(mai):
    print(-1)
    exit()

if kosuu == n:
    print(0)
    exit()

count = 1
now = 0
while mai:
    if pra[now] < mai[0]:
        count += 1
        now += 1
        continue
    else:
        pra[now] -= mai[0]
        count += 1
    mai.pop(0)
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
plus = []
total_minus = 0
for i in range(n):
    diff = a[i] - b[i]
    if diff >= 0:
        plus.append(diff)
    else:
        total_minus += (-1) * diff
plus.sort(reverse=True)
if total_minus == 0:
    print(0)
elif sum(plus) < total_minus:
    print(-1)
else:
    ans = n - len(plus)
    for i in range(n):
        if total_minus <= 0:
            break
        total_minus -= plus[i]
        ans += 1
print(ans)

Submission status: Runtime Error

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

if len(minus_idx[0]) == 0:
    print(0)
    sys.exit()
if len_plus == 0:
    print(-1)
    sys.exit()
count = 0
while minus<0:
    minus += plus.pop()
    count += 1
    len_plus -= 1
    if len_plus < 0:
        print(-1)
        sys.exit()
print(len(minus_idx[0])+count)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
if sum(b)>sum(a):
    print(-1)
    exit()
d=[0]
ans=chk=0
print(d[1])

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
if sum(b)>sum(a):
    print(-1)
d=[0]
ans=chk=0
print(d[1])

Submission status: Runtime Error

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


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[-1]*N
for i in range(N):
    C[i]=A[i]-B[i]
C.sort()

count=0
num=0
#print(C)

if (sum(C))<0:
    print(-1)
else:
    while C[0]<0:
        count+=1
        print(C)
        num+=C.pop(0)    
        if num<0:
            num+=C.pop(-1)
            count+=1
    print(count)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[-1]*N
for i in range(N):
    C[i]=A[i]-B[i]
C.sort()

count=0
num=0
print(C)
if (sum(C))<0:
    print(-1)
else:
    while C[0]<0:
        count+=1
        num+=C.pop(0)    
        if num<0:
            num+=C.pop(-1)
            count+=1
    print(count)

Submission status: Runtime Error

Solution code:
# Ai>=Bi 出来るならそのままにする
# Ai < Bi 仕方ないので溢れたぶんを使う
# 「変更したAi」の最小値が欲しいので、使うのは余ってるやつが多い順に使ったほうがいい

n = int(input())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))

lack, lack_i = 0, []
extra, extra_i = 0, []
for i in range(n):
    if arr[i] < brr[i]:
        lack += brr[i] - arr[i]
        lack_i.append([i, brr[i] - arr[i], False])
    else:
        extra += arr[i] - brr[i]
        extra_i.append([i, arr[i] - brr[i], False])

if lack > extra:
    print(-1)
    exit()

# 大量に余っているやつから優先的に使う
extra_i = list(sorted(extra_i, key=lambda x: x[1], reverse=True))
ans = 0

l_i = 0
e_i = 0

while True:
    if l_i >= len(lack_i):
        break
    while True:
        if e_i >= len(extra_i):
            print(-1)
            exit()
        if lack_i[l_i][1] <= extra_i[e_i][1]:
            extra_i[e_i][2] = True  # 一回でも使用した
            ans += 1  # 少ないやつを潰したぶん
            extra_i[e_i][1] -= lack_i[l_i][1]
            break
        else:
            extra_i[e_i][2] = True  # 一回でも使用した
            e_i += 1
            lack_i[l_i][1] -= extra_i[e_i][1]
            extra_i[e_i][1] = 0
    l_i += 1

bonus = len(list(filter(lambda x: x[2] == True, extra_i)))
print(ans + bonus)

Submission status: Runtime Error

Solution code:
# Ai>=Bi 出来るならそのままにする
# Ai < Bi 仕方ないので溢れたぶんを使う
# 「変更したAi」の最小値が欲しいので、使うのは余ってるやつが多い順に使ったほうがいい

n = int(input())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))

lack, lack_i = 0, []
extra, extra_i = 0, []
for i in range(n):
    if arr[i] < brr[i]:
        lack += brr[i] - arr[i]
        lack_i.append([i, brr[i] - arr[i], False])
    else:
        extra += arr[i] - brr[i]
        extra_i.append([i, arr[i] - brr[i], False])

if lack > extra:
    print(-1)
    exit()

# 大量に余っているやつから優先的に使う
extra_i = list(sorted(extra_i, key=lambda x: x[1], reverse=True))
ans = 0

l_i = 0
e_i = 0

while True:
    if l_i >= len(lack_i):
        break
    while True:
        if e_i > len(extra_i):
            print(-1)
            exit()
        if lack_i[l_i][1] <= extra_i[e_i][1]:
            extra_i[e_i][2] = True  # 一回でも使用した
            ans += 1  # 少ないやつを潰したぶん
            extra_i[e_i][1] -= lack_i[l_i][1]
            break
        else:
            extra_i[e_i][2] = True  # 一回でも使用した
            e_i += 1
            lack_i[l_i][1] -= extra_i[e_i][1]
            extra_i[e_i][1] = 0
    l_i += 1

bonus = len(list(filter(lambda x: x[2] == True, extra_i)))
print(ans + bonus)

Submission status: Runtime Error

Solution code:
# Ai>=Bi 出来るならそのままにする
# Ai < Bi 仕方ないので溢れたぶんを使う
# 「変更したAi」の最小値が欲しいので、使うのは余ってるやつが多い順に使ったほうがいい

n = int(input())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))

lack, lack_i = 0, []
extra, extra_i = 0, []
for i in range(n):
    if arr[i] < brr[i]:
        lack += brr[i] - arr[i]
        lack_i.append([i, brr[i] - arr[i]])
    else:
        extra += arr[i] - brr[i]
        extra_i.append([i, arr[i] - brr[i], False])

if lack > extra:
    print(-1)
    exit()

# 大量に余っているやつから優先的に使う
extra_i = list(sorted(extra_i, key=lambda x: x[1], reverse=True))
ans = 0

l_i = 0
e_i = 0

while True:
    if l_i >= len(lack_i):
        break
    while True:
        if lack_i[l_i][1] <= extra_i[e_i][1]:
            extra_i[e_i][2] = True  # 一回でも使用した
            ans += 1  #
            extra_i[e_i][1] -= lack_i[l_i][1]
            break
        else:
            extra_i[e_i][2] = True  # 一回でも使用した
            e_i += 1
            lack_i[l_i][1] -= extra_i[e_i][1]
            extra_i[e_i][1] = 0
        if e_i > len(extra_i):
            print(-1)
            exit()
            break  # ここにくるときがよくわからんけど
    l_i += 1

bonus = len(list(filter(lambda x: x[2] == True, extra_i)))
print(ans + bonus)

Submission status: Runtime Error

Solution code:
# Ai>=Bi 出来るならそのままにする
# Ai < Bi 仕方ないので溢れたぶんを使う
# 「変更したAi」の最小値が欲しいので、使うのは余ってるやつが多い順に使ったほうがいい

n = int(input())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))

lack, lack_i = 0, []
extra, extra_i = 0, []
for i in range(n):
    if arr[i] < brr[i]:
        lack += brr[i] - arr[i]
        lack_i.append([i, brr[i] - arr[i]])
    else:
        extra += arr[i] - brr[i]
        extra_i.append([i, arr[i] - brr[i], False])

if lack > extra:
    print(-1)
    exit()

# 大量に余っているやつから優先的に使う
extra_i = list(sorted(extra_i, key=lambda x: x[1], reverse=True))
ans = 0

l_i = 0
e_i = 0

while True:
    if l_i >= len(lack_i):
        break
    while True:
        if lack_i[l_i][1] <= extra_i[e_i][1]:
            extra_i[e_i][2] = True  # 一回でも使用した
            ans += 1  #
            extra_i[e_i][1] -= lack_i[l_i][1]
            break
        else:
            extra_i[e_i][2] = True  # 一回でも使用した
            e_i += 1
            lack_i[l_i][1] -= extra_i[e_i][1]
            extra_i[e_i][1] = 0
        if e_i > len(extra_i):
            break  # ここにくるときがよくわからんけど
    l_i += 1

bonus = len(list(filter(lambda x: x[2] == True, extra_i)))
print(ans + bonus)

Submission status: Runtime Error

Solution code:
N=int(input())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))

ablist=[]
for i in range(N):
  ablist.append(alist[i]-blist[i])
  
ablist.sort()
#print(ablist)

if ablist[0] >= 0:
  print("0")
elif sum(ablist) < 0:
  print("-1")
else:
  cnt = 0
  sum_ab = 0
  for ab in ablist:
    if ab<0:
      cnt += 1
      sum_ab += ab
    else:
      break
      
  for ab in reversed(ablist):
    cnt += 1
    sum_ab += ab
    if sum_ab >= 0:
      break
      
print(cnt)

Submission status: Runtime Error

Solution code:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912 2の29乗
const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int N;
ll a[100001],b[100001];
void init(int a[100001]){
    for(int i = 0; i < 100001; i++){
        a[i] = MM;
    }
}
vector<ll> v(0);
ll cnt = 0;
int main(){
    cin >> N;
    ll sum = 0;
    ll sum_up = 0;
    for(int i = 0; i < N; i++) cin >> a[i];
    for(int i = 0; i < N; i++) cin >> b[i];
    for(int i = 0; i < N; i++){
        sum += (a[i]-b[i]);
        if(a[i] >= b[i]){
            sum_up++;
        }
        if(a[i] < b[i]){
            cnt++;
        }
    }
    if(sum < 0 || sum_up < N/2){
        cout << -1 << endl;
        return 0;
    }
    cout << cnt << endl;
}

Submission status: Runtime Error

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(N + 1):
        if surplus[i] >= need:
            print(i + short_num)
            exit()

Submission status: Runtime Error

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

diff = []
neg = 0
count = 0

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

for a, b in zip(A, B):
    diff += [a-b]
    if a < b:
        count += 1
        neg += a - b

for d in reverse(diff):
    if neg >= 0:
        break
    count += 1
    neg += d

print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

num_exam = int(raw_input())
current_scores    = map(int, raw_input().split())
exam_boarderlines = map(int, raw_input().split())

margin_scores = []
lack_scores   = []
count_adjusted = 0

if sum(current_scores) < sum(exam_boarderlines):
  print(-1)
  sys.exit()

for i in range(num_exam):
  if current_scores[i] < exam_boarderlines[i]:
    lack_scores.append(current_scores[i] - exam_boarderlines[i])
    count_adjusted += 1
  elif current_scores[i] > exam_boarderlines[i]:
    margin_scores.append(current_scores[i] - exam_boarderlines[i])

desc_sorted_margin_scores = sorted(margin_scores, reverse=True)
total_lack_score = sum(lack_scores)
for i in range(len(desc_sorted_margin_scores)):
  if total_lack_score >= 0:
    break

  total_lack_score += desc_sorted_margin_scores[i]
  count_adjusted += 1

print(count_adjusted)
~

Submission status: Runtime Error

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: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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: Runtime Error

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()
    
    while (sub_List+max(sub_AB)>=0):
        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: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
k = []
j = 0
na= 0
c = 0
if sum(a)<sum(b):
    print(-1)
else:
    for i in range(n):
        if a[i]<b[i]:
            na +=b[i]-a[i]
            c+=1
        elif a[i] > b[i]:
            k.append(a[i]-b[i])
    k.sort()
        k = k[::-1]
    while na > 0:
        na -=k[j]
        c +=1
        j+=1
    print(c)

Submission status: Runtime Error

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))
for n in N:
    A.append(int(input()))
for n in N:
    B.append(int(input()))
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: Runtime Error

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))
for n in N:
    A.append(int(input()))
for n in N:
    B.append(int(input()))
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: Runtime Error

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

Submission status: Runtime Error

Solution code:
num = int(input())
power = [int(x) for x in input().split()]
exam = [int(y) for y in input().split()]
 
lack = 0
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)

Submission status: Runtime Error

Solution code:
num = int(input())
power = [int(x) for x in input().split()]
exam = [int(y) for y in input().split()]

lack = 0
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 -= lack[p]
  p += 1
print(p)

Submission status: Runtime Error

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[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: Runtime Error

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][::-1]
        minlist=[i for i in difsort if i<0]
        minum=len(minlist)
        absum=abs(sum(minlist))
        sumlist=[sum(pluslist[0:i+1]) for i in range(len(pluslist)-1)]
        while sumlist[count]<absum:
            count+=1
        
        print(count+1+minum)

Submission status: Runtime Error

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][::-1]
        minlist=[i for i in difsort if i<0]
        minum=len(minlist)
        absum=abs(sum(minlist))
        sumlist=[sum(maxsort[0:i+1]) for i in range(len(pluslist)-1)]
        while sumlist[count]<absum:
            count+=1
        
        print(count+1+minum)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Cm = []
Cp = []
for i in range(N):
	if(A[i]-B[i]<0):
		Cm.append(A[i]-B[i])
	elif(A[i]-B[i]>0):
		Cp.append(A[i]-B[i])
Cm.sort()
Cp.sort()


if(len(Cm) == 0):
	print(0)
	exit(1)
if(sum(Cp)<abs(sum(Cm))):
	print(-1)
	exit(1)

j=0
i = 0
nowCp = int(Cp[len(Cp)-i-1])


while(j<len(Cm)):
	if(nowCp>=abs(Cm[j])):
		nowCp -= abs(Cm[j])
		j += 1
	elif(nowCp<abs(Cm[j]) and i<len(Cp)):
		i += 1
		nowCp += int(Cp[len(Cp)-i-1])

	else:
		break
	

if(j == len(Cm)):
	print(j+i+1)
else:
	print(-1)