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

Solution (Python):
from collections import deque
x,y,a,b,c = map(int,input().split())
red = [int(i) for i in input().split()]
g = [int(i) for i in input().split()]
w = [int(i) for i in input().split()]
red.sort(reverse=True)
g.sort(reverse=True)
g = g[:y]
gw = g+w
gw.sort(reverse=True)
gwrui = []
rui = 0
for i in range(y+c):
    rui += gw[i]
    gwrui.append(rui)
red = red[:x]
rrui = []
rui = 0
for i in range(x):
    rui += red[i]
    rrui.append(rui)
rrui = [0] + rrui
ans = 0
oisr = 0
lgw = len(gw)

for i in range(0,x+1):
    temp = rrui[i]
    if x+y-i <= lgw:
        temp += gwrui[x+y-i-1]
        ans = max(ans,temp)
print(ans)

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

ans = []

for i in range(X):
    ans.append(p[i])

for i in range(Y):
    ans.append(q[i])

for i in range(C):
    ans.append(r[i])

ans.sort(reverse=True)
print(sum(ans[0:X+Y]))

Solution (Python):
from collections import deque
x,y,a,b,c = map(int,input().split())
red = [int(i) for i in input().split()]
g = [int(i) for i in input().split()]
w = [int(i) for i in input().split()]
red.sort(reverse=True)
g.sort(reverse=True)
g = g[:y]
gw = g+w
gw.sort(reverse=True)
gwrui = []
rui = 0
for i in range(y+c):
    rui += gw[i]
    gwrui.append(rui)
red = red[:x]
rrui = []
rui = 0
for i in range(x):
    rui += red[i]
    rrui.append(rui)
rrui = [0] + rrui
ans = 0
oisr = 0
lgw = len(gw)

for i in range(0,x+1):
    temp = rrui[i]
    if x+y-i <= lgw:
        temp += gwrui[x+y-i-1]
        ans = max(ans,temp)
print(ans)

Solution (Python):
x,y,a,b,c=map(int,input().split())
p=[int(i) for i in input().split()]
q=[int(j) for j in input().split()]
r=[int(k) for k in input().split()]
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p=p[:x]
q=q[:y]
s=p+q+r
s.sort(reverse=True)
s=s[:x+y]
print(sum(s))

Solution (Python):
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()
p.reverse()
q.reverse()
r.reverse()

ret = 0
z = 0

pidx=0
qidx=0
ridx=0

plen=len(p)
qlen=len(q)
rlen=len(r)
while(x + y > z):
    pattern = 0
    apple = 0
    if x > 0 and pidx < plen:
        apple = p[pidx]
        pattern = 1
    if y > 0 and qidx < qlen:
        if apple < q[qidx]:
            apple = q[qidx]
            pattern = 2
    if ridx < rlen and apple < r[ridx]:
        apple = r[ridx]
        pattern = 3
    ret += apple
    if pattern == 1:
        x -= 1
        pidx += 1
    elif pattern == 2:
        y -= 1
        qidx  += 1
    elif pattern == 3:
        z += 1
        ridx += 1

print(ret)

Solution (Python):
x,y,a,b,c=map(int,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.sort()
q.sort()
p=p[-x:]
q=q[-y:]
s=p+q+r
s.sort()
print(sum(s[-x-y:]))

Solution (Python):
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()
p = p[-X:]
q = q[-Y:]

d = []
d += p
d += q
d += r
d.sort()

print(sum(d[-X-Y:]))

Solution (Python):
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)
ALL = P[0:X]+Q[0:Y]+R
ALL.sort(reverse=True)
print(sum(ALL[0:X+Y]))

Solution (Python):
def main():
    import sys
    input = sys.stdin.buffer.readline
    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.sort(reverse=True)
    Q.sort(reverse=True)
    R.extend(P[:X])
    R.extend(Q[:Y])
    R.sort(reverse=True)
    print(sum(R[:X+Y]))


