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())
pList = [int(x) for x in input().split()]
qList = [int(x) for x in input().split()]
rList = [int(x) for x in input().split()]

pList.sort(reverse=True)
qList.sort(reverse=True)
rList.sort(reverse=True)

stackX=[]
stackY=[]
stackR=[]

for i in range(X):
    stackX.append(pList[i])

for i in range(Y):
    stackY.append(qList[i])

for i in range(C):
    x = stackX[-1]
    y = stackY[-1]
    r = rList[i]

    if r < x and r < y:
        break
    elif x < y:
        stackX.pop()
        stackR.append(r)
    else:
        stackY.pop()
        stackR.append(r)
print(sum(stackX) + sum(stackY) + sum(stackR))

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)
p = p[:X]
q = q[:Y]
p.extend(q)
p.sort()
for i in range(C) :
    if p[i] < r[i]:
        p[i] = r[i]
    else:
        pass
print(sum(p))

Submission status: Runtime Error

Solution code:
X, Y, A, B, C = [input().split()]
ps = [input().split()]
qs = [input().split()]
rs = [input().split()]
 
ps = sorted(ps)
qs = sorted(qs)
 
ans = 0
 
ans += ps[-X:]
ans += qs[-Y:]
 
for r in rs:
  ans += max(p[-1], q[-1], r)
return ans

Submission status: Runtime Error

Solution code:
X, Y, A, B, C = input()
ps = input()
qs = input()
rs = input()

ps = sorted(ps)
qs = sorted(qs)

ans = 0

ans += ps[-X:]
ans += qs[-Y:]

for r in rs:
  ans += max(p[-1], q[-1], r)
return ans

Submission status: Runtime Error

Solution code:
def solve(X, Y, C, p, q, r):
    red_apples = sorted(p, reverse=True)[: X]
    green_apples = sorted(q, reverse=True)[: Y]
    white_apples = sorted(r)

    ret = 0
    while white_apples:
        if white_apples[-1] <= red_apples[-1] and white_apples[-1] <= green_apples[-1]:
            break

        ret += white_apples.pop(-1)
        if red_apples[-1] < green_apples[-1]:
            red_apples.pop(-1)
        else:
            green_apples.pop(-1)
    return ret + sum(red_apples) + sum(green_apples)

if __name__ == '__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()))
    print(solve(X, Y, C, p, q, r))

Submission status: Runtime Error

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	#a = int(input())
	x, y, a, b, c = IN()
	al = list(IN())
	al.sort(reverse=True)
	bl = list(IN())
	bl.sort(reverse = True)
	cl = list(IN())
	cl.sort(reverse=True)
	#s = input()
	tx=x-1
	ty=y-1
	tc=0
	while True:
		if tc == len(cl):
			break
		al_min=al[tx] if tx >= 0 else 10**10
		bl_min=bl[ty] if ty >= 0 else 10**10
		cl_max=cl[tc]
		if al_min >= cl_max and bl_min >= cl_max:
			break
		elif al_min <= bl_min and al_min < cl_max:
			tx -= 1
			rc += 1
		elif bl_min<= al_min and bl_min < cl_max:
			ty -= 1
			tc += 1
		else:
			break
	ret=sum(al[:tx+1])+sum(bl[:ty+1])+sum(cl[:tc])
	print(ret)
			
		
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Runtime Error

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	#a = int(input())
	x, y, a, b, c = IN()
	al = list(IN())
	al.sort(reverse=True)
	bl = list(IN())
	bl.sort(reverse = True)
	cl = list(IN())
	cl.sort(reverse=True)
	#s = input()
	tx=x-1
	ty=y-1
	tc=0
	while True:
		if tc == len(cl):
			break
		al_min=al[tx] if tx >= 0 else 10**10
		bl_min=bl[ty]
		cl_max=cl[tc]
		if al_min >= cl_max and bl_min >= cl_max:
			break
		elif al_min <= bl_min and al_min < cl_max:
			tx -= 1
			rc += 1
		elif bl_min<= al_min and bl_min < cl_max:
			ty -= 1
			tc += 1
		else:
			break
	ret=sum(al[:tx+1])+sum(bl[:ty+1])+sum(cl[:tc])
	print(ret)
			
		
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Runtime Error

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

