Problem:


Score : 500 points

Problem Statement

You are going to eat X red apples and Y green apples.

You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.

Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.

From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.

Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Constraints

1 \leq X \leq A \leq 10^5

1 \leq Y \leq B \leq 10^5

1 \leq C \leq 10^5

1 \leq p_i \leq 10^9

1 \leq q_i \leq 10^9

1 \leq r_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C

Output

Print the maximum possible sum of the deliciousness of the eaten apples.

Sample Input 1

1 2 2 2 1
2 4
5 1
3

Sample Output 1

12

The maximum possible sum of the deliciousness of the eaten apples can be achieved as follows:

Eat the 2-nd red apple.

Eat the 1-st green apple.

Paint the 1-st colorless apple green and eat it.

Sample Input 2

2 2 2 2 2
8 6
9 1
2 1

Sample Output 2

25

Sample Input 3

2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4

Sample Output 3

74



Sample input:
1 2 2 2 1
2 4
5 1
3


Sample output:
12

Submission status: Runtime Error

Solution code:
import sys
#input = sys.stdin.readline
#sys.setrecursionlimit(10**6)

def main():
    x,y,a,b,c = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    p.sort(reverse = True)
    q.sort(reverse=True)
    r.sort(reverse=True)

    p = p[:x]
    q = q[:y]
    p.sort()
    q.sort()
    cnt = 0
    for er in r:
        if p[cnt] > er and q[cnt] >er:
            cnt += 1
        elif p[cnt] < q[cnt]:
            if p[cnt] < er:
                p[cnt] = er
        else:
            if q[cnt] < er:
                q[cnt] = er



    print(sum(p) + sum(q))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
s = []
r.extend( [0 for i in range(x+y)])
p.sort()
q.sort()
r.sort()


for i in range(x):
    if  p[-1]>= r[-1]:
        s.append(p.pop())
    else:
        s.append(r.pop())
    
for i in range(y):
    if  q[-1]>= r[-1]:
        s.append(q.pop())
    else:
        s.append(r.pop())
        
print(sum(s))

Submission status: Runtime Error

Solution code:
X, Y, A, B, C = list(map(int, input().split()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)

P = P[:X]
Q = Q[:Y]

P.sort()
Q.sort()
R.sort(reverse=True)

p_i = 0
q_i = 0

for ri in R:
    if p_i >= len(P) and q_i >= len(Q):
        break
    if ri < P[p_i] and ri < Q[q_i]:
        break

    if p_i >= len(P):
        if ri >= Q[q_i]:
            Q[q_i] = ri
            q_i += 1
    elif q_i >= len(Q):
        if ri >= P[p_i]:
            P[p_i] = ri
            p_i += 1
    elif ri > P[p_i] and ri > Q[q_i]:
        d1 = ri - P[p_i]
        d2 = ri - Q[q_i]
        if d1 > d2:
            P[p_i] = ri
            p_i += 1
        else:
            Q[q_i] = ri
            q_i += 1
    elif ri > P[p_i] and ri < Q[q_i]:
        P[p_i] = ri
        p_i += 1
    else:
        Q[q_i] = ri
        q_i += 1


# print(P, Q)
ans = sum(P) + sum(Q)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

X,Y,A,B,C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort()
q.sort()
r.sort()
m = [X,Y]
ans = 0
while m[0] > 0 or m[1] > 0:
    if m[0] > 0:
        if p[-1] < r[-1]:
            ans += r[-1]
            r.pop()
        else:
            ans += p[-1]
            p.pop()
        m[0] -= 1
    if m[1] > 0:
        if q[-1] < r[-1]:
            ans += r[-1]
            r.pop()
        else:
            ans += q[-1]
            q.pop()
        m[1] -= 1
print(ans)

Submission status: Runtime Error

Solution code:
X, Y, A, B, C = list(map(int, input().split()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)

P = P[:X]
Q = Q[:Y]

P.sort()
Q.sort()
R.sort(reverse=True)

p_i = 0
q_i = 0

for ri in R:
    if ri < P[p_i] and ri < Q[q_i]:
        break
    elif ri > P[p_i] and ri > Q[q_i]:
        d1 = ri - P[p_i]
        d2 = ri - Q[q_i]
        if d1 > d2:
            P[p_i] = ri
            p_i += 1
        else:
            Q[q_i] = ri
            q_i += 1
    elif ri > P[p_i] and ri < Q[q_i]:
        P[p_i] = ri
        p_i += 1
    else:
        Q[q_i] = ri
        q_i += 1


# print(P, Q)
ans = sum(P) + sum(Q)
print(ans)

Submission status: Runtime Error

Solution code:
X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))