if __name__ == '__main__':
    main()

Solution (Python):
x,y,a,b,c=map(int,input().split())
p=sorted([int(i) for i in input().split()],reverse=True)[:x]
q=sorted([int(i) for i in input().split()],reverse=True)[:y]
r=sorted([int(i) for i in input().split()],reverse=True)
pq=sorted(p+q)
for i in range(min(x+y,a+b,c)):
    if pq[i]<r[i]:
        pq[i]=r[i]
print(sum(pq))

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

pX = sorted(p, reverse=True)[:X]
qY = sorted(q, reverse=True)[:Y]

D = pX + qY + r

print(sum(sorted(D, reverse=True)[:X+Y]))

Solution (Python):
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)
V = p[0:x] + q[0:y] + r
v = sorted(V,reverse=True)
print(sum(v[0:x+y]))

Solution (Python):
X,Y,A,B,C = map(int,input().split())
r_l = list(map(int,input().split()))
b_l = list(map(int,input().split()))
n_l = list(map(int,input().split()))

r_l.sort(reverse=True)
b_l.sort(reverse=True)

a_l = r_l[:X] + b_l[:Y] + n_l
a_l.sort(reverse=True)
print(sum(a_l[:X+Y]))

Solution (Python):
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)
r.sort(reverse=True)


taberu = p[0:X] + q[0:Y] + r
taberu.sort(reverse=True)

print(sum(taberu[0:X+Y]))

Solution (Python):
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)
r.sort(reverse=True)


taberu = p[0:X] + q[0:Y] + r
taberu.sort(reverse=True)

print(sum(taberu[0:X+Y]))

Solution (Python):
X,Y,A,B,C = list(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)

taberu = p[0:X] + q[0:Y] + r
taberu.sort(reverse=True)

print(sum(taberu[0:X+Y]))

Solution (Python):
x,y,a,b,c = list(map(int, input().split(' ')))
p = sorted(list(map(int, input().split(' '))))[-x:]
q = sorted(list(map(int, input().split(' '))))[-y:]
r = sorted(list(map(int, input().split(' '))))[-x-y:]

z = sorted(p+q+r)[-x-y:]

print (sum(z))

Solution (Python):
x, y, a, b, c = map(int, input().split())
red = list(map(int, input().split()))
green = list(map(int, input().split()))
colorless = list(map(int, input().split()))

red.sort(reverse=True)
green.sort(reverse=True)
colorless.sort(reverse=True)

red = red[:x]
green = green[:y]

l = red + green + colorless
l.sort(reverse=True)
ans = sum(l[:x + y])
print(ans)

Solution (Python):
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)
r.sort(reverse=True)


taberu = p[0:X] + q[0:Y] + r
taberu.sort(reverse=True)

print(sum(taberu[0:X+Y]))

Solution (Python):
X,Y,A,B,C = list(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)

taberu = p[0:X] + q[0:Y] + r
taberu.sort(reverse=True)

print(sum(taberu[0:X+Y]))

Solution (Python):


def mergef(a,b):
    c = []
    h = j = 0
    while j<len(a) and h<len(b):
        if a[j]>b[h]:
            c.append(a[j])
            j+=1
        else:
            c.append(b[h])
            h+=1
    if j==len(a):
        for i in b[h:]:
            c.append(i)
    else:
        for i in a[j:]:
            c.append(i)
    return c

def merge_sortf(lists):
    if len(lists) <= 1:
        return lists
    middle = int(len(lists)/2)
    left = merge_sortf(lists[:middle])
    right = merge_sortf(lists[middle:])
    return mergef(left,right)


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

pm=merge_sortf(p)
qm=merge_sortf(q)
rm=merge_sortf(r)