A=P[:X]+Q[:Y]+R

A.sort(reverse=True)

print(A[X+Y])

Submission status: Runtime Error

Solution code:
x,y,a,b,c = map(int,input().split())
p_list = list(map(int,input().split()))
q_list = list(map(int,input().split()))
r_list = list(map(int,input().split()))
p_list.sort(reverse=1)                          # 大きい順に並べる
q_list.sort(reverse=1)
r_list.sort(reverse=1)
#print(q_list,p_list,r_list)
ans = 0
ans_list_x = [0]*x
ans_list_y = [0]*y
for i in range(x):
    ans_list_x[i] = p_list[i]
for j in range(y):
    ans_list_y[j] = q_list[j]

#逆順で回す
xdum = x
ydum = y
cdum = c
for k in range(cdum,0,-1):
    #print(k)
    #print(a-k,c-k)
    dum1 = r_list[c-k]-p_list[a-k]
    dum2 = r_list[c-k]-q_list[b-k]
    if dum1 > dum2:
        if dum1 > 0:                                        #dum1が０より小さい時dum2も０より小さい
            ans_list_x[xdum-k] = r_list[k-1]                #無色リンゴを赤色のリンゴに変換
            a += 1
            b += 1
        else:
            c -= 1
    else:
        if dum2 > 0:                                        #dum1が０より小さい時dum2も０より小さい
            ans_list_y[ydum-k] = r_list[k-1]                #無色リンゴを赤色のリンゴに変換
            a += 1
            b += 1
        else:
            c -= 1
print(sum(ans_list_x)+sum(ans_list_y))
#    (ans_list_x[x-k],ans_list_y[y-k],r_list[k])

#print(ans_list_x,ans_list_y)

Submission status: Runtime Error

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

import sys
import math
import numpy as np

sys.setrecursionlimit(10 ** 6)

input_line = input()
X, Y, A, B, C = map(int, input_line.split(" "))

input_line = input()
p = list(map(int, input_line.split(" ")))
p = sorted(p, reverse=True)

input_line = input()
q = list(map(int, input_line.split(" ")))
q = sorted(q, reverse=True)

input_line = input()
r = list(map(int, input_line.split(" ")))
r = sorted(r, reverse=True)

ans = 0

if X>Y:
    for i in range(X-Y):
        if r!=[]:
            if p[0] >= r[0]:
                ans += p[0]
                p = p[1:]
            else:
                ans += r[0]
                r = r[1:]
        else:
            ans += p[0]
            p = p[1:]

elif Y>X:
    for i in range(Y-X):
        if r!=[]:
            if q[0] >= r[0]:
                ans += q[0]
                q = q[1:]
            else:
                ans += r[0]
                r = r[1:]
        else:
            ans += q[0]
            q = q[1:]

lists =  [p, q, r]
for i in range(min(X,Y)):
    p, q, r = lists
    if r!=[]:
        if len(r)!=1:
            inds = np.argsort(np.array([p[0], q[0], r[0], r[1]]))[::-1]
        else:
            inds = np.argsort(np.array([p[0], q[0], r[0]]))[::-1]
    else:
        inds = np.argsort(np.array(p[0], q[0]))[::-1]

    ans += lists[inds[0]][0]
    lists[inds[0]] = lists[inds[0]][1:]

    if inds[1]==3:
        inds[1] = 2
    ans += lists[inds[1]][0]
    lists[inds[1]] = lists[inds[1]][1:]

