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):
import numpy as np
X, Y, A, B, C = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

A = A[0:X]
B = B[0:Y]
D = A+B+C

D.sort(reverse=True)

D = D[0:X+Y]
print(sum(D))

Solution (Python):
X,Y,A,B,C=map(int,input().split())
P=sorted([int(x) for x in input().split()])
Q=sorted([int(x) for x in input().split()])
R=sorted([int(x) for x in input().split()],reverse=True)

p=A-X
q=B-Y

final=sorted(P[p:]+Q[q:])

ans=sum(final)

i=0

for item in R:
	if item > final[i]:
		ans-=final[i]
		ans+=item
		i+=1

print(ans)

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

Pi.sort()
Qi.sort()
Ri.sort(reverse=True)




r=0
p=A-X
q=B-Y
while(r<C):
  if(p>=A and q>=B):
    break
  elif(p>=A):
    
    if(Qi[q]>=Ri[r]):
      break;
    else:
      Qi[q]=Ri[r]
      q+=1
  elif(q>=B):
    
    if(Pi[p]>=Ri[r]):
      break;
    else:
      Pi[p]=Ri[r]
      p+=1
  elif(Pi[p]>=Qi[q]):
    
    if(Qi[q]>=Ri[r]):
      break;
    else:
      Qi[q]=Ri[r]
      q+=1
  elif(Pi[p]<Qi[q]):
    
    if(Pi[p]>=Ri[r]):
      break;
    else:
      Pi[p]=Ri[r]
      p+=1
  elif(Pi[p]>=Ri[r] and Qi[q]>=Ri[r]):
    break
  
  r+=1

psum=sum(Pi[A-X:A])
qsum=sum(Qi[B-Y:B])


happy = psum + qsum

print(happy)

Solution (Python):
X,Y,A,B,C=map(int,input().split())
D=[sorted(int(x) for x in input().split()) for _ in range(3)]

