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 sys
sys.setrecursionlimit(10**6) 
import math
from copy import copy, deepcopy
from operator import itemgetter

from bisect import bisect_left, bisect, bisect_right

from collections import deque 



from collections import Counter

from itertools import accumulate

from heapq import heapify,heappop,heappush


def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds





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]


ans=0
countp=0
countq=0
countr=0
count=0
r=0
pt=0
qt=0
lR=len(R)


while count<X+Y:
    if countr<lR and r==0:
        r=R[countr]
        countr+=1


    if countp<X and pt==0:
        pt=p[countp]
        countp+=1
    

    if countq<Y and qt==0:
        qt=q[countq]
        countq+=1



    
    ans+=max(r,pt,qt)
    if r>=pt and r>=qt:
        r=0
    elif pt>=r and pt>=qt:
        pt=0
    else:
        qt=0
    
    count+=1


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]
l.sort()

i = 0
while i < len(l) and i < len(r):
  if l[i] < r[i]:
    l[i] = r[i]
    i += 1
  else:
    break

print(sum(l))

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]

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

Solution (Python):
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
p.sort(reverse=True)
topP = p[:X]

q = list(map(int, input().split()))
q.sort(reverse=True)
topQ = q[:Y]

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

concat = topP + topQ + r
concat.sort(reverse=True)
top = concat[:X+Y]

print(sum(top))

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

p = p[a-x:]
q = q[b-y:]

p.extend(q)
p.sort()

ans = sum(p)
count = 0
for i in range(c):
	if p[i] < r[i]:
		ans += r[i] - p[i]
	else:
		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 = sorted(p, reverse=True)
q = sorted(q, reverse=True)
r = sorted(r, reverse=True)
s = p[:x] + q[:y]
s = sorted(s, reverse=True)
i = 1
I = 0
while i <= len(s) and i <= len(r) and s[-i] <= r[i-1]:
    I = i
    i += 1
S = s[:x+y-I] + r[:I]

print(sum(S))

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


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


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False



def main():
    X, Y, A, B, C = MI()
    p = LI()
    q = LI()
    r = LI()
    ans = 0
    p = sorted(p, reverse=True)
    q = sorted(q, reverse=True)
    r = sorted(r, reverse=True)
    p = p[:X]
    q = q[:Y]
    hp = []
    hq = []
    hr = []

    for i in p:
        heappush(hp, i)

    for i in q:
        heappush(hq, i)

    for i in r:
        heappush(hr, -i)

    while len(hr) != 0:
        vr = -heappop(hr)
        vp = heappop(hp)
        vq = heappop(hq)

        if vp < vq and vr > vp:
            heappush(hp, vr)
            heappush(hq, vq)
        elif vp >= vq and vr > vq:
            heappush(hp, vp)
            heappush(hq, vr)
        else:
            heappush(hp, vp)
            heappush(hq, vq)

    print(sum(hp) + sum(hq))

if __name__ == '__main__':
    main()

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

Solution (Python):
x,y,a,b,c=map(int,input().split())
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
lc=list(map(int,input().split()))
la=sorted(la,reverse=True)
lb=sorted(lb,reverse=True)
lc=sorted(lc,reverse=True)
for i in range(a-x):
    la.pop(-1)
for j in range(b-y):
    lb.pop(-1)
l=[]
for ii in range(x):
    l.append(la[ii])
for jj in range(y):
    l.append(lb[jj])
for kk in range(c):
    l.append(lc[kk])
l=sorted(l,reverse=True)
print(sum(l[0:x+y]))

Solution (Python):
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[a-x:]
q=sorted(list(map(int,input().split())))[b-y:]
r=sorted(list(map(int,input().split())))[::-1]
s=sum(p)+sum(q)
p=p+[10**10]
q=q+[10**10]
pp=0
qq=0
for i in range(c):
  t=r[i]
  if p[pp]<t:
    if q[qq]<p[pp]:
      s=s+t-q[qq]
      qq+=1
    else:
      s=s+t-p[pp]
      pp+=1
  elif q[qq]<t:
    s=s+t-q[qq]
    qq+=1