print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque
X, Y, A, B, C = map(int, input().split())
qa = deque(sorted(list(map(int, input().split())), reverse=True))
qb = deque(sorted(list(map(int, input().split())), reverse=True))
qc = deque(sorted(list(map(int, input().split())), reverse=True))
ans = 0
for _ in range(X):
    if qa[0] >= qc[0]:
        ans += qa.popleft()
    else:
        ans += qc.popleft()

for _ in range(Y):
    if qb[0] >= qc[0]:
        ans += qb.popleft()
    else:
        ans += qc.popleft()
print(ans)

Submission status: Runtime Error

Solution code:
X, Y, A, B, C = map(int, input().split())
deli_A = list(map(int, input().split()))
deli_B = list(map(int, input().split()))
deli_C = list(map(int, input().split()))

sum_deli = 0
for a in range(X):
    max_deli_A = max(deli_A)
    if max_deli_A > max(deli_C):
        deli_A.remove(max_deli_A)
    else:
        max_deli_A = max(deli_C)
        deli_C.remove(max_deli_A)

    sum_deli += max_deli_A

for a in range(Y):
    max_deli_B = max(deli_B)
    if max_deli_B > max(deli_C):
        deli_B.remove(max_deli_B)
    else:
        max_deli_B = max(deli_C)
        deli_C.remove(max_deli_B)

    sum_deli += max_deli_B

print(sum_deli)

Submission status: Runtime Error

Solution code:
X, Y, A, B, C = map(int, input().split())
deli_A = list(map(int, input().split()))
deli_B = list(map(int, input().split()))
deli_C = list(map(int, input().split()))

sum_deli = 0
for a in range(X):
    max_deli_A = max(deli_A)
    if len(deli_C) > 0 and max_deli_A > max(deli_C):
        deli_A.remove(max_deli_A)
    else:
        max_deli_A = max(deli_C)
        deli_C.remove(max_deli_A)

    sum_deli += max_deli_A

for a in range(Y):
    max_deli_B = max(deli_B)
    if len(deli_C) > 0 and max_deli_B > max(deli_C):
        deli_B.remove(max_deli_B)
    else:
        max_deli_B = max(deli_C)
        deli_C.remove(max_deli_B)

    sum_deli += max_deli_B

print(sum_deli)

Submission status: Runtime Error

Solution code:
x, y, a, b, c = map(int, input().split())
pn = list(map(int, input().split()))
qn = list(map(int, input().split()))
rn = list(map(int, input().split()))

pn.sort(reverse=True)
qn.sort(reverse=True)
rn.sort(reverse=True)

pn = pn[:x]
qn = qn[:y]
rcount = 0

while min(pn[-1], qn[-1]) <= rn[0]:
  if pn[-1] >= qn[-1]:
    rcount += rn[0]
    del qn[-1]
  else:
    rcount += rn[0]
    del pn[-1]
  del rn[0]
  if len(rn) == 0:
    break
  
print(sum(pn) + sum(qn) + rcount)

Submission status: Runtime Error

Solution code:
# 標準入力
X, Y, A, B, C = map(int, input().split())
red = list(map(int,input().split()))
green = list(map(int,input().split()))
trans = list(map(int,input().split()))

red.sort(reverse=True)
green.sort(reverse=True)
trans.sort(reverse=True)
apple = red[:X] + green[:Y]
apple.sort(reverse=True)

j = 0
for i in range(X + Y):
    if apple[X + Y - i - 1] < trans[j]:
        apple[X + Y - i - 1] = trans[j]
        j = j + 1
        if j is C:
            break
    else:
        continue
print(sum(apple))

Submission status: Runtime Error

Solution code:
# 標準入力
X, Y, A, B, C = map(int, input().split())
red = list(map(int,input().split()))
green = list(map(int,input().split()))
trans = list(map(int,input().split()))
red.sort(reverse=True)
green.sort(reverse=True)
trans.sort(reverse=True)
apple = red[:X] + green[:Y]
apple.sort(reverse=True)
j = 0
for i in range(X + Y):
    if apple[i] < trans[j]:
        apple[i] = trans[j]
        j = j + 1
    else:
        continue