print(sum(sorted(D[0][-X:]+D[1][-Y:]+D[2])[-(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()
p.reverse()
q.sort()
q.reverse()
r.sort()
r.reverse()
total=[]
for i in range(X):
    total.append(p[i])
for i in range(Y):
    total.append(q[i])
for i in range(C):
    total.append(r[i])
total.sort()
total.reverse()
ans=0
for i in range(X+Y):
    ans+=total[i]
print(ans)

Solution (Python):
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]

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

Solution (Python):
X,Y,A,B,C=map(int,input().split())
import numpy as np
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
R=list(map(int,input().split()))
Xa=np.array(P+Q+R)
Ya=np.array([i for i,j in enumerate([A,B,C]) for k in range(j)])
x = np.argsort(Xa)
Xa=Xa[x]
Xa=Xa[::-1]
Ya=Ya[x]
Ya=Ya[::-1]
ans=0
N=0
nokori=[X,Y]
for i in range(A+B+C):
  if Ya[i]==2:
    N+=1
    ans+=Xa[i]
  elif nokori[Ya[i]]>0:
    nokori[Ya[i]]-=1
    ans+=Xa[i]
  if sum(nokori)==N:
    break
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)
P=p[0:X]
Q=q[0:Y]
N=P+Q+r
N.sort(reverse=True)
print(sum(N[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)
a = p[:x] + q[:y] + r
a.sort(reverse = True)
print(sum(a[:(x+y)]))

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(reverse = True)
q.sort(reverse = True)

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

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

ans = 0

for i in range(x + y):
  ans += p[i]
  
print("{}".format(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)

num = []
n1 = 0
n2 = 0
n3 = 0
flg_0 = False
flg_1 = False
flg_2 = False
for i in range(x+y):
    if flg_0 is False:
        u = p[min(a-1, n1)]
    else:
        u = 0
    if flg_1 is False:
        uu = q[min(b-1, n2)]
    else:
        uu = 0
    if flg_2 is False:
        uuu = r[min(c-1, n3)]
    else:
        uuu = 0
    if max(u, uu, uuu) == u:
        num.append(u)
        n1 += 1
    elif max(u, uu, uuu) == uu:
        num.append(uu)
        n2 += 1
    else:
        num.append(uuu)
        n3 += 1
    if n1 >= x:
        flg_0 = True
    if n2 >= y:
        flg_1 = True
    if n3 >= c:
        flg_2 = True
    if (n1 + n2 + n3) == (x + y):
        break

print(sum(num))

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 = sorted(p, reverse=True)[:X]
q = sorted(q, reverse=True)[:Y]

ans = sum(sorted((p + q + r), reverse=True)[:X + Y])
print(ans)

Solution (Python):
from heapq import heappush, heappop, heapify

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

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)

heap = []
heapify(heap)

for a in PA[:X]:
    heappush(heap, -a)

for a in PB[:Y]:
    heappush(heap, -a)

for a in PC:
    heappush(heap, -a)

cnt = 0
sum_ = 0
while cnt < X + Y:
    val = heappop(heap)
    sum_ += val * -1

    cnt += 1


print(sum_)

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:]
r.extend(p)
r.extend(q)
r.sort()
print(sum(r[-(X + Y):]))

Solution (Python):
import sys
sys.setrecursionlimit(10**7)

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

pi = [int(i) for i in input().split()]
qi = [int(i) for i in input().split()]
ri = [int(i) for i in input().split()]

pi.sort(reverse=True)
qi.sort(reverse=True)
ri.sort(reverse=True)

import heapq
"""
a = [3,0,2,6]


heapq.heapify(a)
print(a)


heapq.heappush(a,3)
print(a)


print(heapq.heappop(a))
print(a)
"""
apple = []

for i in range(x):
    heapq.heappush(apple,pi[i])
    
for i in range(y):
    heapq.heappush(apple,qi[i])
    
for i in range(c):
    tmp = heapq.heappop(apple)
    if tmp < ri[i]:
        heapq.heappush(apple,ri[i])
    else:
        heapq.heappush(apple,tmp)
        
print(sum(apple))

Solution (Python):
import heapq

def main():
    x, y, a, b, c = map(int, input().split())
    p = sorted(list(map(int, input().split())))
    p = [p[i] for i in range(-x, 0)]
    q = sorted(list(map(int, input().split())))
    q = [q[i] for i in range(-y, 0)]
    r = sorted(list(map(int, input().split())), reverse=True)
    for i in range(c):
        red = heapq.heappop(p)
        green = heapq.heappop(q)
        if r[i] <= red and r[i] <= green:
            heapq.heappush(p, red)
            heapq.heappush(q,green)
            break
        else:
            if r[i] - red >= r[i] - green:
                heapq.heappush(p, r[i])
                heapq.heappush(q,green)
            else:
                heapq.heappush(q, r[i])
                heapq.heappush(p, red)
    print(sum(p)+sum(q))

if __name__ == '__main__':
    main()

Solution (Python):
import sys
from itertools import accumulate
import heapq
x, y, a, b, c = [int(i) for i in sys.stdin.readline().split()]
ps = [int(i) for i in sys.stdin.readline().split()]
qs = [int(i) for i in sys.stdin.readline().split()]
rs = [int(i) for i in sys.stdin.readline().split()]
ls = []
for p in ps:
    heapq.heappush(ls, (-p, 0))
for q in qs:
    heapq.heappush(ls, (-q, 1))
for r in rs:
    heapq.heappush(ls, (-r, 2))
ans = 0
cnt = 0
x_cnt = 0
y_cnt = 0
while cnt < x + y:
    item = heapq.heappop(ls)
    if item[1] == 2:
        ans -= item[0]
        cnt += 1
    elif item[1] == 0:
        if x_cnt >= x:
            continue
        else:
            x_cnt += 1
            cnt += 1
            ans -= item[0]
    else:
        if y_cnt >= y:
            continue
        else:
            y_cnt += 1
            cnt += 1
            ans -= item[0]
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)

l=p[:x]+q[:y]+r
l.sort(reverse=True)
print(sum(l[: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)
tmp=[]
for i in range(x):
    tmp.append(p[i])

for j in range(y):
    tmp.append(q[j])

for k in range(len(r)):
    tmp.append(r[k])

tmp.sort(reverse=True)
ans=0
for i in range(x+y):
    ans+=tmp[i]

print(ans)

Solution (Python):
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 = sorted(list(map(int, input().split())), reverse=True)
M = sorted(P+Q+R, reverse=True)
print(sum(M[:x+y]))

Solution (Python):
import sys
import math
import numpy

x , y , a , b , c = map(int,input().split())
pa = list(map(int,input().split()))
pb = list(map(int,input().split()))
pc = list(map(int,input().split()))

pa.sort()
pb.sort()
pc.sort()

if x <= a:
    pa = pa[a-x::]
    a = x
if y <= b:
    pb = pb[b-y::]
    b = y
if x+y <= c:
    
    pc = pc[(c-(x+y))::]
    c = x+y

ain = 0
bin = 0
cin = 0

total = 0
for times in range(x+y):
    if ain < a:
        ta = pa[a-1 - ain ]
    else:
        ta = 0
    
    if bin < b :
        tb = pb[b-1 - bin]
    else:
        tb = 0
    
    if cin < c:
        tc = pc[c-1 - cin]
    else:
        tc = 0
    
    if tb <= ta and tc <= ta:
        total += ta
        ain += 1
    elif ta <= tb and tc <= tb:
        total += tb
        bin += 1
    elif ta <= tc and tb <= tc:
        total += tc
        cin += 1
    else:
        print("error")

print(total)

Solution (Python):
from collections import deque

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

s = p[:X] + q[:Y] + 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 = sorted(P,reverse=True)
Q = sorted(Q,reverse=True)
R = sorted(R,reverse=True)
P = P[:X]
Q = Q[:Y]
P.append(-100)
Q.append(-100)
R.append(-100)

ans = sum(P)+sum(Q)

p=0
q=0
r=0

x = 0
y = 0

ans = 0
while(x<=X or y<=Y):
    mm = max(P[p],Q[q],R[r])
    if R[r] == mm:
        ans += R[r]
        r+=1
    elif P[p]==mm:
        ans += P[p]
        p+=1
        x+=1
    elif Q[q]==mm:
        ans += Q[q]
        q+=1
        y+=1
    if (x+y+r)==(X+Y):
        break
    

print(ans)

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

p_dat = list(map(int, input().split()))
q_dat = list(map(int, input().split()))
r_dat = list(map(int, input().split()))

p_max_list = sorted(p_dat, reverse=True)
p_max_list = p_max_list[0:X]
q_max_list = sorted(q_dat, reverse=True)
q_max_list = q_max_list[0:Y]

join_list = p_max_list + q_max_list + r_dat
join_list = sorted(join_list, reverse=True)
join_list = join_list[0:(X+Y)]

print(sum(join_list))

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)
P = P[:X]
Q = Q[:Y]
P.append(-100)
Q.append(-100)
R.append(-100)

ans = sum(P)+sum(Q)

p=0
q=0
r=0

x = 0
y = 0

ans = 0
while(x<=X or y<=Y):
    mm = max(P[p],Q[q],R[r])
    if R[r] == mm:
        ans += R[r]
        r+=1
    elif P[p]==mm:
        ans += P[p]
        p+=1
        x+=1
    elif Q[q]==mm:
        ans += Q[q]
        q+=1
        y+=1
    if (x+y+r)==(X+Y):
        break
    

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()
q.sort()
ans=[]
for i in range(X):
    a=i+1
    ans.append(p[-a])
for i in range(Y):
    a=i+1
    ans.append(q[-a])
for i in r:
    ans.append(i)
ans.sort()
Ans=0
for i in range(X+Y):
    a=i+1
    Ans+=ans[-a]
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)

pqr = []

for i in range(x):
    pqr.append(p[i])
for i in range(y):
    pqr.append(q[i])
for i in range(c):
    pqr.append(r[i])

pqr.sort(reverse=True)

delicious = 0
for i in range(x+y):
    delicious += pqr[i]

print(delicious)

Solution (Python):
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))[:min(C, X+Y)]