p=sorted(p,reverse=True)
q=sorted(q,reverse=True)
r=sorted(r,reverse=True)
answer=p[:X]+q[:Y]
sum=0
answer=sorted(answer,reverse=True)
i=0

while answer[-i-1]<r[i]:
    answer[-i-1]=r[i]
    i+=1

for a in answer:
    sum+=a

print(sum)

Submission status: Runtime Error

Solution code:
スコード 

Copy
Copy
def main():
  X, Y, A, B, C  = map(int, input().split())
  aka_list = sorted([int(t) for t in input().split()],reverse=True)[:X]
  midori_list = sorted([int(t) for t in input().split()],reverse=True)[:Y]
  mu_list = sorted([int(t) for t in input().split()],reverse=True)
  
  sum_list = sorted(aka_list + midori_list + mu_list)[:X+Y]
  print(sum(sum_list))

Submission status: Runtime Error

Solution code:
from collections import deque

X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p = deque(p)
q = deque(q)
r = deque(r)
ans = 0
carry = 0

while X or Y or carry:
  if X and Y:
    if p[0]>=q[0] and p[0]>=r[0]:
      X -= 1
      ans += p.popleft()
    elif q[0]>=p[0] and q[0]>=r[0]:
      Y -= 1
      ans += q.popleft()
    elif r[0]>=p[0] and r[0]>=q[0]:
      ans += r.popleft()
      X -= 1
      Y -= 1
      carry += 1
  elif X:
    if carry:
      if p[0]>=q[0] and p[0]>=r[0]:
        X -= 1
        ans += p.popleft()
      elif q[0]>=p[0] and q[0]>=r[0]:
        carry -= 1
        ans += q.popleft()
      elif r[0]>=p[0] and r[0]>=q[0]:
        ans += r.popleft()
        X -= 1
    else:
      if p[0]>=r[0]:
        X -= 1
        ans += p.popleft()
      elif r[0]>=p[0]:
        ans += r.popleft()
        X -= 1
  elif Y:
    if carry:
      if p[0]>=q[0] and p[0]>=r[0]:
        carry -= 1
        ans += p.popleft()
      elif q[0]>=p[0] and q[0]>=r[0]:
        Y -= 1
        ans += q.popleft()
      elif r[0]>=p[0] and r[0]>=q[0]:
        ans += r.popleft()
        Y -= 1
    else:
      if q[0]>=r[0]:
        Y -= 1
        ans += p.popleft()
      elif r[0]>=q[0]:
        ans += r.popleft()
        Y -= 1
  elif carry:
    if p[0]>=q[0] and p[0]>=r[0]:
      carry -= 1
      ans += p.popleft()
    elif q[0]>=p[0] and q[0]>=r[0]:
      carry -= 1
      ans += q.popleft()
    elif r[0]>=p[0] and r[0]>=q[0]:
      ans += r.popleft()
      carry -= 1

print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque

X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p = deque(p)
q = deque(q)
r = deque(r)
ans = 0
carry = 0

while X or Y or carry:
  print("a")
  if X and Y:
    if p[0]>=q[0] and p[0]>=r[0]:
      X -= 1
      ans += p.popleft()
    elif q[0]>=p[0] and q[0]>=r[0]:
      Y -= 1
      ans += q.popleft()
    elif r[0]>=p[0] and r[0]>=q[0]:
      ans += r.popleft()
      X -= 1
      Y -= 1
      carry += 1
  elif X:
    if carry:
      if p[0]>=q[0] and p[0]>=r[0]:
        X -= 1
        ans += p.popleft()
      elif q[0]>=p[0] and q[0]>=r[0]:
        carry -= 1
        ans += q.popleft()
      elif r[0]>=p[0] and r[0]>=q[0]:
        ans += r.popleft()
        X -= 1
    else:
      if p[0]>=r[0]:
        X -= 1
        ans += p.popleft()
      elif r[0]>=p[0]:
        ans += r.popleft()
        X -= 1
  elif Y:
    if carry:
      if p[0]>=q[0] and p[0]>=r[0]:
        carry -= 1
        ans += p.popleft()
      elif q[0]>=p[0] and q[0]>=r[0]:
        Y -= 1
        ans += q.popleft()
      elif r[0]>=p[0] and r[0]>=q[0]:
        ans += r.popleft()
        Y -= 1
    else:
      if q[0]>=r[0]:
        Y -= 1
        ans += p.popleft()
      elif r[0]>=q[0]:
        ans += r.popleft()
        Y -= 1
  elif carry:
    if p[0]>=q[0] and p[0]>=r[0]:
      carry -= 1
      ans += p.popleft()
    elif q[0]>=p[0] and q[0]>=r[0]:
      carry -= 1
      ans += q.popleft()
    elif r[0]>=p[0] and r[0]>=q[0]:
      ans += r.popleft()
      carry -= 1