print(sum(apple))

Submission status: Runtime Error

Solution code:
# 標準入力
X, Y, A, B, C = map(int, input().split())
red = list(map(int,input().split()))
green = list(map(int,input().split()))
trans = list(map(int,input().split()))
red.sort(reverse=True)
green.sort(reverse=True)
trans.sort(reverse=True)
apple = red[:X] + green[:Y]
j = 0
for i in range(X + Y):
    if apple[i] < trans[j]:
        apple[i] = trans[j]
        j = j + 1
    else:
        continue
print(sum(apple))

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_que1 = deque([])
q_que1 = deque([])
r_que1 = deque([])

p_que2 = deque([])
q_que2 = deque([])
r_que2 = deque([])

for i in range(a):
    p_que1.append(p[i])
    p_que2.append(p[i])
for i in range(b):
    q_que1.append(q[i])
    q_que2.append(q[i])
for i in range(c):
    r_que1.append(r[i])
    r_que2.append(r[i])

yamm_1 = 0
yamm_2 = 0

for i in range(x):
    if p_que1[0] >= r_que1[0]:
        ma = int(p_que1.popleft())
        yamm_1 += ma
    else:
        ma = int(r_que1.popleft())
        yamm_1 += ma

for i in range(y):
    if q_que1[0] >= r_que1[0]:
        ma = int(q_que1.popleft())
        yamm_1 += ma
    else:
        ma = int(r_que1.popleft())
        yamm_1 += ma


for i in range(x):
    if p_que2[0] >= r_que2[0]:
        ma = int(p_que2.popleft())
        yamm_2 += ma
    else:
        ma = int(r_que2.popleft())
        yamm_2 += ma

for i in range(y):
    if q_que2[0] >= r_que2[0]:
        ma = int(q_que2.popleft())
        yamm_2 += ma
    else:
        ma = int(r_que2.popleft())
        yamm_2 += ma


print(max(yamm_1, yamm_2))

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_que = deque([])
q_que = deque([])
r_que = deque([])
for i in range(a):
    p_que.append(p[i])
for i in range(b):
    q_que.append(q[i])
for i in range(c):
    r_que.append(r[i])

yamm = 0

for i in range(x):
    if p_que[0] >= r_que[0]:
        ma = int(p_que.popleft())
        yamm += ma
    else:
        ma = int(r_que.popleft())
        yamm += ma

for i in range(y):
    if q_que[0] >= r_que[0]:
        ma = int(q_que.popleft())
        yamm += ma
    else:
        ma = int(r_que.popleft())
        yamm += ma

print(yamm)

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_que = deque([])
q_que = deque([])
r_que = deque([])
for i in range(a):
    p_que.append(p[i])
for i in range(b):
    q_que.append(q[i])
for i in range(c):
    r_que.append(r[i])

yamm = 0

for i in range(x):
    if p_que[0] >= r_que[0]:
        ma = int(p_que.popleft())
        yamm += ma
    else:
        ma = int(q_que.popleft())
        yamm += ma

for i in range(y):
    if q_que[0] >= r_que[0]:
        ma = int(q_que.popleft())
        yamm += ma
    else:
        ma = int(r_que.popleft())
        yamm += ma

print(yamm)

Submission status: Runtime Error

Solution code:
x,y,a,b,c = map(int, input().split())
p1 = list(map(int, input().split()))
p2 = list(map(int, input().split()))
p3 = list(map(int, input().split()))
ans1 = 0
ans2 = 0
p1.sort(reverse = True)
p2.sort(reverse = True)
p3.sort(reverse = True)
for i in range(0,x):
  ans1= ans1 + max(p1[i],p3[0])
  if(p3[0]>p1[i]):
    del p3[0]