pq = np.hstack((p, q, r))
pq.sort()
print(sum(pq[-(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)
eat=p[:X]+q[:Y]+r
eat.sort(reverse=True)
eat=eat[:(X+Y)]
print(sum(eat))

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)

p = p[:X]
q = q[:Y]
s = sorted(p+q+r,reverse=True)[: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 = sorted(p, reverse=True)[:X]
q = sorted(q, reverse=True)[:Y]
t = sorted(p+q+r, reverse=True)[:X+Y]
print (sum(t))

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)

a = []
a.extend(p[:x])
a.extend(q[:y])
a.extend(r)
a.sort(reverse=True)

print(sum(a[: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)
pp = p[:x]
qq = q[:y]
if x+y <= c:
  rr = r[:(x+y)]
else:
  rr = r
ppqqrr = pp + qq + rr
ppqqrr.sort(reverse = True)
print(sum(ppqqrr[: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)[:x]
q = sorted(q, reverse=True)[:y]

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

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)
qs=sorted(q,reverse=True)
pn=ps[:x]
qn=qs[:y]
nl=sorted(pn+qn+r,reverse=True)
print(sum(nl[:x+y]))

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

P = list( map(int, input().split()))
Q = list( map(int, input().split()))
R = list( map(int, input().split()))

PQ = [(p,0) for p in P] + [(q,1) for q in Q]
PQ.sort(key=lambda x:x[0])
R.sort()
x=0
y=0
z=0
ans = 0
while x+y+z < X+Y:
    if R and PQ[-1][0] < R[-1]:
        ans += R.pop()
        z+=1
    else:
        tmp, label = PQ.pop()
        if label == 0 and x < X:
            ans+=tmp
            x+=1
        elif label == 1 and y < Y:
            ans+=tmp
            y+=1

print(ans)

Solution (Python):

X, Y, A, B, C = map(int, input().split())
P = [int(x) for x in input().split()]
Q = [int(x) for x in input().split()]
R = [int(x) for x in input().split()]


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

def eat(idx):
    p = -1 if idx[0] == X else P[idx[0]]
    q = -1 if idx[1] == Y else Q[idx[1]]
    r = -1 if idx[2] == C else R[idx[2]]

    if p > q:
        if p > r:
            idx[0] += 1
            return p 
        else:
            idx[2] += 1
            return r
    else:
        if q > r:
            idx[1] += 1
            return q
        else:
            idx[2] += 1
            return r

ans = 0
idx = [0, 0, 0]
while True:
    ans += eat(idx)
    if sum(idx) == X+Y:
        break


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

pqr = p + q + r
pqr = sorted(pqr, reverse = True)[:x+y]

print(sum(pqr))

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):
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))[:min(C, X+Y)]

pq = np.hstack((p, q))
pq.sort()
ri = 0
for i, t in enumerate(pq):
    if t < r[ri]:
        pq[i] = r[ri]
        ri += 1
    if ri == len(r):
        break
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()))
p.sort()
p.reverse()
q.sort()
q.reverse()
r.sort()
r.reverse()
xp,yq = p[:X],q[:Y]
xp.extend(yq)
xp.extend(r)
xp.sort()
xp.reverse()
print(sum(xp[:(X+Y)]))

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= list(map(int,input().split()))
P=P[0:X]
Q=Q[0:Y]
R.extend(P)
R.extend(Q)
R=sorted(R,reverse=True)
ans = 0
for i in range(X+Y):
    ans+=R[i]