print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
X,Y,A,B,C = [int(x) for x in stdin.readline().rstrip().split()]
P = [int(x) for x in stdin.readline().rstrip().split()]
Q = [int(x) for x in stdin.readline().rstrip().split()]
R = [int(x) for x in stdin.readline().rstrip().split()]

P.sort()
Q.sort()
R.sort()

P = [0]*(10**5) + P[A-X:]
Q = [0]*(10**5) + Q[B-Y:]
R = [0]*(10**5) + R

ans = 0
while True:
    if P[-1] > Q[-1]:
        if P[-1] > R[-1]:
            ans += P.pop()
        else:
            ans += R.pop()
        X -= 1
    else:
        if Q[-1] > R[-1]:
            ans += Q.pop()
        else:
            ans += R.pop()
        Y -= 1
    if X == 0 and Y == 0:
        break
print(ans)

Submission status: Runtime Error

Solution code:
x, y, A, B, C = map(int, input().split(' '))

a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

a = a[:x]
b = b[:y]

a_index = -1
b_index = -1

a_sum = sum(a)
b_sum = sum(b)

a_target = a[a_index]
b_target = b[b_index]

for i in c:
  if a_target > i and b_target > i:
    # もうりんごの更新はされない
    break
    
  if a_target > b_target:
    b_index -= 1
    b_sum -= b_target
    b_target = b[b_index]
    b_sum += i
  else:
    a_index -= 1
    a_sum -= a_target
    a_target = a[a_index]
    a_sum += i
    
print(a_sum + b_sum)

Submission status: Runtime Error

Solution code:
from collections import deque
x,y,a,b,c = map(int,input().split())

p = deque(sorted(list(map(int,input().split()))))
q = deque(sorted(list(map(int,input().split()))))
r = deque(sorted(list(map(int,input().split()))))

ans = deque(maxlen=(x+y))

def insertion(z):
	global x,y
	if z == p:
		x -= 1
	else:
		y -= 1
	return ans.append(z.pop())

while x > 0 or y > 0:
	if x and y:
		if p[-1] > q[-1] :
			insertion(p)
		else:
			insertion(q)
	elif not x:
		insertion(q)
	else:
		insertion(p)


while ans[-1] < r[-1]:
		ans.pop()
		ans.appendleft(r.pop())

print(sum(ans))

Submission status: Runtime Error

Solution code:
X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p=[:X]
q=[:Y]
r=[:max(X,Y)]
p.sort()
q.sort()
p.reverse()
q.reverse()
 
a=p[:]
a.extend(q)
a.extend(r)
a.sort()
a.reverse()
b=q[:]
b.extend(r)
b.sort()
b.reverse()
c=p[:]
c.extend(r)
c.sort()
c.reverse()
red=0
green=0
sum=0
sum1=0
sum2=0
d=0
for i in range(X+Y):
  if(a[i] in p):
    red+=1
  elif(a[i] in q):
    green+=1
  d+=a[i]
 
  if(i<X):
      sum1+=p[i]
      sum2+=c[i]
  if(i<Y):
      sum1+=b[i]
      sum2+=q[i]
    
if(red<=X and green<=Y):
  print(d)
elif(red>X):
  print(sum1)
elif(green>Y):
  print(sum2)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

from collections import deque

X,Y,A,B,C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P = sorted(P, reverse=True)[:X]
Q = sorted(Q, reverse=True)[:Y]
R = sorted(P+Q+R, reverse=True)[:X+Y]

