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:
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()))
zen = []

for i in range(a):
    zen.append((P[i],'P'))
for i in range(b):
    zen.append((Q[i],'Q'))
for i in range(c):
    zen.append((R[i],'R'))
zen = sorted(zen,reverse=True)

i=0
ans = 0
red = 0
green = 0
white = 0
while red+green+white!=a+b:
    aji,color = zen[i]
    if red<=a and green <=b:
        if color == 'P':
            red+=1
        elif color =='Q'
            green+=1
        else:
            white+=1
        ans += aji
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int(): return int(input())

def map_int_input(): return map(int, input())

MII = map_int_input

def MII_split(): return map(int, input().split())

def MII_to_index(): return map(to_index, input())

def MII_split_to_index(): return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs(): return list(map(int, input()))

LII = list_int_inputs

def LII_split(): return list(map(int, input().split()))

# 2次元リスト化
def LII_2D(rows_number): return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number): return [LII_split() for _ in range(rows_number)]

X, Y, A, B, C = MII_split()
p_list = LII_split()
q_list = LII_split()
r_list = LII_split()

prices = p_list + q_list + r_list
prices = prices.sort()
print(sum(prices[0:X + Y]))

Submission status: Runtime Error

Solution code:
x,y,a,b,c = (int(x) for x in input().split())
list_p = list(map(int,input().split()))
list_q = list(map(int,input().split()))
list_r = list(map(int,input().split()))
list_p.reverse()
list_q.reverse()
list_r.reverse()
list_total =[]
for i in range(x):
    list_total.append(list_p[i])
for i in range(y):
    list_total.append(list_q[i])
list_total.sort()
for i in range(c):
    if list_r[len(list_r)]>list_total[0]:
        list_total[0]=list_r[0]
        list_total.sort()
        list_r.pop(0)
print(sum(list_total))

Submission status: Runtime Error

Solution code:
X, Y, num_red_apple, num_green_apple, num_apple = map(int, input().strip().split())
red_apples = list(map(int, input().strip().split()))
green_apples = list(map(int, input().strip().split()))
apples = list(map(int, input().strip().split()))

good_apples = []
for i in range(1, X+1):
    good_apples.append(sorted(red_apples)[-i])

for i in range(1, Y+1):
    good_apples.append(sorted(green_apples)[-i])
    
print(good_apples)

while(1):
    if max(apples) > min(good_apples):
        good_apple = apples.pop(apples.index(max(apples)))
        good_apples.remove(min(good_apples))
        good_apples.append(good_apple)
    else:
        break

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

goukei = X + Y
delicious = 0
red = 0
green = 0


def max_pop(p):
    pidx = p.index(max(p))
    maxp = p.pop(pidx)
    return maxp


maxp = max_pop(p)
maxq = max_pop(q)
maxr = max_pop(r)
maxdelis = [maxp, maxq, maxr]
for i in range(goukei):
    maxdeli = max(maxdelis)
    idx = maxdelis.index(max(maxdelis))
    delicious += maxdeli
    if idx == 0:
        red += 1
        if red == X:
            maxdelis[0] = 0
        else:
            maxdelis[0] = max_pop(p)
    elif idx == 1:
        green += 1
        if green == X:
            maxdelis[1] = 0
        else:
            maxdelis[1] = max_pop(q)
    else:
        maxdelis[2] = max_pop(r)

print(delicious)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
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 = sum(p[-x:])+sum(q[-y:])
x_pos = -x
y_pos = -y
for i in range(c):
    #したから見ていく
    if min(p[x_pos],q[y_pos]) >= r[i]:
        continue
    elif p[x_pos] > q[y_pos]:
        ans += r[i] - q[y_pos]
        y_pos -= 1
    else:
        ans += r[i] - p[x_pos]
        x_pos -= 1
    if x_pos == -a:
        p.insert(0,10**5)
        x_pos -= 1
    if y_pos == -b:
        q.insert(0,10**5)
        y_pos -=1
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.sort()
q.sort()
r.sort()
pcount=0
qcount=0
rcount=0
ans=[]
for i in range(x):
  ans.append(p[-1-i])
for i in range(y):
  ans.append(q[-1-i])
ans.sort()
for i in ragne(r):
  if ans[i]<=r[-1-rcount]:
    ans[i]=r[-1-rcount]
    rcount+=1
print(sum(ans))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 28 22:06:13 2020