print(ans)

Solution (Python):
import sys
input=sys.stdin.readline
x,y,a,b,c=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
arr3=list(map(int,input().split()))
arr1.sort(reverse=True)
arr2.sort(reverse=True)
sum=0
for i in range(x):
    arr3.append(arr1[i])
for j in range(y):
    arr3.append(arr2[j])
arr3.sort(reverse=True)
for k in range(x+y):
    sum+=arr3[k]
print(sum)

Solution (Python):
import sys
input=sys.stdin.readline
x,y,a,b,c=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
arr3=list(map(int,input().split()))
arr1.sort(reverse=True)
arr2.sort(reverse=True)
sum=0
for i in range(x):
    arr3.append(arr1[i])
for j in range(y):
    arr3.append(arr2[j])
arr3.sort(reverse=True)
for k in range(x+y):
    sum+=arr3[k]
print(sum)

Solution (Python):






from sys import stdin,setrecursionlimit


import heapq







setrecursionlimit(10**6+1)
input=stdin.readline

def main():
    x,y,a,b,c=map(int,input().split())
    p=sorted([int(i) for i in input().split()],reverse=1)[:x]
    q=sorted([int(i) for i in input().split()],reverse=1)[:y]
    r=[int(i) for i in input().split()]
    print(sum(sorted(p+q+r,reverse=1)[:x+y]))