k=0;i=X-1;j=Y-1
while i>=0 and j>=0 and k<C:
    if min((pm[i]-rm[k]),(qm[j]-rm[k])) < 0 :
        if pm[i]>=qm[j] :
            qm[j]=rm[k]
            if j>0:
                j=j-1
        elif pm[i]<qm[j]:
            pm[i]=rm[k]
            if i>0:
                i=i-1
    elif min((pm[i]-rm[k]),(qm[j]-rm[k])) > 0:
        break
    k=k+1

ans=sum(pm[:X])+sum(qm[:Y])
print(ans)

Solution (Python):


x, y, a, b, c = map(int,input().split())
L = []
Pa = list(map(int,input().split()))
Pb = list(map(int,input().split()))
Pc = list(map(int,input().split()))
Pa.sort(reverse = True)
Pb.sort(reverse = True)
Pc.sort(reverse = True)

ca = 0
cb = 0
cc = 0
flg1 = True
flg2 = True
flg3 = True
ans = 0
for i in range(x+y):
    if ca == x:
        flg1 = False
        ca = 0
        Pa[ca] = 0
    if cb == y:
        flg2 = False
        cb = 0
        Pb[cb] = 0
    if cc == c:
        flg3 = False
        cc = 0
        Pc[cc] = 0
    if Pa[ca] == max(Pa[ca], Pb[cb], Pc[cc]) and flg1:
        ans += Pa[ca]
        ca += 1
    elif Pb[cb] == max(Pa[ca], Pb[cb], Pc[cc]) and flg2:
        ans += Pb[cb]
        cb += 1
    elif Pc[cc] == max(Pa[ca], Pb[cb], Pc[cc]) and flg3:
        ans += Pc[cc]
        cc += 1
        

print(ans)

Solution (Python):
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)
ans = []
for i in range(x):
    ans.append(A[i])
for i in range(y):
    ans.append(B[i])
for i in range(c):
    ans.append(C[i])
ans.sort(reverse=True)
anss = 0
for i in range(x+y):
    anss += ans[i]
print(anss)

Solution (Python):


from collections import deque


X, Y, A, B, C = map(int, input().split())
red_apples = sorted(list(map(int, input().split())), reverse=True)
green_apples = sorted(list(map(int, input().split())), reverse=True)
mushoku_apples = list(map(int, input().split()))


red_apples = red_apples[:X]
green_apples = green_apples[:Y]
ans_list = deque([])


for r in red_apples:
    ans_list.append(r)
for g in green_apples:
    ans_list.append(g)
for m in mushoku_apples:
    ans_list.append(m)
ans_list = sorted(ans_list, reverse=True)


ans = sum(ans_list[:X+Y])
print(ans)

Solution (Python):
import heapq
x,y,a,b,c=map(int,input().split())
def _int(x):
    return -int(x)
p=list(map(_int,input().split()))
q=list(map(_int,input().split()))
r=list(map(_int,input().split()))
heapq.heapify(p)
heapq.heapify(q)
heapq.heapify(r)

ans=[]
heapq.heapify(ans)
for i in range(x):
    _p=heapq.heappop(p)
    heapq.heappush(ans,-_p)
for i in range(y):
    _q=heapq.heappop(q)
    heapq.heappush(ans,-_q)

for i in range(x+y):
    if len(r)==0:break
    _ans=heapq.heappop(ans)
    _r=-heapq.heappop(r)
    if _r>=_ans:
        heapq.heappush(ans,_r)
    else:
        heapq.heappush(ans,_ans)
        break
print(sum(ans))

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

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

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

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

ans=sum(lst[:X+Y])
print(ans)

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

Solution (Python):
import sys


def input():
    return sys.stdin.readline().strip()


x, y, a, b, c = map(int, input().split())
P = sorted(list(map(int, input().split())), reverse=True)[:x]
Q = sorted(list(map(int, input().split())), reverse=True)[:y]
R = list(map(int, input().split()))

print(sum(sorted(P + Q + R, reverse=True)[:x + y]))

Solution (Python):
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)
s = P[:X]+Q[:Y]+R
s.sort(reverse=True)
        