for i in range(0,y):
  ans2= ans2 + max(p2[i],p3[0])
  if(p3[0]>p2[i]):
    del p3[0]
print(ans1+ans2)

Submission status: Runtime Error

Solution code:
x,y,a,b,c = map(int, input().split())
p1 = list(map(int, input().split()))
p2 = list(map(int, input().split()))
p3 = list(map(int, input().split()))
ans1 = 0
ans2 = 0
p1.sort(reverse = True)
p2.sort(reverse = True)
p3.sort(reverse = True)
for i in range(0, max(x,y)):
  p3.append(0)
for i in range(0,x):
  ans1= ans1 + max(p1[i],p3[i])
  if(p3[i]>p1[i]):
    del p[i]
for i in range(0,y):
  ans2= ans2 + max(p2[i],p3[i])
  if(p3[i]>p2[i]):
    del p3[i]
print(ans1+ans2)

Submission status: Runtime Error

Solution code:
X, Y, A, B, C = map(int, input().split())
p = []
q = []
r = []
for text in input().split():
    p.append(int(text))
for text in input().split():
    q.append(int(text))
for text in input().split():
    r.append(int(text))
p.sort()
q.sort()
r.sort()
nowA = A
nowB = B
nowC = C
buf = True
while(buf and nowC != 0):
    if(p[nowA - X - 1] > q[nowB - Y - 1]):
        if(q[nowB - Y - 1] < r[nowC - 1]):
            q.append(r[nowC - 1])
            nowB+=1
            nowC-=1
        else:
            buf = False
    else:
        if(p[nowA - Y - 1] < r[nowC - 1]):
            p.append(r[nowC - 1])
            nowA+=1
            nowC-=1
        else:
            buf = False
ans = 0
for i in range(X):
    ans+=p[nowA - i - 1]
for i in range(Y):
    ans+=q[nowB - i - 1]
print(ans)

Submission status: Runtime Error

Solution code:
X, Y, A, B, C = map(int, input().split())
p = []
q = []
r = []
for text in input().split():
    p.append(int(text))
for text in input().split():
    q.append(int(text))
for text in input().split():
    r.append(int(text))
p.sort()
q.sort()
r.sort()
nowA = A
nowB = B
nowC = C
buf = True
while(buf && nowC != 0):
    if(p[nowA - X - 1] > q[nowB - Y - 1]):
        if(q[nowB - Y - 1] < r[nowC - 1]):
            q.append(r[nowC - 1])
            nowB++
            nowC--
        else:
            buf = False
    else:
        if(p[nowA - Y - 1] < r[nowC - 1]):
            p.append(r[nowC - 1])
            nowA++
            nowC--
        else:
            buf = False
ans = 0
for i in range(X):
    ans+=p[nowA - i - 1]
for i in range(Y):
    ans+=q[nowB - i - 1]
print(ans)

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)
P = P[:X]
Q = Q[:Y]
A = P + Q + R
A.sorted(reverse=True)
ans = sum(A[:X+Y])
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
input = 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()))
red = sorted(p)
green = sorted(q)
no = sorted(r)
red.reverse()
green.reverse()
no.reverse()

c_r = 0
c_g = 0
c_n = 0
ans = 0

while (c_r < X) and (c_g < Y) and (c_n < C):
  tmp = min(red[X-c_r-1],green[Y-c_g-1])
  if tmp > no[c_n]:
    break
  else:
    ans += no[c_n]
    c_n += 1
    if red[X-c_r] > green[Y-c_g]:
      c_g += 1
    else:
      c_r += 1

if c_r == X:
  while (c_n < C) and (c_g < Y):
    if green[c_g] > no[c_n] :
      break
    else:
      ans += no[c_n]
      c_g += 1
      c_n += 1