print(s)

Solution (Python):
X, Y, A, B, C = map(int, input().split())
apple = []
nokori = [0] * 3
nokori[1] = X
nokori[2] = Y

a = list(map(int, input().split()))
for p in a:
    apple.append([p, 1])

a = list(map(int, input().split()))
for p in a:
    apple.append([p, 2])

a = list(map(int, input().split()))
for p in a:
    apple.append([p, 0])

apple = sorted(apple, key=lambda x: -x[0])

ans = 0
siroCnt = 0
ato = X + Y
siro = 0
for ap in apple:
    if ato == siroCnt:
        break

    if nokori[ap[1]] > 0:
        ans += ap[0]
        nokori[ap[1]] -= 1
        ato -= 1

    if ap[1] == 0:
        siro += ap[0]
        siroCnt += 1


print(ans + siro)

Solution (Python):
def main():
    import heapq
    x,y,a,b,c = map(int,input().split(" "))
    rs = list(map(int,input().split(" ")))
    rg = list(map(int,input().split(" ")))
    rn = list(map(int,input().split(" ")))

    rs_s = sorted(rs,reverse=True)[:x]
    rg_s = sorted(rg,reverse=True)[:y]

    hp = []
    for r in rs_s:
        heapq.heappush(hp,r)
    for r in rg_s:
        heapq.heappush(hp,r)

    rn.sort(reverse=True)

    sum = 0
    i = 0
    rnlen = len(rn)

    while len(hp)>0:
        r = heapq.heappop(hp)
        if i < rnlen:
            if r < rn[i]:
                sum+=rn[i]
                i+=1
            else:
                sum+=r
        else:
            sum+=r
    
    print(sum)
main()

Solution (Python):
x,y,_,_,_ = map(int,raw_input().split(' '))

a,b,c = map(int, raw_input().split(' ')),map(int, raw_input().split(' ')),map(int, raw_input().split(' '))
a.sort(key = lambda x:-x)
b.sort(key = lambda x:-x)
c.sort(key = lambda x:-x)
r = a[:x] + b[:y]
r.sort()

i,j = 0,0
while(j < len(c) and i < len(r)):
	if c[j] > r[i]:
		r[i] = c[j]
		i +=1
	else:
		break
	j +=1

print sum(r)

Solution (Python):
import collections
x,y,aa,bb,cc = map(int,raw_input().split(' '))

aas = map(int, raw_input().split(' '))
bbs = map(int, raw_input().split(' '))
ccs = map(int, raw_input().split(' '))

aas.sort(key = lambda x:-x)
bbs.sort(key = lambda x:-x)
ccs.sort(key = lambda x:-x)
aas = aas[:x]
bbs = bbs[:y]

r = (aas + bbs)
r.sort()

i = 0
j = 0
while(j < len(ccs) and i < len(r)):
	if ccs[j] > r[i]:
		r[i] = ccs[j]
		i+=1
	j+=1

print sum(r)

Solution (Python):
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left 
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

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):
import numpy as np

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

p_l = list(map(int, input().split()))
q_l = list(map(int, input().split()))
r_l = list(map(int, input().split()))

p_l = sorted(p_l)[::-1]
q_l = sorted(q_l)[::-1]
r_l = sorted(r_l)[::-1]

p_X = p_l[:X]
q_Y = q_l[:Y]

all_l = p_X + q_Y + r_l

ans = np.sum(sorted(all_l)[::-1][:X+Y])

print(ans)

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

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

xlist = p[-X:] 
ylist = q[-Y:] 

"""
def main(X,Y,xlist,ylist,r):
    for i in range(min(X,Y)):
        if xlist[i] < ylist[i] and min(xlist) < max(r):
            xlist.remove(min(xlist))
            xlist.append(r.pop())
            
        elif ylist[i] < xlist[i] and min(ylist) < max(r):
            ylist.remove(min(ylist))
            ylist.append(r.pop())
            
        elif min(xlist) >= max(r) and min(ylist) >= max(r):
            break
        else:
            continue
    
    print(sum(xlist + ylist))

main(X,Y,xlist,ylist,r)
"""
all_apples = sorted(xlist + ylist + r)
print(sum(all_apples[-(X+Y):]))