print(sum(s[:X+Y]))

Solution (Python):
import sys
import numpy as np

from collections import deque 
from functools import reduce



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)

p_np = np.zeros(999999)
q_np = np.zeros(999999)

if len(p) > x:
    p_np[:x] = p[:x]
else:
    l_p = len(p)
    p_np[:l_p] = p[:]

if len(q) > y:
    q_np[:y] = q[:y]
else:
    l_q = len(q)
    q_np[:l_q] = q[:]
ap_np = np.hstack((p_np[:x], q_np[:y]))
ap_np.sort()
ap_cnt = 0

for i, ri in enumerate(r):
    if i >= x + y:
        break
    if (r[i] > ap_np[i]):
        ap_np[i] = r[i]
print(int(ap_np.sum()))

Solution (Python):
x, y, a, b, c = map(int, input().split())
print(sum(sorted(
    sorted(int(x) for x in input().split())[-x:] +
    sorted(int(x) for x in input().split())[-y:] +
    [int(x) for x in input().split()])[-(x+y):]))

Solution (Python):
import heapq
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 = sorted(list(map(lambda x:int(x),input().split())),reverse=True)

p = sorted(p)[a - x:a]
q = sorted(q)[b - y:b]
p+=q
p.sort()

for i in range(min(len(r),len(p))):
    p[i] = max(p[i],r[i])
print(sum(p))

Solution (Python):
x, y, a, b, c = map(int, input().split())
red = [int(x) for x in input().split()]
green = [int(x) for x in input().split()]
red.sort(reverse=True)
green.sort(reverse=True)
candidates = [int(x) for x in input().split()] + red[:x] + green[:y]
candidates.sort(reverse=True)
print(sum(candidates[:x+y]))

Solution (Python):
x, y, a, b, c = map(int, input().split())
red = [int(x) for x in input().split()]
green = [int(x) for x in input().split()]
red.sort(reverse=True)
green.sort(reverse=True)
candidates = [int(x) for x in input().split()] + red[:x] + green[:y]
candidates.sort(reverse=True)
print(sum(candidates[:x+y]))

Solution (Python):
x, y, a, b, c = map(int, input().split())
red = [int(x) for x in input().split()]
green = [int(x) for x in input().split()]
red.sort()
green.sort()
candidates = [int(x) for x in input().split()] + red[-x:] + green[-y:]
candidates.sort()
print(sum(candidates[-x-y:]))

Solution (Python):
x, y, a, b, c = map(int, input().split())
red = [int(x) for x in input().split()]
green = [int(x) for x in input().split()]
red.sort()
green.sort()
candidates = [int(x) for x in input().split()] + red[-x:] + green[-y:]
candidates.sort()
print(sum(candidates[-x-y:]))

Solution (Python):
x, y, a, b, c = map(int, input().split())
red = [int(x) for x in input().split()]
green = [int(x) for x in input().split()]
red.sort()
green.sort()
candidates = [int(x) for x in input().split()] + red[-x:] + green[-y:]
candidates.sort()
print(sum(candidates[-x-y:]))

Solution (Python):
x, y, a, b, c = map(int, input().split())
red = [int(x) for x in input().split()]
green = [int(x) for x in input().split()]
red.sort(reverse=True)
green.sort(reverse=True)
candidates = [int(x) for x in input().split()] + red[:x] + green[:y]
candidates.sort(reverse=True)
print(sum(candidates[:x+y]))

Solution (Python):
x, y, a, b, c = map(int, input().split())
red = sorted(int(x) for x in input().split())[-x:]
green = sorted(int(x) for x in input().split())[-y:]
print(sum(sorted([int(x) for x in input().split()] + red + green)[-(x+y):]))

Solution (Python):
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)
c_apple = p[0:x] + q[0:y]
c_apple.sort()
for i in range(len(r)):
    if c_apple[i] < r[i]:
        c_apple[i] = r[i]
    else:
        break