elif c_g == Y:
  while (c_n < C) and (c_r < X):
    if red[c_r] > no[c_n] :
      break
    else:
      ans += no[c_n]
      c_r += 1
      c_n += 1

if c_r != X:
  ans += sum(red[0:X-c_r])
if c_g != Y:
  ans += sum(green[0:Y-c_g])
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
input = 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()))
red = sorted(p, reverse = True)
green = sorted(q, reverse = True)
no = sorted(r, reverse = True)

c_r = 0
c_g = 0
c_n = 0
ans = 0

while (c_r < X) and (c_g < Y) and (c_n < C):
  tmp = min(red[X-c_r-1],green[Y-c_g-1])
  if tmp > no[c_n]:
    break
  else:
    ans += no[c_n]
    c_n += 1
    if red[X-c_r] > green[Y-c_g]:
      c_g += 1
    else:
      c_r += 1

if c_r == X:
  while (c_n < C) and (c_g < Y):
    if green[c_g] > no[c_n] :
      break
    else:
      ans += no[c_n]
      c_g += 1
      c_n += 1
elif c_g == Y:
  while (c_n < C) and (c_r < X):
    if red[c_r] > no[c_n] :
      break
    else:
      ans += no[c_n]
      c_r += 1
      c_n += 1

if c_r != X:
  ans += sum(red[0:X-c_r-1])
if c_g != Y:
  ans += sum(green[0:Y-c_g-1])
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
input = stdin.readline
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()) for _ in range(X))
q = list(map(int, input().split()) for _ in range(Y))
r = list(map(int, input().split()))
red = sorted(p, reverse = True)
green = sorted(q, reverse = True)
no = sorted(r, reverse = True)

c_r = 0
c_g = 0
c_n = 0
ans = 0

while (c_r < X) and (c_g < Y) and (c_n < C):
  tmp = min(red[X-c_r-1],green[Y-c_g-1])
  if tmp > no[c_n]:
    break
  else:
    ans += no[c_n]
    c_n += 1
    if red[X-c_r] > green[Y-c_g]:
      c_g += 1
    else:
      c_r += 1

if c_r == X:
  while (c_n < C) and (c_g < Y):
    if green[c_g] > no[c_n] :
      break
    else:
      ans += no[c_n]
      c_g += 1
      c_n += 1
elif c_g == Y:
  while (c_n < C) and (c_r < X):
    if red[c_r] > no[c_n] :
      break
    else:
      ans += no[c_n]
      c_r += 1
      c_n += 1

if c_r != X:
  ans += sum(red[0:X-c_r-1])
if c_g != Y:
  ans += sum(green[0:Y-c_g-1])
print(ans)

Submission status: Runtime Error

Solution code:
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()) for _ in range(X))
q = list(map(int, input().split()) for _ in range(Y))
r = list(map(int, input().split()))
new = p + q + r
new = sorted(new, reverse = True)
print(sum(new[0:X+Y]))

Submission status: Runtime Error

Solution code:
from sys import stdin
input = stdin.readline
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()) for _ in range(X))
q = list(map(int, input().split()) for _ in range(Y))
r = list(map(int, input().split()))
new = p + q + r
new = sorted(new, reverse = True)
print(sum(new[0:X+Y]))

Submission status: Runtime Error

Solution code:
from sys import stdin
input = stdin.readline
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()) for _ in range(X))
q = list(map(int, input().split()) for _ in range(Y))
r = list(map(int, input().split()))
red = sorted(p, reverse = True)
green = sorted(q, reverse = True)
no = sorted(r, reverse = True)

c_r = 0
c_g = 0
c_n = 0
ans = 0

while (c_r < X) and (c_g < Y) and (c_n < C):
  tmp = min(red[X-c_r-1],green[Y-c_g-1])
  if tmp > no[c_n]:
    break
  else:
    ans += no[c_n]
    c_n += 1
    if red[X-c_r] > green[Y-c_g]:
      c_g += 1
    else:
      c_r += 1