@author: Kanaru Sato
"""

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 = []
Q = []
R = []

for i in range(a):
    P.append([P_[i],1])
for i in range(b):
    Q.append([Q_[i],2])
for i in range(c):
    R.append([R_[i],3])

p = P+R
p.sort(reverse=True, key=lambda x: x[0])
q = Q+R
q.sort(reverse=True, key=lambda x: x[0])
##########
pr = 0
for i in range(x):
    if p[i][1] == 3:
        pr += 1

qr = 0
for i in range(y):
    if q[i][1] == 3:
        qr += 1
        
n = min(pr,qr)

############

prest = p[x:len(p)+1]
qrest = q[y:len(q)+1]
rest = prest+qrest
rest.sort(reverse=True, key=lambda x: x[0])

sum = 0
for i in range(n):
    sum += rest[i][0]

diff = abs(pr-qr)

count = 0

rsum = 0
if pr <= qr:
    for i in range(x):
        if p[i][1] == 3:
            count += 1
            if count > diff
                rsum += p[i][0]
else:
    for i in range(y):
        if q[i][1] == 3:
            count += 1
            if count > diff
                rsum += q[i][0]

psum = 0
for i in range(x):
    psum += p[i][0]
qsum = 0
for i in range(y):
    qsum += q[i][0]

ans = psum + qsum -rsum + sum

print(ans)

Submission status: Runtime Error

Solution code:
X,Y,A,B,C=map(int,input().split())
p=sorted(map(int,input().split()))
q=sorted(map(int,input().split()))
r=sorted(map(int,input().split()))
ans=[]
ans+=p[A-X:]
ans+=q[B-Y:]
ans.sort()
i=0
j=0
for i in ans:
	j=max(r)
	if i<j:
		ans[i]=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_up = P[-X:]
Q_up = Q[-Y:]

P_up.append(Q_up)
P_up.extend(R)

P_up.sort()
a=-(X+Y)
print(sum(P_up[a:]))

Submission status: Runtime Error

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

###
# main
if(__name__ == '__main__'):
    # input
    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()

    x_cnt = 0
    y_cnt = 0
    r_cnt = 0
    deli = 0
    used_a = []
    used_b = []
    used_c = []
    for i in range(x+y):
        tgt_p = p[-1]
        tgt_q = q[-1]
        tgt_r = r[-1]
        if tgt_q <= tgt_p and tgt_r <= tgt_p:
            x_cnt += 1
            deli += tgt_p
            p.remove(tgt_p)
            used_a.append(tgt_p)
        elif tgt_p <= tgt_q and tgt_r <= tgt_q:
            y_cnt += 1
            deli += tgt_q
            q.remove(tgt_q)
            used_b.append(tgt_q)
        elif tgt_p <= tgt_r and tgt_q <= tgt_r:
            deli += tgt_r
            r.remove(tgt_r)
            used_c.append(tgt_r)

    if r_cnt == 0:
        print(deli)

# else:
    # do nothing

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)

red = []
green = []

# for i in range(x):
#     red.append(p[i])
# for j in range(y):
#     green.append(q[j])

# print(p[:x])
# print(q[:y]
# print(red)
# print(green)

all = p[:x] + q[:y]
all.sort()

for i in range(len(all)):
    if min(r) > all[i]:
        #print(i)
        if i >= len(r):
            ans = all[len(r) + 1:] + r
        else:
            ans = all[i + 1:] + r[:i]
        break

# for mushoku in r:
#     for i in range(len(all)):
#         if mushoku > all[i]:
#             all[i] = mushoku


# print(sum(all))
print(sum(ans))

Submission status: Runtime Error

Solution code:
X, Y, A, B, C = map(int, input().split())
p = sorted([int(i) for i in input().split()], reverse=True)
q = sorted([int(i) for i in input().split()], reverse=True)
r = sorted([int(i) for i in input().split()])

p = p[:X]
q = q[:Y]
plus_r = []

while r != [] and ((p != [] and r[-1] > p[-1]) or (q != [] and r[-1] > q[-1])):
    if p[-1] < q[-1]:
        p.pop()
    else:
        q.pop()
    plus_r.append(r.pop())

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

Submission status: Runtime Error

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

psum = 0
plist = []

for i in range(X):
        plist.append(p[i])
for i in range(Y):
        plist.append(q[i])
        
plist.sort()
        
for i in range(C):
    if r[i] > plist[0]:
        plist.pop(i)
        plist.append(r[i])
    else:
        break
        
print(sum(plist))

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()))
zen = []

for i in range(a):
    zen.append((P[i],'P'))
for i in range(b):
    zen.append((Q[i],'Q'))
for i in range(c):
    zen.append((R[i],'R'))
zen = sorted(zen,reverse=True)

i=0
ans = 0
red = 0
green = 0
white = 0
while red+green+white!=a+b:
    aji,color = zen[i]
    if red<=a and green <=b:
        if color == 'P':
            red+=1
        elif color =='Q'
            green+=1
        else:
            white+=1
        ans == aji
print(ans)

Submission status: Runtime Error

Solution code:
#200329E
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)
R = sorted(r)
Red = p + r
Red = sorted(Red)
Deli =[]

for i in range(X):
    Deli.append(Red[len(Red)-1-i])
    if Red[len(Red)-1-i] == P[len(P)-1-i]:
        Red[len(Red)-1-i] = 0
        #print(Red)
        P[len(P)-1-i]= 0
    else:
        Red[len(Red)-1-i] = 0
        R[len(R)-1-i]= 0

Green = q + R
Green = sorted(Green)
for i in range(Y):
    Deli.append(Green[len(Green)-1-i])
    
#print(Deli)
print(int(sum(Deli)))

Submission status: Runtime Error

Solution code:
x,y,a,b,c = (int(x) for x in input().split())

from bisect import insort

p_list = []
q_list = []
r_list = []

for value in input().split():
  value = int(value)
  if len(p_list) >= x:
    if p_list[-1*(x-1)-1] < value:
      insort(p_list,value)
      p_list = p_list[-1*(x+1)-1:]
  else:
    insort(p_list,value)

for value in input().split():
  value = int(value)
  if len(q_list) >= y:
    if q_list[-1*(y-1)-1] < value:
      insort(q_list,value)
      q_list = q_list[-1*(y+1)-1:]
  else:
    insort(q_list,value)
  
for value in input().split():
  value = int(value)
  if len(r_list) >= x+y:
    if r_list[-1*(x+y)-1] < value:
      insort(r_list.value)
      r_list = r_list[-1*(x+y+1)-1:]
  else:
    insort(r_list,value)
  
red = 0
green = 0
white = 0

sum_num = 0

for i in range(1,x+y+1):
  if red < x:
  	red_num = p_list[(red*-1)-1]
  else:
    red_num = 0
  if green < y:
  	green_num = q_list[(green*-1)-1]
  else:
    green_num = 0
  if white < c:
  	white_num = r_list[(white*-1)-1]
  else:
    white_num = 0
  
  max_p = max([red_num,green_num,white_num])
  sum_num += max_p
  if max_p == white_num:
    white += 1
  elif max_p == red_num:
    red += 1
  elif max_p == green_num:
    green += 1

print(sum_num)

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 len(arrayAns) >= i:
        if arrayAns[i] <= int(arrayR[i]):
           arrayAns[i] = int(arrayR[i])
        else:
            break
print(sum(arrayAns))

Submission status: Runtime Error

Solution code:
import heapq


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

r = []
g = []
nc = []
for p in P:
    heapq.heappush(r, -p)

for q in Q:
    heapq.heappush(g, -q)

for i in R:
    heapq.heappush(nc, -i)

ans = 0
#print(r,g,nc)
while X > 0 or Y > 0:


    if X > 0 and Y > 0:
        if len(nc) > 0 and r[0] < nc[0]:
            ans += -1 * r[0]
            heapq.heappop(r)
            X -= 1

        elif len(nc) > 0 and g[0] < nc[0]:
            ans += -1 * g[0]
            heapq.heappop(g)
            Y -= 1
        else:
            if  len(nc) > 0 and abs(nc[0] - r[0]) >= abs(nc[0] - g[0]):
                ans += -1 * nc[0]
                heapq.heappop(nc)
                X -= 1
            elif len(nc) > 0 and abs(nc[0] - r[0]) < abs(nc[0] - g[0]):
                ans += -1 * nc[0]
                heapq.heappop(nc)
                Y -= 1
            else:
                if r[0] < g[0]:
                    ans += -1 * r[0]
                    heapq.heappop(r)
                    X -= 1
                else:
                    ans += -1 * g[0]
                    heapq.heappop(g)
                    Y -= 1
        
    elif X > 0:
        if len(nc) > 0 and  r[0] < nc[0]:
            ans += -1 * r[0]
            heapq.heappop(r)
            X -= 1

        elif len(nc) > 0 and  r[0] >= nc[0]:
            ans += -1 * nc[0]
            heapq.heappop(nc)
            X -= 1
        elif :
            ans += -1 * r[0]
            heapq.heappop(r)
            X -= 1
    else:
        if len(nc) > 0 and  g[0] < nc[0]:
            ans += -1 * g[0]
            heapq.heappop(g)
            Y -= 1

        elif len(nc) > 0 and  g[0] >= nc[0]:
            ans += -1 * nc[0]
            heapq.heappop(nc)
            Y -= 1
        elif :
            ans += -1 * g[0]
            heapq.heappop(g)
            Y -= 1
            

print(ans)

Submission status: Runtime Error

Solution code:
#コンマで区切る
A_list = input().split(' ')
    
#コンマで区切る
p_list = input().split(' ')
for i in range(len(p_list)):
    p_list[i] = int(p_list[i])
p_list = p_list.sort()

#コンマで区切る
q_list = input().split(' ')
for i in range(len(q_list)):
    q_list[i] = int(q_list[i])
q_list = q_list.sort()

#コンマで区切る
r_list = input().split(' ')
for i in range(len(r_list)):
    r_list[i] = int(r_list[i])
r_list = r_list.sort()    
    
ans_list = []
#無色を考えない
del p_list[int(X):]
del q_list[int(Y):]

ans_list = p_list + p_list
ans_list = ans_list.sort()





for i in range(len(ans_list)):
  if(ans_list[i] < r_list[0]):
    ans_list[i] = r_list[0]
    r_list.remove(r_list[0])
    
print(sum(ans_list))

Submission status: Runtime Error

Solution code:
X,Y,A,B,C=map(int,input().split())
red=sorted(list(map(int,input().split())),reverse=True)
green=sorted(list(map(int,input().split())),reverse=True)
nocolor=sorted(list(map(int,input().split())),reverse=True)

X_cnt=0
Y_cnt=0
ans=[]

for i in range(X):
    ans.append(red[i])
    X_cnt+=1
    if X_cnt==X:
        break
    elif X_cnt<X:
        continue
for i in range(Y):
    ans.append(green[i])
    Y_cnt+=1
    if Y_cnt==Y:
        break
    elif Y_cnt<Y:
        continue

ans=sorted(ans)
ans_sum=sum(ans)    
for i in range(C):
    if ans[i]<nocolor[i]:
        ans_sum=ans_sum+nocolor[i]-ans[i]
        
print(ans_sum)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 28 22:06:13 2020

@author: Kanaru Sato
"""

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 = []
Q = []
R = []