print(sum(c_apple))

Solution (Python):
X,Y,A,B,C = map(int,input().split())
p = input().split()
q = input().split()
r = input().split()
p = [int(val) for val in p]
q = [int(val) for val in q]
r = [int(val) for val in r]
p.sort()
q.sort()
p_candidate = p[len(p)-X::]
q_candidate = q[len(q)-Y::]
candidate = []
candidate.extend(p_candidate)
candidate.extend(q_candidate)
candidate.extend(r)
candidate.sort()
print(sum(candidate[len(candidate)-X-Y::]))

Solution (Python):
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
setrecursionlimit(1000000)


INF = int(1e10)

def input():
    return stdin.readline()[:-1]

def main():
    from builtins import int, map
    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)

    ans = 0
    v = p[:X] + q[:Y]
    v.sort()
    w = 0
    for i in range(min(X + Y, C)):
        if v[i] < r[w]:
            v[i] = r[w]
            w += 1
    print(sum(v))


if __name__ == '__main__':
    main()

Solution (Python):


from collections import deque


X, Y, A, B, C = map(int, input().split())
red_apples = sorted(list(map(int, input().split())), reverse=True)
green_apples = sorted(list(map(int, input().split())), reverse=True)
mushoku_apples = sorted(list(map(int, input().split())), reverse=True)


red_apples = red_apples[:X]
green_apples = green_apples[:Y]
ans_list = deque([])
for r in red_apples:
    ans_list.append(r)
for g in green_apples:
    ans_list.append(g)
for m in mushoku_apples:
    ans_list.append(m)
ans_list = sorted(ans_list, reverse=True)


i = X+Y
ans = sum(ans_list[:i])
print(ans)

Solution (Python):
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()))
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)
res = P[:x] + Q[:y]
heapq.heapify(res)

for i in range(c):
    tmp_min = heapq.heappop(res)
    tmp_r = R[i]
    if tmp_r > tmp_min:
        heapq.heappush(res, tmp_r)
    else:
        heapq.heappush(res, tmp_min)
print(sum(res))

Solution (Python):
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()))
ps = sorted(p,reverse=True)[:X]
qs = sorted(q,reverse=True)[:Y]
r.extend(ps)
r.extend(qs)
rs = sorted(r,reverse=True)
deli = 0
for i in range(0,X+Y):
    deli = deli + rs[i]
print(deli)

Solution (Python):
x,y,a,b,c = map(int,input().split())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))

A = A[::-1][:x]
B = B[::-1][:y]
C = C[::-1]
D = A+B+C
D.sort(reverse = True)
print(sum(D[:x+y]))

Solution (Python):
import sys

input = sys.stdin.buffer.readline

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)
ans = p[:x]
ans[x:x] = q[:y]
ans += r
ans = sorted(ans,reverse=True)
print(sum(ans[:x+y]))

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

ans = p[:x] + q[:y] + r[:x+y]
ans.sort(reverse=True)

print(sum(ans[:x+y]))

Solution (Python):
import sys
sys.setrecursionlimit(15000)
x,y,a,b,c = map(int,input().split())
p = list(sorted(map(int,input().split()),reverse=True))[:x] 
q = list(sorted(map(int,input().split()),reverse=True))[:y] 
r = list(sorted(map(int,input().split()),reverse=True))
print(sum(sorted(p+q+r,reverse=True)[:x+y]))

Solution (Python):
x, y, a, b, c = map(int, input().split())
p_array = list(map(int, input().split()))
q_array = list(map(int, input().split()))
r_array = list(map(int, input().split()))
apple = []
p_array.sort()
q_array.sort()
for _ in range(x):
    apple.append((p_array.pop(), 1))
for _ in range(y):
    apple.append((q_array.pop(), 2))
for r in r_array:
    apple.append((r, 0))
apple.sort()
print(sum(map(lambda z: z[0], apple[-(x + y):])))