if c_r == X:
  while (c_n < C) and (c_g < Y):
    if green[c_g] > no[c_n] :
      break
    else:
      ans += no[c_n]
      c_g += 1
      c_n += 1
elif c_g == Y:
  while (c_n < C) and (c_r < X):
    if red[c_r] > no[c_n] :
      break
    else:
      ans += no[c_n]
      c_r += 1
      c_n += 1

if c_r != X:
  ans += sum(red[0:X-c_r-1])
if c_g != Y:
  ans += sum(green[0:Y-c_g-1])
print(ans)

Submission status: Runtime Error

Solution code:
#n,x,y=map(int,input())
# Queue
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()
q.sort()
p=deque(p[a-x:])
q=deque(q[b-y:])
r.sort()
for ri in r:
    if ri > p[0] and q[0] >= p[0]:
        p.popleft()
        p.append(ri)
        p.sort()
        continue
    if ri > q[0] and p[0] >= q[0]:
        q.popleft()
        q.sort()
        q.append(ri)
print(sum(p)+sum(q))

"""
1 2 2 2 1
2 4
5 1
3
->12
2 2 2 2 2
8 6
9 1
2 1
->25
"""

Submission status: Runtime Error

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

p_a = list(map(int, input().split()))
p_b = list(map(int, input().split()))
p_c = list(map(int, input().split()))

p_a = p_a[-x:]
p_a.extend(p_b[-y:])
p_a.sort()
p_c.sort()

start = 0

sum = 0
for _ in range(x + y):
    print(p_a, p_c)
    if p_a > p_c:
        sum += p_a.pop()
    else:
        sum += p_c.pop()

print(sum)

Submission status: Runtime Error

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

p_a = list(map(int, input().split()))
p_b = list(map(int, input().split()))
p_c = list(map(int, input().split()))

p_a = p_a[-x:]
p_a.extend(p_b[-y:])
p_a = sorted(p_a)
p_c.sort(reverse=True)

start = 0

while p_c:
    if p_a[start] < p_c[0]:
        p_a[start] = p_c.pop(0)
        start += 1
    else: break


print(sum(p_a))

Submission status: Runtime Error

Solution code:
X, Y, R, G, W = map(int, input().split())
red = sorted(list(map(int, input().split())), key=lambda x: -x)
green = sorted(list(map(int, input().split())), key=lambda x: -x)
white = sorted(list(map(int, input().split())), key=lambda x: -x)

dp = [[[0 for _ in range(X+Y+1)] for __ in range(Y+1)] for ___ in range(X+1)]

ans = 0

for w in range(min(W, X+Y)+1):
    for x in range(X+1):
        for y in range(Y+1):
            if x + y + w == X + Y:
                ans = max(ans, dp[x][y][w])
                break
            if x < X:
                dp[x+1][y][w] = max(dp[x+1][y][w], dp[x][y][w] + red[x])
            if y < Y:
                dp[x][y+1][w] = max(dp[x][y+1][w], dp[x][y][w] + green[y])
            if w < W:
                dp[x][y][w+1] = max(dp[x][y][w+1], dp[x][y][w] + white[w])

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)

k = 0
i = x-1
j = y-1

while k <= c and   (p[i] < r[k] or q[j] < r[k]):
  if p[i] <= q[j] and p[i] < r[k]:
    p[i] = r[k]
    if i > 0:
      i -= 1
  
    k += 1
  elif p[i] > q[j] and q[j] < r[k]:
    q[j] = r[k]
    if i > 0:
      j -= 1
    k += 1
  
  
  
#print(p)
#print(q)
    
sum = 0
for ii in range(x):
  sum += p[ii]

for jj in range(y):
  sum += q[jj]
  
print(sum)

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)

k = 0
i = x-1
j = y-1