Solution (Python):
x, y, a, b, c = map(int, input().split())
ps = sorted(list(map(int, input().split())), reverse=True)[:x]
qs = sorted(list(map(int, input().split())), reverse=True)[:y]
rs = list(map(int, input().split()))
apples = sorted(ps + qs + rs, reverse=True)
print(sum(apples[:x+y]))

Solution (Python):
import heapq
x, y, a, b, c = map(int, input().split())
ps = sorted(list(map(int, input().split())), reverse=True)[:x]
qs = sorted(list(map(int, input().split())), reverse=True)[:y]
rs = sorted(list(map(int, input().split())))
apples = ps + qs
heapq.heapify(apples)
m = heapq.heappop(apples)
M = rs.pop()
while 1:
    if m < M:
        heapq.heappush(apples, M)
        if rs: 
            m = heapq.heappop(apples)
            M = rs.pop()
        else:
            break
    else:
        heapq.heappush(apples, m)
        break 
print(sum(apples))

Solution (Python):
X, Y, A, B, C = map(int, input().split())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))
Clist = list(map(int, input().split()))
Alist.sort(reverse=True)
Blist.sort(reverse=True)
Clist.sort(reverse=True)
W = list()
for i in range(X):
    W.append(Alist[i])
for i in range(Y):
    W.append(Blist[i])
W.sort()
for i in range(min(X+Y, C)):
    if W[i] < Clist[i]:
        W[i] = Clist[i]
    else:
        break
print(sum(W))

Solution (Python):

"""
Created on Tue Apr 28 22:12:42 2020
"""

import sys


sys.setrecursionlimit(10 ** 9)


mod = 10**9+7


X, Y, A, B, C = map(int,input().split())
r = list(map(int,input().split()))
g = list(map(int,input().split()))
n = list(map(int,input().split()))

r.sort()
g.sort()

r = r[-X:]
g = g[-Y:]

all_apple = r+g+n
all_apple.sort()
ans = sum(all_apple[-(X+Y):])

print(ans)

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

red = sorted(red)[::-1]
gre = sorted(gre)[::-1]
ino = sorted(ino)[::-1]

eat = sorted(red[:x] + gre[:y])
ans = sum(eat)

for i in range(min(len(eat), len(ino))):
  if eat[i] < ino[i]:
    ans = ans - eat[i] + ino[i]
  else:
    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(key=lambda x: -x)
q.sort(key=lambda x: -x)

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

r.extend(p)
r.extend(q)
r.sort(key=lambda x: -x)
print(sum(r[:x+y]))

Solution (Python):
import copy
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()
por = p[a-x:a]
qor = q[b-y:b]
qp = por.copy()
qp.extend(qor.copy())
qp.sort()
i=0
while(i < x+y and i < c and r[c-i-1] > qp[i]):
    qp[i] = r[c-i-1]
    i = i + 1
ans = sum(qp)
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)

i = 0
j = 0
k = 0
ans = 0
while  i+j+k < X+Y:
    if i == X:
        for n in range(Y-(j+k)):
            if k == C:
                ans += Q[j]
                j += 1
            elif Q[j] > R[k]:
                ans += Q[j]
                j += 1
            else:
                ans += R[k]
                k += 1
    elif j == Y:
        for n in range(X-(i+k)):
            if k == C:
                ans += P[i]
                i += 1
            elif P[i] > R[k]:
                ans += P[i]
                i += 1
            else:
                ans += R[k]
                k += 1
    elif k == C:
        if P[i] > Q[j]:
            ans += P[i]
            i += 1
        else:
            ans += Q[j]
            j += 1
    else:
        if P[i] >= max(Q[j], R[k]):
            ans += P[i]
            i += 1
        elif Q[j] >= max(P[i], R[k]):
            ans += Q[j]
            j += 1
        else:
            ans += R[k]
            k += 1