Solution (Python):
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
p = p[A-X:]
q = list(map(int, input().split()))
q.sort()
q = q[B-Y:]
r = list(map(int, input().split()))
apple = p+q+r
apple.sort()
print(sum(apple[len(apple)-X-Y:]))

Solution (Python):



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)

p_s = p[:x]
q_s = q[:y]

new = p_s + q_s + r
new.sort(reverse=True)

print(sum(new[:x+y]))

Solution (Python):
def solve():
    X,Y,A,B,C = map(int, input().split())

    red = list(map(int, input().split()))
    red.sort(reverse=True)

    green = list(map(int, input().split()))
    green.sort(reverse=True)

    colorless = list(map(int, input().split()))
    colorless.sort(reverse=True)

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

    colorless_idx = 0
    for i in range(X+Y-1, -1, -1):
        if chosen[i] < colorless[colorless_idx]:
            chosen[i] = colorless[colorless_idx]
            colorless_idx += 1
        if colorless_idx == C:
            break
        
    print(sum(chosen))



if __name__ == '__main__':
    solve()

Solution (Python):
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)
s = p[:x] + q[:y] + r
s.sort(reverse=True)
print(sum(s[:x+y]))

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

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

Solution (Python):
import sys,math,copy,queue,itertools
from fractions import gcd
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
INF = 10**18
MOD = 10**9 + 7
DD = ((1,0),(0,1),(-1,0),(0,-1))
X,Y,A,B,C = LI()
p = sorted(LI(),reverse=True)[:X]
q = sorted(LI(),reverse=True)[:Y]
r = sorted(LI(),reverse=True)[:X+Y]

pq = sorted(p + q)
ans = sum(pq)

for i in range(len(r)):
    if pq[i] < r[i]:
        ans += r[i] - pq[i]
    else:
        break

print (ans)

Solution (Python):
X,Y,A,B,C=map(int,input().split())
a=sorted(list(map(int,input().split())),reverse=True)
b=sorted(list(map(int,input().split())),reverse=True)
c=sorted(list(map(int,input().split())))
ans=sum(sorted(a[0:X]+b[0:Y]+c,reverse=True)[0:(X+Y)])
print(ans)

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

red = [0] + list(map(int,input().split()))
red.sort()
green = [0] + list(map(int,input().split()))
green.sort()
colorless = [0] + list(map(int,input().split()))
colorless.sort()



z = x + y
deliscious = 0
countx = 0
county = 0
for i in range(z):
    p = red[len(red)-1]
    q = green[len(green)-1]
    r = colorless[len(colorless)-1]
    
    if p >= q and p > r and countx < x:
        deliscious += p
        red.pop()
        countx += 1
    elif q >= p and q > r and county < y:
        deliscious += q
        green.pop()
        county += 1
    else:
        deliscious += r
        colorless.pop()
    if countx == x:
        red.append(0)
        countx += 1
    if county == y:
        green.append(0)
        county += 1
        
    
    
    
print(deliscious)

Solution (Python):
import sys
input = sys.stdin.readline

x, y, a, b, c = map(int, input().split())
red = list(map(int, input().split()))
gre = list(map(int, input().split()))
tra = list(map(int, input().split()))

red = sorted(red)[-x:]
gre = sorted(gre)[-y:]
uni = tra + red + gre

ans = sum(sorted(uni)[-(x+y):])
print(ans)

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


p = p[:x]
q = q[:y]


p.sort()
q.sort()


r.sort(reverse=True)


d = []

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

print(sum(d[: x + y]))

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

l=sorted(p,reverse=True)[:x]+sorted(q,reverse=True)[:y]+r
l.sort(reverse=True)
print(sum(l[:x+y]))

Solution (Python):
X, Y, A, B, C = map(int, input().split())
p = sorted(list(map(int, input().split())))[-X:]
q = sorted(list(map(int, input().split())))[-Y:]
r = sorted(list(map(int, input().split())))
print (sum(sorted(p+q+r)[-X-Y:]))