if __name__=="__main__":
    main()

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 = list(map(int, input().split()))

total = sorted(P + Q + R)[-X-Y:]
print(sum(total))

Solution (Python):
x,y,a,b,c=map(int,input().split())
print(sum(sorted(sorted(list(map(int,input().split())))[-x:]+sorted(list(map(int,input().split())))[-y:]+list(map(int,input().split())))[-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)
P=P[:x]
Q.sort(reverse=True)
Q=Q[:y]
P=P+Q
P.sort()
R.sort(reverse=True)
for i in range(min(x+y,c)):
    if P[i]<R[i]:
        P[i]=R[i]
    else:
        break
print(sum(P))

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)

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

for i in range(c):
    if r[i] > ans1[i]:
        ans1[i] = r[i]
    else:
        break

print(sum(ans1))

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

x,y,a,b,c = map(int,readline().split())
p = list(map(int,readline().split()))
q = list(map(int,readline().split()))
r = list(map(int,readline().split()))

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

def cumsum(lst): 
    res = lst[:]
    for i in range(1,len(res)):
        res[i] += res[i-1]
    return res
cum_p = cumsum(p)
cum_q = cumsum(q)
ans = 0
for i in range(max(0,a-c),a+1): 
    if i == 0:
        ans = max(ans,cum_q[x+y-i-1])
    else:
        ans = max(ans,cum_p[i-1] + cum_q[x+y-i-1])

print(ans)

Solution (Python):
x, y, a, b, c = map(int,input().split())
datp = sorted(list(map(int, input().split())), reverse=True)
datq = sorted(list(map(int, input().split())), reverse=True)
datr = sorted(list(map(int, input().split())), reverse=True)
dat = sorted(datp[:x] + datq[:y] + datr, reverse=True)
print(sum(dat[:x+y]))

Solution (Python):



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


p = sorted([int(i) for i in input().split()])
q = sorted([int(i) for i in input().split()])
r = sorted([int(i) for i in input().split()])

l = p[A - X:] + q[B - Y:] + r

print(sum(sorted(l)[(X+Y) * -1:]))

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)

apples=[]
apples.extend(p[:x])
apples.extend(q[:y])
apples.extend(r)

apples.sort(reverse=True)

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

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

Solution (Python):
import sys
from heapq import heapify, heappushpop

read = sys.stdin.read
readline = sys.stdin.readline

X, Y, A, B, C = map(int, readline().split())
p = list(map(int, readline().split()))
q = list(map(int, readline().split()))
r = [0] + list(map(int, readline().split()))
p.sort()
q.sort()
r.sort()
heap_p = p[-X:]
heap_q = q[-Y:]
'''
heapify(heap_q)
heapify(heap_p)
while r[-1] > heap_p[0] or r[-1] > heap_q[0]:
    if heap_q[0] < heap_p[0]:
        heappushpop(heap_q, r.pop())
    else:
        heappushpop(heap_p, r.pop())

print(sum(heap_p) + sum(heap_q))
'''
a = heap_p + heap_q + r
a.sort()
print(sum(a[-(X + Y):]))

Solution (Python):
import sys
from heapq import heapify, heappushpop

read = sys.stdin.read
readline = sys.stdin.readline

X, Y, A, B, C = map(int, readline().split())
p = list(map(int, readline().split()))
q = list(map(int, readline().split()))
r = [0] + list(map(int, readline().split()))
p.sort()
q.sort()
r.sort()
heap_p = p[-X:]
heap_q = q[-Y:]
heapify(heap_q)
heapify(heap_p)
while r[-1] > heap_p[0] or r[-1] > heap_q[0]:
    if heap_q[0] < heap_p[0]:
        heappushpop(heap_q, r.pop())
    else:
        heappushpop(heap_p, r.pop())

print(sum(heap_p) + sum(heap_q))