print(ans)

Solution (Python):

"""
Created on Tue Apr 28 22:12:42 2020
"""

import sys


sys.setrecursionlimit(10 ** 9)


mod = 10**9+7


X, Y, A, B, C = map(int,input().split())
r = list(map(int,input().split()))
g = list(map(int,input().split()))
n = list(map(int,input().split()))

r.sort()
g.sort()
n.sort()

x, y = A-X, B-Y
z = C-1
ans = 0
ans += sum(r[x:])
ans += sum(g[y:])
g.append(10**10)

while z >= 0:

    flg = True
    if x < A and r[x] < n[z] and r[x] < g[y]:
        ans += (n[z] - r[x])
        x += 1
        z -= 1
        flg = False
    elif y < B and g[y] < n[z]:
        ans += (n[z] - g[y])
        y += 1
        z -= 1
        flg = False
    if flg:
        break

print(ans)

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

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)

redlist = plist[:X]
greenlist = qlist[:Y]
RandG = redlist+greenlist+rlist
RandG.sort(reverse=True)
print(sum(RandG[:X+Y]))

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)

redlist = plist[:X]
greenlist = qlist[:Y]
RandG = redlist+greenlist+rlist
RandG.sort(reverse=True)
print(sum(RandG[: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=sorted(list(map(int,input().split())),reverse=True)
p2=p[:x]
q2=q[:y]
memop=x-1
memoq=y-1
sp=sum(p2)
sq=sum(q2)
k=0
flagp=0
flagq=0
while k<c:
    if memop<0:
        flagp=1
    if memoq<0:
        flagq=1
    if flagp*flagq==1:
        print(sp+sq)
        exit()
    elif flagq==1:
        if p2[memop]>=r[k]:
            print(sp+sq)
            exit()
        else:
            sp-=p2[memop]
            sp+=r[k]
            k+=1
            memop-=1
    elif flagp==1:
        if q2[memoq]>=r[k]:
            print(sp+sq)
            exit()
        else:
            sq-=q2[memoq]
            sq+=r[k]
            k+=1
            memoq-=1
    elif p2[memop]>=r[k] and q2[memoq]>=r[k] and flagp+flagq==0:
        print(sp+sq)
        exit()
    elif p2[memop]>q2[memoq]:
        sq-=q2[memoq]
        sq+=r[k]
        k+=1
        memoq-=1
    elif p2[memop]<=q2[memoq]:
        sp-=p2[memop]
        sp+=r[k]
        k+=1
        memop-=1
print(sp+sq)

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)

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

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

x, y, a, b, c = map(int, readline().split())
p = sorted(list(map(int, readline().split())), reverse=True)
q = sorted(list(map(int, readline().split())), reverse=True)
r = list(map(int, readline().split()))
r += p[:x] + q[:y]
r.sort(reverse=True)
print(sum(r[:x + y]))

Solution (Python):
if __name__ == '__main__':
    x, y, a, b, c = map(int, input().split())
    p = list(map(int, input().split()))
    p.sort(reverse=True)
    q = list(map(int, input().split()))
    q.sort(reverse=True)
    r = list(map(int, input().split()))
    r.sort(reverse=True)
    t = p[:x] + q[:y] + r[:(x + y)]
    t.sort(reverse=True)
    print(sum(t[:(x + y)]))

Solution (Python):

import sys
input = sys.stdin.buffer.readline


from collections import defaultdict

con = 10 ** 9 + 7

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


def main():
	X, Y, A, B, C = getlist()
	P = sorted(getlist())
	Q = sorted(getlist())
	R = getlist()
	apple = []
	for i in range(X):
		apple.append(P[-1 - i])
	for i in range(Y):
		apple.append(Q[-1 - i])

	apple += R
	apple = sorted(apple)
	ans = 0
	for i in range(X + Y):
		ans += apple[-1 - i]
	print(ans)



if __name__ == '__main__':
	main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

P = sorted(map(int, readline().split()),reverse=True)
Q = sorted(map(int, readline().split()),reverse=True)
R = sorted(map(int, readline().split()),reverse=True)

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

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

P = sorted(list(map(int, readline().split())),reverse=True)
Q = sorted(list(map(int, readline().split())),reverse=True)
R = sorted(list(map(int, readline().split())),reverse=True)

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

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

Solution (Python):
import sys
import heapq

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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 = sorted(P, reverse=True)[:X]
Q = sorted(Q, reverse=True)[:Y]
R.sort(reverse=True)

heapq.heapify(P)
heapq.heapify(Q)

for r in R:
    p = heapq.heappop(P)
    q = heapq.heappop(Q)

    if p <= q and p < r:
        heapq.heappush(P, r)
        heapq.heappush(Q, q)
    elif q < r:
        heapq.heappush(Q, r)
        heapq.heappush(P, p)
    else:
        heapq.heappush(P, p)
        heapq.heappush(Q, q)

print(sum(P) + sum(Q))

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

RED = sorted(RED, reverse=True)
GREEN = sorted(GREEN, reverse=True)
TRANSPARENT = sorted(TRANSPARENT, reverse=True)

New = RED[0:X]+GREEN[0:Y]+TRANSPARENT[0:X+Y]

New = sorted(New, reverse=True)

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

Solution (Python):

def main():
  x, y, _a, _b, _c = map(int, input().split())
  p = sorted(map(int, input().split()))[-x:]
  q = sorted(map(int, input().split()))[-y:]
  r = sorted(map(int, input().split()), reverse=True)[:x + y]

  arr = sorted(p + q)
  new_num = 0

  for i, nc_apple in enumerate(r):
    if arr[i] >= nc_apple: break

    new_num += nc_apple - arr[i]

  print(sum(arr) + new_num)


main()

Solution (Python):
import heapq
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)
ri,pi=0,0
ans=[]
for i in range(x):
    ans.append(p[i])
for i in range(y):
    ans.append(q[i])
ans.sort()
for i in range(len(r)):
    if ans[pi]<r[i]:
        ans[pi]=r[i]
        pi+=1
    else:
        break
print(sum(ans))

Solution (Python):
import heapq
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)
ri,pi=0,0
ans=[]
for i in range(x):
    ans.append(p[i])