Solution (Python):
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()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
candidates = []
for i in range(X):
    candidates.append(-1 * p[i])
for i in range(Y):
    candidates.append(-1 * q[i])
for i in range(C):
    candidates.append(-1 * r[i])
heapq.heapify(candidates)
ans = 0
for _ in range(X + Y):
    val = heapq.heappop(candidates)
    ans += val
print(-ans)

Solution (Python):
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()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
candidates = []
for i in range(X):
    candidates.append(-1 * p[i])
for i in range(Y):
    candidates.append(-1 * q[i])
for i in range(C):
    candidates.append(-1 * r[i])
heapq.heapify(candidates)
ans = 0
for _ in range(X + Y):
    val = heapq.heappop(candidates)
    ans += val
print(-ans)

Solution (Python):
X, Y, A, B, C = map(int, input().split())
p = [int(a) for a in input().split()]
q = [int(a) for a in input().split()]
r = [int(a) for a in input().split()]
s = []

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

p = p[:X]
q = q[:Y]
s = p + q + r
s.sort(reverse=True)

s = s[:(X + Y)]
        
print(sum(s))

Solution (Python):
def resolve():
    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(p[:X] + q[:Y] + list(map(int, input().split())), reverse=True)
    print(sum(r[:X+Y]))

resolve()

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

ans = p[:X]+q[:Y]+r[:X+Y]
ans.sort(reverse=True)
su = sum(ans[:X+Y])

print(su)

Solution (Python):
X, Y, A, B, C = map(int, input().split())

pList = list(map(int, input().split()))
qList = list(map(int, input().split()))
rList = list(map(int, input().split()))

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

pList = pList[:X]
qList = qList[:Y]

appleList = pList + qList + rList
appleList.sort(reverse=True)
appleList = appleList[:X+Y]

print(sum(appleList))

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

memo = []

for i in range(x):
    memo.append(p[i])
for j in range(y):
    memo.append(q[j])
for k in r:
    memo.append(k)

memo.sort(reverse=True)
ans = 0

for l in range(x+y):
    ans += memo[l]
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

rl = lambda: list(map(int, input().split()))

x, y, a, b, c = rl()
p = rl()
q = rl()
r = rl()
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
res = sum(sorted(p[:x] + q[:y] + r, reverse=True)[:x+y])
print(res)

Solution (Python):
import sys


rl = lambda: list(map(int, input().split()))

x, y, a, b, c = rl()
p = rl()
q = rl()
r = rl()
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
res = sum(sorted(p[:x] + q[:y] + r, reverse=True)[:x+y])
print(res)

Solution (Python):
import sys
input = sys.stdin.readline

rl = lambda: list(map(int, input().split()))

x, y, a, b, c = rl()
p = rl()
q = rl()
r = rl()
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
res = sum(sorted(p[:x] + q[:y] + r, reverse=True)[:x+y])
print(res)

Solution (Python):
X, Y, A, B, C = map(int, input().split())
p = [int(n) for n in input().split()]
q = [int(n) for n in input().split()]
r = [int(n) for n in input().split()]
p.sort(reverse=True)
q.sort(reverse=True)
px = p[0: X]
qx = q[0: Y]
t = px + qx + r
t.sort(reverse=True)
print(sum(t[0: X + Y]))

Solution (Python):

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)

s = p[:X] + q[:Y] + r

s.sort(reverse = True)
answer = sum(s[:X+Y])    

print(answer)

Solution (Python):
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)
 
mazemaze =p[:x]+q[:y]+r
list.sort(mazemaze, reverse=True)
print(sum(mazemaze[:x+y]))

Solution (Python):
x, y, aa, bb, cc, = 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)

ary = a[:x] + b[:y] + c
ary.sort(reverse=True)
print (sum(ary[:x+y]))