for i in range(a):
    P.append([P_[i],1])
for i in range(b):
    Q.append([Q_[i],2])
for i in range(c):
    R.append([R_[i],3])

p = P+R
p.sort(reverse=True, key=lambda x: x[0])
q = Q+R
q.sort(reverse=True, key=lambda x: x[0])
##########
pr = 0
for i in range(x):
    if p[i][1] == 3:
        pr += 1

qr = 0
for i in range(y):
    if q[i][1] == 3:
        qr += 1
        
n = min(pr,qr)

############

prest = p[x:len(p)+1]
qrest = q[y:len(q)+1]
rest = prest+qrest
rest.sort(reverse=True, key=lambda x: x[0])

sum = 0
for i in range(n):
    sum += rest[i][0]

diff = abs(pr-qr)

count = 0

rsum = 0
if pr <= qr:
    for i in range(x):
        if p[i][1] == 3:
            count += 1
            if count > diff
                rsum += p[i][0]
else:
    for i in range(y):
        if q[i][1] == 3:
            count += 1
            if count > diff
            rsum += q[i][0]

psum = 0
for i in range(x):
    psum += p[i][0]
qsum = 0
for i in range(y):
    qsum += q[i][0]

ans = psum + qsum -rsum + sum

print(ans)

Submission status: Runtime Error