print(sum(R)

Submission status: Runtime Error

Solution code:
X, Y, A, B, C = [int(i) for i in input().split()]
reds = sorted([int(i) for i in input().split()], reverse=True)
greens = sorted([int(i) for i in input().split()], reverse=True)
clears = sorted([int(i) for i in input().split()], reverse=True)

clear_acc = [0]

for i in clears:
    clear_acc.append(rr[-1]+i)
        
reds = reds[:X]
greens = greens[:Y]

all_apples = sorted(reds+greens)

apple_sum = [sum(all_apples)]


for i in all_apples:
    apple_sum.append(apple_sum[-1]-i)
    

output = []

for i in range(min(X+Y, C+1)):
    output.append(apple_sum[i] + clear_acc[i])

print(max(output))

Submission status: Runtime Error

Solution code:
x, y, a, b, c = map(int, input().split())
arrayP = list(map(int, input().split()))
arrayQ = list(map(int, input().split()))
arrayR = list(map(int, input().split()))
arrayP.sort(reverse=True)
arrayQ.sort(reverse=True)
arrayR.sort(reverse=True)
arrayAns = []
for i in range(x):
    arrayAns.append(int(arrayP[i]))
for i in range(y):
    arrayAns.append(int(arrayQ[i]))
arrayAns.sort()
for i in range(len(arrayR)):
    if arrayAns[i] <= int(arrayR[i]):
        arrayAns[i] = int(arrayR[i])
    else:
        break
print(sum(arrayAns))

Submission status: Runtime Error

Solution code:
x, y, a, b, c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort()
q.sort()
r.sort()
ans = 0
n = x+y
ma = [-1, -1, -1]
for i in range(n):
    if p:
        ma[0] = p[-1]
    if q:
        ma[1] = q[-1]
    if r:
        ma[2] = r[-1]

    if ma.index(max(ma)) == 0:
        if x:
            x -= 1
            ans += p[-1]
            p.pop()
        else:
            if r:
                if q:
                    if r[-1] > q[-1]:
                        y -= 1
                        ans += r[-1]
                        r.pop()
                    else:
                        y -= 1
                        ans += q[-1]
                        q.pop()
                else:
                    y -= 1
                    ans += r[-1]
                    r.pop()
            else:
                y -= 1
                ans += q[-1]
                q.pop()
    elif ma.index(max(ma)) == 1:
        if y:
            y -= 1
            ans += q[-1]
            q.pop()
        else:
            if r:
                if p:
                    if r[-1] > p[-1]:
                        x -= 1
                        ans += r[-1]
                        r.pop()
                    else:
                        x -= 1
                        ans += p[-1]
                        p.pop()
                else:
                    x -= 1
                    ans += r[-1]
                    r.pop()
            else:
                x -= 1
                ans += p[-1]
                p.pop()
    else:
        if p[-1] > q[-1]:
            if y:
                y -= 1
            else:
                x -= 1
        else:
            if x:
                x -= 1
            else:
                y -= 1
        ans += r[-1]
        r.pop()
print(ans)

Submission status: Runtime Error

Solution code:
x, y, a, b, c = map(int, input().split())
arrayP = list(map(int, input().split()))
arrayQ = list(map(int, input().split()))
arrayR = list(map(int, input().split()))
arrayP.sort(reverse=True)
arrayQ.sort(reverse=True)
arrayR.sort(reverse=True)
arrayAns = []
for i in range(x):
    arrayAns.append(int(arrayP[i]))
for i in range(y):
    arrayAns.append(int(arrayQ[i]))
arrayAns.sort()
for i in range(len(arrayAns)):
    if arrayAns[i] <= int(arrayR[i]):
        arrayAns[i] = int(arrayR[i])
    else:
        break
print(sum(arrayAns))

Submission status: Runtime Error

Solution code:
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
tmp = 0
p.sort(reverse=True)
p.append(0)
q.sort(reverse=True)
q.append(0)
r.sort(reverse=True)
r.append(0)
z = X+Y
e, f, g = 0, 0, 0
for i in range(z):
    if X>0 and ((p[e]>=q[f] and p[e]>=r[f]) or (Y==0 and p[e]>=r[g])):
        tmp = tmp+p[e]
        e += 1
        X -= 1
    elif Y>0 and ((q[f]>=p[e] and q[f]>=r[g]) or (X==0 and q[f]>=r[g])):
        tmp = tmp+q[f]
        f += 1
        Y -= 1
    elif r[g]>p[e] or r[g]>q[f]:
        tmp = tmp+r[g]
        g += 1
        
print(tmp)

Submission status: Runtime Error

Solution code:
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

px = p[:X]
qy = q[:Y]
print(qy)
while r and min(px[-1], qy[1]) < r[0]:
  px.sort(reverse=True)
  qy.sort(reverse=True)
  if px[-1] < qy[-1]:
    px[-1] = r[0]
    r.pop(0)
  else:
    qy[-1] = r[0]
    r.pop(0)

print(sum(px) + sum(qy))

Submission status: Runtime Error

Solution code:
mod = 10**9 + 7

def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <=0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n-r+1, n+1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r+1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        #print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

#####################################################ライブラリ集ここまで

def main():
    X, Y, A, B, C = iip()
    p = iip(listed=True)
    p.extend([0 for i in range(10**6)])
    q = iip(listed=True)
    q.extend([0 for i in range(10**6)])
    r = iip(listed=True)

    p.sort(reverse=True)
    q.sort(reverse=True)
    r.sort(reverse=True)

    red = p[:X]
    blue = q[:Y]
    red.sort()
    blue.sort()

    ir = 0
    ib = 0
    for nocolor in r:
        if min(red[ir], blue[ib]) < nocolor:
            if red[ir] < blue[ib]:
                red[ir] = nocolor
                if ir <= len(red)-2:
                    ir += 1
            else:
                blue[ib] = nocolor
                if ir <= len(blue)-2:
                    ib +=1
        else:
            break

    print(sum(red)+sum(blue))



    pass

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
x,y,a,b,c  = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]
p = sorted(p,reverse=True)
q = sorted(q,reverse=True)
r = sorted(r,reverse=True)
chk = p[:x]+q[:y]
chk = sorted(chk,reverse=True)
for i in range(c):
  if r[i] > chk[-1+i]:
    chk[-1+i] = r[i] 