Solution (Python):
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 = list(map(int, input().split()))

apple = []
apple.extend(p[:X])
apple.extend(q[:Y])
apple.extend(r)

apple = sorted(apple)[::-1]

print(sum(apple[:X+Y]))

Solution (Python):
X,Y,A,B,C=map(int, input().split())
AA=list(map(int, input().split()))
BB=list(map(int, input().split()))
CC=list(map(int, input().split()))
AA=sorted(AA,reverse=True)
BB=sorted(BB,reverse=True)
CC=sorted(CC,reverse=True)
XX=sorted(AA[0:X]+BB[0:Y]+CC,reverse=True)
XX=XX[0:X+Y]
print(sum(XX))

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 = sorted(p, reverse=True)
q_sort = sorted(q, reverse=True)
r_sort = sorted(r, reverse=True)

del p_sort[X:]
del q_sort[Y:]

total_list = p_sort + q_sort + r_sort
total_list_sort = sorted(total_list, reverse=True)
del total_list_sort[(X+Y):]
print(sum(total_list_sort))

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)

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

Solution (Python):
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)
white=sorted(list(map(int,input().split())),reverse=True)
eat_list=sorted(red[:x]+green[:y])
for i in range(min(len(eat_list),len(white))):
  if eat_list[i]<white[i]:
    eat_list[i]=white[i]
  else:
    break
print(sum(eat_list))

Solution (Python):
x,y,a,b,c=(int(i) for i in input().split())
p=sorted([int(i) for i in input().split()])
q=sorted([int(i) for i in input().split()])
r=sorted([int(i) for i in input().split()])
l=sorted(p[a-x:]+q[b-y:]+r)
n=len(l)
print(sum(l[n-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)

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

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

p.extend(q)
p.extend(r)

p.sort(reverse=True)
s=0
for i in range(X+Y):
    s+=p[i]
print(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()
p = p[-x:]
q.sort()
q = q[-y:]
print(sum(sorted(p + q + r)[-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()))

apples=[]
for i in range(a):
    apples.append([p[i],0])
for i in range(b):
    apples.append([q[i],1])
for i in range(c):
    apples.append([r[i],2])

apples.sort(reverse=True)

mx_cnt=[x,y,float('inf')]
cnt=[0,0,0]
ans=0
for app in apples:
    deli=app[0]
    clr = app[1]

    if cnt[clr] < mx_cnt[clr]:
        ans+=deli
        cnt[clr]+=1

    if sum(cnt)>=x+y:
        break
print(ans)

Solution (Python):
L=lambda:map(int,input().split())
x,y,a,b,c=L()
*p,=L()
*q,=L()
*r,=L()
print(sum(sorted(sorted(p,reverse=1)[:x]+sorted(q,reverse=1)[:y]+r,reverse=1)[: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):
def resolve():
    X, Y, A, B, C = map(int,input().split())
    P = sorted(tuple(map(int, input().split())), reverse=True)
    Q = sorted(tuple(map(int, input().split())), reverse=True)
    R = sorted(tuple(map(int, input().split())), reverse=True)

    NP = P[0:X]
    NQ = Q[0:Y]

    NP.extend(NQ)
    NP.extend(R)

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

if __name__ == '__main__':
    resolve()

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    X,Y,A,B,C=MI()
    p=LI()
    q=LI()
    r=LI()
    p.sort(reverse=True)
    q.sort(reverse=True)
    r.sort(reverse=True)
    sp=sum(p[:X])
    sq=sum(q[:Y])
    np=X-1
    nq=Y-1
    nr=0
    p.append(10**10)
    q.append(10**10)
    r.append(-1)
    
    
    while True:
        pp=p[np]
        qq=q[nq]
        rr=r[nr]
        if rr>pp and rr>qq:
            if pp>qq:
                sq=sq-qq+rr
                nr+=1
                nq-=1
            else:
                sp=sp-pp+rr
                nr+=1
                np-=1
        elif rr>pp:
            sp=sp-pp+rr
            nr+=1
            np-=1
        elif rr>qq:
            sq=sq-qq+rr
            nr+=1
            nq-=1
        else:
            break
        
    print(sp+sq)
            
            
    
    
    

main()