for i in range(y):
    ans.append(q[i])
ans.sort()
for i in range(len(r)):
    if ans[pi]<r[i]:
        ans[pi]=r[i]
        pi+=1
    else:
        break
print(sum(ans))

Solution (Python):
def main():
    import bisect
    x,y,a,b,c = map(int,input().split())
    p = sorted(list(map(int,input().split())))
    q = sorted(list(map(int,input().split())))
    r = list(map(int,input().split()))
    ans = 0
    if x<=a:
        p = p[a-x:a]
    if y<=b:
        q = q[b-y:b]
    ans = sorted(p+q+r,reverse=True)
    print(sum(ans[0:x+y]))
if __name__ == "__main__":
    main()

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(reverse=True)
del p[:a-x]
del q[:b-y]

s=p+q
s.sort()
if s[0]<r[0]:
    s[0]=r[0]
    for i in range(1,c):
        if s[i]>=r[i]:
            break
        else:
            s[i]=r[i]

print(sum(s))

Solution (Python):
from collections import defaultdict

def main():
    X, Y, A, B, C = map(int, input().split())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))
    R = list(map(int, input().split()))
    d_p = defaultdict(int)
    d_q = defaultdict(int)
    d_r = defaultdict(int)
    for p in P:
        d_p[p] += 1
    for q in Q:
        d_q[q] += 1
    for r in R:
        d_r[r] += 1
    D = P + Q + R
    D.sort(reverse=True)
    ans = 0
    x = 0
    y = 0
    c = 0
    for i in range(A + B + C):
        if x + y + c >= X + Y:
            break

        if x < X and d_p[D[i]]:
            ans += D[i]
            x += 1
            d_p[D[i]] -= 1
        elif y < Y and d_q[D[i]]:
            ans += D[i]
            y += 1
            d_q[D[i]] -= 1
        elif d_r[D[i]]:
            ans += D[i]
            c += 1
            d_r[D[i]] -= 1

    print(ans)