print(sum(chk))

Submission status: Runtime Error

Solution code:
from sys import stdin
X,Y,A,B,C = [int(x) for x in stdin.readline().rstrip().split()]
P = [int(x) for x in stdin.readline().rstrip().split()]
Q = [int(x) for x in stdin.readline().rstrip().split()]
R = [int(x) for x in stdin.readline().rstrip().split()]

P.sort()
Q.sort()
R.sort()

P = P[A-X:]
Q = Q[B-Y:]

ans = 0

while True:
    if X > 0 and Y > 0:
        if P[-1] > Q[-1]:
            if P[-1] > R[-1]:
                ans += P.pop()
                X -= 1
            else:
                ans += R.pop()
        else:
            if Q[-1] > R[-1]:
                ans += Q.pop()
                Y -= 1
            else:
                ans += R.pop()
    elif X > 0 and Y == 0 and R:
        X -= 1
        if P[-1] < R[-1]:
            ans += R.pop()
        else:
            ans += P.pop()
    elif X == 0 and Y > 0 and R:
        Y -= 1
        if Q[-1] < R[-1]:
            ans += R.pop()
        else:
            ans += Q.pop()
    else:
        break
print(ans)

Submission status: Runtime Error

Solution code:
import sys
from collections import deque
readline = sys.stdin.readline

def main():
  x,y,a,b,c=map(int,readline().split())

  red=[int(i) for i in readline().split()]
  green=[int(i) for i in readline().split()]
  nc=sorted([int(i) for i in readline().split()], reverse=1)
  if a<x:
    red+=nc[:(x-a)]
    nc=nc[(x-a):]
  if b<y:
    green+=nc[:(y-b)]
    nc=nc[(y-b):]
  red=deque(sorted(red)[-x:])
  green=deque(sorted(green)[-y:])
  res=0
  for i in nc:
    tr=red[0]
    tg=green[0]
    if tr<tg:
      if i>tr:
        red.popleft()
        res+=i
    else:
      if i>tg:
        green.popleft()
        res+=i
  print(res+sum(red)+sum(green))

main()

Submission status: Runtime Error

Solution code:
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p = p.sort(reverse=True)
q = q.sort(reverse=True)
r = r.sort(reverse=True)
p = p[:X]
q = q[:Y]
sumlist = list()
sumlist.extend(p)
sumlist.extend(q)
sumlist.extend(r)
sumlist = sumlist.sort(reverse=True)
print(sum(sumlist[:X+Y]))

Submission status: Runtime Error

Solution code:
mod = 10**9 + 7

def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <=0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n-r+1, n+1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r+1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        #print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

#####################################################ライブラリ集ここまで