Solution code:
x, y, a, b, c = map(int, input().split())
R = sorted(list(map(int, input().split())), reverse=True)
G = sorted(list(map(int, input().split())), reverse=True)
M = sorted(list(map(int, input().split())), reverse=True)

ans, r, g, m = 0, 0, 0, 0

for i in range(x + y):
    if r >= x:
        if m >= c:
            ans += G[g]
            g += 1
        elif G[g] >= M[m]:
            ans += G[g]
            g += 1
        else:
            ans += M[m]
            m += 1
    elif g >= y:
        if m >= c:
            ans += R[r]
            r += 1
        elif R[r] >= M[m]:
            ans += R[r]
            r += 1
        else:
            ans += M[m]
            m += 1
    elif R[r] > G[g]:
        if m >= c:
            ans += R[r]
            r += 1
        elif R[r] >= M[m]:
            ans += R[r]
            r += 1
        else:
            ans += M[m]
            m += 1
    elif R[r] <= G[g]:
        if m >= c:
            ans += G[g]
            g += 1
        if G[g] >= M[m]:
            ans += G[g]
            g += 1
        else:
            ans += M[m]
            m += 1
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()))

list.sort(p,reverse=True)
list.sort(q,reverse=True)
list.sort(r,reverse=True)
ans = 0
nokorix = x
nokoriy = y
pin =0
qin=0
rin=0
for i in range(x+y):
    c=0
    if nokorix !=0:
        if p[pin]>= max(q[qin],r[rin]):
            ans+=p[pin]
            nokorix -=1
            pin +=1
            c+=1
    if nokoriy != 0:
        if q[qin] >=max(p[pin], r[rin]):
            ans+=q[qin]
            nokoriy -=1
            qin +=1
            c+=1
    if c==0 and (nokorix!=0 or nokoriy!=0):
        if q[qin] >= p[pin] and p[pin]<=r[rin]:
            ans+=r[rin]
            nokorix -=1
            qin+=1
        elif p[pin] >=q[qin] and q[qin] <=r[rin] :
            ans+=r[rin]
            nokoriy-=1
            qin+=1      