while k <= c and   (p[i] < r[k] or q[j] < r[k]):
  if p[i] <= q[j] and p[i] < r[k]:
    p[i] = r[k]
    i -= 1
    k += 1
  elif p[i] > q[j] and q[j] < r[k]:
    q[j] = r[k]
    j -= 1
    k += 1
  
  
  
#print(p)
#print(q)
    
sum = 0
for ii in range(x):
  sum += p[ii]

for jj in range(y):
  sum += q[jj]
  
print(sum)

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)

k = 0
i = x-1
j = y-1

while p[i] < r[k] or q[j] < r[k]:
  if p[i] <= q[j] and p[i] < r[k]:
    p[i] = r[k]
    i -= 1
    k += 1
  elif p[i] > q[j] and q[j] < r[k]:
    q[j] = r[k]
    j -= 1
    k += 1

#print(p)
#print(q)
    
sum = 0
for ii in range(x):
  sum += p[ii]

for jj in range(y):
  sum += q[jj]
  
print(sum)

Submission status: Runtime Error

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

red = [int (i) for i in input().split()];
green = [int (i) for i in input().split()];
color = [int (i) for i in input().split()];

usedr = 0;
usedg = 0;
usedc = 0;
res = 0;

red.sort(reverse=True);
green.sort(reverse=True);
color.sort(reverse=True);

red.append(0);
green.append(0);
color.append(0);

while True:
    #print(usedr, usedg, usedc);
    if usedr + usedg + usedc == x + y:
        break;
    if usedc < c:
        if (color[usedc] >= red[usedr] and color[usedc] >= green[usedg]) or (usedg == y and usedr == x):
            res += color[usedc];
            usedc += 1;
        elif (red[usedr] >= green[usedg] and usedr < x) or (usedg == y):
            res += red[usedr];
            usedr += 1;
        else:
            res += green[usedg];
            usedg += 1;
    else:
        if usedr < x:
            res += red[usedr];
            usedr += 1;
        if usedg < y:
            res += red[usedr];
            usedr += 1;

print(res);

Submission status: Runtime Error

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

red = [int (i) for i in input().split()];
green = [int (i) for i in input().split()];
color = [int (i) for i in input().split()];

usedr = 0;
usedg = 0;
usedc = 0;
res = 0;

red.sort(reverse=True);
green.sort(reverse=True);
color.sort(reverse=True);

red.append(0);
green.append(0);

while True:
    #print(usedr, usedg, usedc);
    if usedr + usedg + usedc == x + y:
        break;
    if usedc < c:
        if color[usedc] >= red[usedr] and color[usedc] >= green[usedg] or (usedg == y and usedr == x):
            res += color[usedc];
            usedc += 1;
        elif (red[usedr] >= green[usedg] and usedr < x) or (usedg == y):
            res += red[usedr];
            usedr += 1;
        else:
            res += green[usedg];
            usedg += 1;
    else:
        if usedr < a:
            res += red[usedr];
            usedr += 1;
        if usedg < b:
            res += red[usedr];
            usedr += 1;

print(res);

Submission status: Runtime Error

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

red = [int (i) for i in input().split()];
green = [int (i) for i in input().split()];
color = [int (i) for i in input().split()];

usedr = 0;
usedg = 0;
usedc = 0;
res = 0;

red.sort(reverse=True);
green.sort(reverse=True);
color.sort(reverse=True);

red.append(0);
green.append(0);

while True:
    if usedr + usedg + usedc == x + y:
        break;
    if usedc < c:
        if color[usedc] >= red[usedr] and color[usedc] >= green[usedg]:
            res += color[usedc];
            usedc += 1;
        elif red[usedr] >= green[usedg]:
            res += red[usedr];
            usedr += 1;
        else:
            res += green[usedg];
            usedg += 1;
    else:
        if usedr < a:
            res += red[usedr];
            usedr += 1;
        if usedg < b:
            res += red[usedr];
            usedr += 1;

print(res);

Submission status: Runtime Error

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