def main():
    X, Y, A, B, C = iip()
    p = iip(listed=True)
    p.extend([0 for i in range(X)])
    q = iip(listed=True)
    q.extend([0 for i in range(Y)])
    r = iip(listed=True)

    p.sort(reverse=True)
    q.sort(reverse=True)
    r.sort(reverse=True)

    red = p[:X]
    blue = q[:Y]
    red.sort()
    blue.sort()

    ir = 0
    ib = 0
    for nocolor in r:
        if min(red[ir], blue[ib]) < nocolor:
            if red[ir] < blue[ib]:
                red[ir] = nocolor
                if ir <= len(red)-2:
                    ir += 1
            else:
                blue[ib] = nocolor
                if ir <= len(blue)-2:
                    ib +=1
        else:
            break

    print(sum(red)+sum(blue))



    pass

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
X, Y, A, B, C = map(int,input().split())
Reds = list(map(int, input().split()))
Greens = list(map(int, input().split()))
Ns = list(map(int, input().split()))

Reds = np.array(Reds)
Greens = np.array(Greens)
Ns = np.array(Ns)

Reds = np.sort(Reds)[:X-1:-1]
Greens = np.sort(Greens)[:Y-1:-1]
Ns = np.sort(Ns)[::-1]

Full = np.append(Reds, Greens)
Full = np.append(Full, Ns)
Full = np.sort(Full)[::-1]

sum = 0

for i in range(X+Y):
    sum += Full[i]

print(sum)

Submission status: Runtime Error

Solution code:
mod = 10**9 + 7

def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <=0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n-r+1, n+1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r+1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        #print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

#####################################################ライブラリ集ここまで

def main():
    X, Y, A, B, C = iip()
    p = iip(listed=True).extend([0 for i in range(X)])
    q = iip(listed=True).extend([0 for i in range(Y)])
    r = iip(listed=True)

    p.sort(reverse=True)
    q.sort(reverse=True)
    r.sort(reverse=True)

    red = p[:X]
    blue = q[:Y]
    red.sort()
    blue.sort()

    ir = 0
    ib = 0
    for nocolor in r:
        if min(red[ir], blue[ib]) < nocolor:
            if red[ir] < blue[ib]:
                red[ir] = nocolor
                if ir <= len(red)-2:
                    ir += 1
            else:
                blue[ib] = nocolor
                if ir <= len(blue)-2:
                    ib +=1
        else:
            break

    print(sum(red)+sum(blue))



    pass

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
val = input().split(' ')
x = int(val[0])
y = int(val[1])
a = int(val[2])
b = int(val[3])
c = int(val[4])

p_list = sorted([int(a) for a in input().split(' ')]).reverse()
q_list = sorted([int(a) for a in input().split(' ')]).reverse()
r_list = sorted([int(a) for a in input().split(' ')]).reverse()

xapples = p_list[0:x+1]
yapples = q_list[0:y+1]
zapples = r_list[0:x+y+1]

apples = sorted(xapples.extend(yapples).extend(zapples)).reverse()[0:x+y+1]
print(sum(apples))

Submission status: Runtime Error

Solution code:
mod = 10**9 + 7

def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <=0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n-r+1, n+1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r+1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        #print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

#####################################################ライブラリ集ここまで

def main():
    X, Y, A, B, C = iip()
    p = iip(listed=True)
    q = iip(listed=True)
    r = iip(listed=True)

    p.sort(reverse=True)
    q.sort(reverse=True)
    r.sort(reverse=True)

    red = p[:X]
    blue = q[:Y]
    red.sort()
    blue.sort()

    ir = 0
    ib = 0
    for nocolor in r:
        if min(red[ir], blue[ib]) < nocolor:
            if red[ir] < blue[ib]:
                red[ir] = nocolor
                if ir <= len(red)-2:
                    ir += 1
            else:
                blue[ib] = nocolor
                if ir <= len(blue)-2:
                    ib +=1
        else:
            break

    print(sum(red)+sum(blue))



    pass

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
mod = 10**9 + 7

def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <=0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n-r+1, n+1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r+1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        #print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

#####################################################ライブラリ集ここまで

def main():
    X, Y, A, B, C = iip()
    p = iip(listed=True)
    q = iip(listed=True)
    r = iip(listed=True)

    p.sort(reverse=True)
    q.sort(reverse=True)
    r.sort(reverse=True)

    red = p[:X]
    blue = q[:Y]
    red.sort()
    blue.sort()

    ir = 0
    ib = 0
    for nocolor in r:
        if min(red[ir], blue[ib]) < nocolor:
            if red[ir] < blue[ib]:
                red[ir] = nocolor
                if ir < len(red)-2:
                    ir += 1
            else:
                blue[ib] = nocolor
                if ir < len(red)-2:
                    ib +=1
        else:
            break

    print(sum(red)+sum(blue))



    pass

if __name__ == "__main__":
    main()