print(ans)

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()
    for ir in range(c):
        if ir <= x  and ir <= y:
            if p[ir] < q[ir]:
                if p[ir] < r[ir]:
                    p[ir] = r[ir]
            else:
                if q[ir] < r[ir]:
                    q[ir] = r[ir]
        elif ir <= x:
            if p[ir] < r[ir]:
                p[ir] = r[ir]
        elif ir <= y:
            if q[ir] < r[ir]:
                q[ir] = r[ir]

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

sum = 0
num_X = 0
num_Y = 0

for i in range(X+Y):
  if p[0] >= q[0] and p[0] >= r[0] and num_X < X:
    sum += p[0]
    del p[0]
    num_X += 1
  elif q[0] >= p[0] and q[0] >= r[0] and num_Y < Y:
    sum += q[0]
    del q[0]
    num_Y += 1
  elif r[0] >= p[0] and r[0] >= q[0] and p[0] >= q[0] and num_Y < Y:
    sum += r[0]
    del r[0]
    num_Y += 1
  elif r[0] >= p[0] and r[0] >= q[0] and q[0] >= p[0] and num_X < X:
    sum += r[0]
    del r[0]
    num_X += 1
  elif num_X == X and q[0] >= r[0]:
    sum += q[0]
    del q[0]
    num_Y += 1
  elif num_X == X and r[0] >= q[0]:
    sum += r[0]
    del r[0]
    num_Y += 1
  elif num_Y == Y and p[0] >= r[0]:
    sum += p[0]
    del p[0]
    num_X += 1
  elif num_Y == Y and r[0] >= p[0]:
    sum += r[0]
    del r[0]
    num_X += 1
print(sum)

Submission status: Runtime Error

Solution code:
x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)

result = sum(p[:x]) + sum(q[:y])
i = 0
red_min = x-1
blue_min = y-1
flag = True

while flag == True:
    if r[i] > p[red_min] or r[i] > q[blue_min]:
        if p[red_min] < q[blue_min]:
            result = result - p[red_min] + r[i]
            i += 1
            red_min -= 1
        else:
            result = result - q[blue_min] + r[i]
            i += 1
            blue_min -= 1
    else:
        flag = False
print(result)

Submission status: Runtime Error

Solution code:
from collections import deque
X, Y, A, B, C = map(int,input().split())
p = sorted(list(map(int,input().split())))[::-1]
q = sorted(list(map(int,input().split())))[::-1]
r = sorted(list(map(int,input().split())))[::-1]
p = deque(p)
q = deque(q)
r = deque(r)
ans = 0

while len(r) > 0 and X > 0 and p[0] > r[0]:
    ans += p.popleft()
    X -= 1
while len(r) > 0 and Y > 0 and q[0] > r[0]:
    ans += q.popleft()
    Y -= 1