if __name__ == "__main__":
    main()

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)
l=[]
for i in range(x):
    l.append(A[i])
for i in range(y):
    l.append(B[i])
for i in C:
    l.append(i)
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()
q.sort()
r.sort(reverse=True)
del p[:a-x]
del q[:b-y]

s=p+q
s.sort()
if s[0]<r[0]:
    s[0]=r[0]
    for i in range(1,c):
        if s[i]>=r[i]:
            break
        else:
            s[i]=r[i]

print(sum(s))

Solution (Python):
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):
    if len(stackX)>0:
        x = stackX[-1]
    else:
        x = pow(10,10)

    if len(stackY)>0:
        y = stackY[-1]
    else:
        y = pow(10,10)

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

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

z = []

for i in range(x):
    z.append(p[a - i - 1])
    
for i in range(y):
    z.append(q[b - i - 1])

for i in list(r):
    z.append(i)

z.sort(reverse=True)

ans = 0

for i in range(x + y):
    ans += z[i]
    
print(ans)

Solution (Python):
X, Y, *_ = map(int, input().split())
print(sum(sorted(sorted(map(int, input().split()), reverse=True)[:X] + sorted(map(int, input().split()), reverse=True)[:Y] + list(map(int, input().split())), 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)
p = p[:X]
q = q[:Y]
p.extend(q)
p.sort()
if X+Y > C:
    for i in range(C) :
        if p[i] < r[i]:
            p[i] = r[i]
        else:
            pass
else:
    for i in range(X+Y) :
        if p[i] < r[i]:
            p[i] = r[i]
        else:
            pass
print(sum(p))

Solution (Python):
import sys
class Node:
    def __init__(self,a:int):
        self.val = a
        self.parent = None
        self.right = None
        self.left = None

class Heap:
    def __init__(self):
        self.size = None
        self.node = None

    def push(self, a:int):
        c = Node(a)
        if self.size is None:
            self.size = 1
            self.node = c
        else:
            self.size += 1
            n = self.size
            l = []
            b = self.node
            c = Node(a)
            while n != 1:
                l.append(n % 2)
                n //= 2
            for i in range(len(l) - 1):
                if l[len(l) - 1 - i] == 1:
                    b = b.right
                else:
                    b = b.left
            if l[0] == 1:
                b.right = c
                c.parent = b
            else:
                b.left = c
                c.parent = b
            while c.parent is not None and c.parent.val < c.val:
                d = c.val
                c.val = c.parent.val
                c.parent.val = d
                c = c.parent

    def pop(self):
        aval = self.node.val
        a = self.node
        n = self.size
        l = []
        b = self.node
        while n != 1:
            l.append(n % 2)
            n //= 2
        for i in range(len(l)):
            if l[len(l) - 1 - i] == 1:
                b = b.right
                if len(l) - 1 - i == 0:
                    b.parent.right = None
            else:
                b = b.left
                if len(l) - 1 - i == 0:
                    b.parent.left = None
        self.size -= 1
        a.val = b.val

        while (a.right is not None and a.val < a.right.val) or (a.left is not None and a.val < a.left.val):
            if a.right is None and a.left is not None:
                c = a.val
                a.val = a.left.val
                a.left.val = c
                a = a.left
            elif a.left.val > a.right.val:
                c = a.val
                a.val = a.left.val
                a.left.val = c
                a = a.left
            else:
                c = a.val
                a.val = a.right.val
                a.right.val = c
                a = a.right
        return aval
def main(): 
    x, y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    pq = Heap()
    p.sort()
    q.sort()
    for i in range(x):
        pq.push(p[len(p) - 1 - i])
    for i in range(y):
        pq.push(q[len(q) - 1 - i])
    for i in range(len(r)):
        pq.push(r[i])
    ans = 0
    for i in range(x + y):
        ans += pq.pop()
    print(ans)

main()