while X > 0 or Y > 0:
    if X > 0 and Y > 0:
        if p[0] > q[0]:
            ans += r.popleft()
            Y -= 1
        else:
            ans += r.popleft()
            X -= 1
    elif X == 0 and Y > 0:
        if len(r) == 0:
            ans += q.popleft()
            Y -= 1
        elif r[0] > q[0]:
            ans += r.popleft()
            Y -= 1
        else:
            ans += q.popleft()
            Y-= 1
    else:
        if len(r) == 0:
            ans += p.popleft()
            X -= 1
        elif r[0] > p[0]:
            ans += r.popleft()
            X -= 1
        else:
            ans += p.popleft()
            X -= 1
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.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

red = []
green = []

# for i in range(x):
#     red.append(p[i])
# for j in range(y):
#     green.append(q[j])

# print(p[:x])
# print(q[:y]
# print(red)
# print(green)

all = p[:x] + q[:y]
all.sort()

for i in range(len(all)):
    if min(r) > all[i]:
        #print(i)
    if i >= len(r):
        ans = all[len(r) + 1:] + r
    else:
        ans = all[i + 1:] + r[:i]
    break

# for mushoku in r:
#     for i in range(len(all)):
#         if mushoku > all[i]:
#             all[i] = mushoku


# print(sum(all))
print(sum(ans))

Submission status: Runtime Error

Solution code:

eat_RED,eat_GR,hav_RED,hav_GR,hav_CL=map(int, input().split())
RED_yam=list(map(int, input().split()))
GR_yam=list(map(int, input().split()))
CL_yam=list(map(int, input().split()))


RED_sub=[]
GR_sub=[]
for i in range(eat_RED):
    RED_sub.append(max(RED_yam))
    RED_yam.remove(max(RED_yam))
for i in range(eat_GR):
    GR_sub.append(max(GR_yam))
    GR_yam.remove(max(GR_yam))

Apple=sorted(RED_sub+GR_sub)

for i in range(len(Apple)):
    if Apple[i]<max(CL_yam):
        Apple[i]=max(CL_yam)
        CL_yam.remove(max(CL_yam))
    else:
        break


print(sum(Apple))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
X, Y, A, B, C = [int(x) for x in input().strip().split()]
p = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:X]
q = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:Y]
r = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:X+Y]

pi, qi, ri = X-1, Y-1, 0
tp, tq, tr = p[pi], q[qi], r[ri]
ans = 0
while pi >= 0 or qi >= 0:
    if tp >= tr and  tq >= tr:
        break
    elif tp < tr and tq < tr:
        if tp < tq:
            p[pi] = r[ri]
            pi -= 1
            ri += 1
        else:
            q[qi] = r[ri]
            qi -= 1
            ri += 1
    else:
        if tp < tr:
            p[pi] = r[ri]
            ri += 1
            pi -= 1
            tp = p[pi]
        else:
            q[qi] = r[ri]
            ri += 1
            qi -= 1
            tq = q[qi]

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

Submission status: Runtime Error

Solution code:
X,Y,A,B,C=map(int,input().split())
red=sorted(list(map(int,input().split())),reverse=True)
green=sorted(list(map(int,input().split())),reverse=True)
nocolor=sorted(list(map(int,input().split())),reverse=True)

X_cnt=0
Y_cnt=0
ans=[]

for i in range(X):
    ans.append(red[i])
    X_cnt+=1
    if X_cnt==X:
        break
    elif X_cnt<X:
        continue
for i in range(Y):
    ans.append(green[i])
    Y_cnt+=1
    if Y_cnt==Y:
        break
    elif Y_cnt<Y:
        continue

ans=sorted(ans)
ans_sum=sum(ans)    
for i in range(C):
    if ans[i]<nocolor[i]:
        ans_sum=ans_sum_nocolor[i]-ans[i]
        
print(ans_sum)

Submission status: Runtime Error

Solution code:
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    X, Y, A, B, C = iim()
    P = list(iim())
    Q = list(iim())
    R = list(iim())

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

    p1 = [0]*(X+1)
    for i in range(X):
        p1[i+1] = p1[i] + P[i]
    q1 = [0]*(Y+1)
    for i in range(Y):
        q1[i+1] = q1[i] + Q[i]

    si = [X-1, Y-1]
    S = [P, Q]
    if P[si[0]] < Q[si[1]]:
        idx = 0
    else:
        idx = 1
    ans = 0
    for i in range(C):
        if S[idx][si[idx]] < R[i]:
            si[idx] -= 1
            ans += R[i]
            if P[si[0]] < Q[si[1]]:
                idx = 0
            else:
                idx = 1
        else:
            break

    print(p1[si[0]+1] + q1[si[1]+1] + ans)

if __name__ == "__main__":
    resolve()