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):
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()))
temp=[]
red.sort(reverse=True)
green.sort(reverse=True)
colorless.sort(reverse=True)
for i in range(min(x,a)):
  temp.append(red[i])
for i in range(min(y,b)):
  temp.append(green[i])
for i in range(c):
  temp.append(colorless[i])
temp.sort(reverse=True)
ans=0
for i in range(x+y):
  ans+=temp[i]
print(ans)

Solution (Python):
x,y,a,b,c=[int(i) for i in input().split()]

red_list=[int(i) for i in input().split()]
green_list=[int(i) for i in input().split()]
non_col_list=[int(i) for i in input().split()]

red_list.sort()
green_list.sort()
non_col_list.sort()

eat_red=[]
eat_green=[]
for i in range(x):
    eat_red.append(red_list.pop())
for i in range(y):
    eat_green.append(green_list.pop())


ans_list=eat_green+eat_red+non_col_list
ans_list.sort()
ans=0
for i in range(x+y):
    ans+=ans_list.pop()

print(ans)

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

p_list_max = sorted(p_list, reverse=True)
q_list_max = sorted(q_list, reverse=True)
r_list_max = sorted(r_list, reverse=True)

p_list_X = p_list_max[:X]
q_list_Y = q_list_max[:Y]

ans_list = []
ans_list.extend(p_list_X)
ans_list.extend(q_list_Y)
ans_list.extend(r_list_max)
ans_list_max = sorted(ans_list, reverse=True)

ans = 0

for i in range(X+Y):
    ans += ans_list_max[i]
print(ans)

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

n=len(r)
count=-1
for i in range(n):
    if r[i]>pq[count]:
        ans+=(r[i]-pq[count])
        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)
p=p[:x]
q=q[:y]
ans=p+q
ans.sort(reverse=True)
ans=[0]+ans
nowi=x+y
r=[0]+r
nowr=0
while nowr<=c-1 and nowi>0 and r[nowr+1]>ans[nowi]:
  nowi+=-1
  nowr+=1
ans_=0
for i in range(nowi+1):
  ans_+=ans[i]
for j in range(nowr+1):
  ans_+=r[j]
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[:x]
q=q[:y]
ans=p+q+r
ans.sort(reverse=True)
print(sum(ans[:x+y]))

Solution (Python):
def resolve():
    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)
    eatreds = P[:X]
    eatgreens = Q[:Y]
    import heapq
    heapq.heapify(eatreds)
    heapq.heapify(eatgreens)
    for r in R:
        smallred = heapq.heappop(eatreds)
        smallgreen = heapq.heappop(eatgreens)
        reddiff = r-smallred
        greendiff = r-smallgreen
        if reddiff < 0 and greendiff < 0:
            heapq.heappush(eatreds, smallred)
            heapq.heappush(eatgreens, smallgreen)
            break
        if reddiff > greendiff:
            heapq.heappush(eatreds, r)
            heapq.heappush(eatgreens, smallgreen)
        else:
            heapq.heappush(eatreds, smallred)
            heapq.heappush(eatgreens, r)
    print(sum(eatreds)+sum(eatgreens))


if __name__ == "__main__":
    resolve()

Solution (Python):
from collections import deque

X,Y,A,B,C = map(int, input().split())
A=[int(a) for a in input().split()]
B=[int(b) for b in input().split()]
C=[int(c) for c in input().split()]

A=sorted(A, reverse=True)[:X]
B=sorted(B, reverse=True)[:Y]
AB=deque(sorted(A+B))

for c in sorted(C, reverse=True):
  if c >= AB[0]:
    AB.popleft()
    AB.append(c)
  else:
    break

print(sum(AB))

Solution (Python):

import sys
import collections as cl


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    x, y, a, b, c = MI()
    p = LI()
    q = LI()
    r = LI()

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

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

    ans = [*p_selected, *q_selected]

    ans.sort()
    i = 0

    while i < x + y and i < c and ans[i] < r[i]:
        ans[i] = r[i]
        i += 1

    print(sum(ans))


main()

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 bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

X, Y, A, B, C = MI()
P = LI()
Q = LI()
R = LI()

P.sort()
Q.sort()
R.sort()

Ans = []
for p in P:
    Ans.append(('P', p))
for q in Q:
    Ans.append(('Q', q))
for r in R:
    Ans.append(('R', r))
Ans.sort(key=lambda tup: tup[1])


Ans_text = []
for i in range(A + B + C - X - Y, A + B + C):
    Ans_text.append(Ans[i][0])

c = collections.Counter(Ans_text)

R_num = c['R']
P_num = c['P']
Q_num = c['Q']

ans = 0
cnt = 0
if c['P'] <= X and c['Q'] <= Y:
    while cnt < (X + Y):
        ans += Ans.pop()[1]
        cnt += 1
elif c['P'] > X:
    while cnt < X:
        ans += P.pop()
        cnt += 1
    while cnt < (X + Y):
        b = Ans.pop()
        if b[0] == 'P':
            continue
        else:
            ans += b[1]
            cnt += 1
else:
    while cnt < Y:
        ans += Q.pop()
        cnt += 1
    while cnt < (X + Y):
        b = Ans.pop()
        if b[0] == 'Q':
            continue
        else:
            ans += b[1]
            cnt += 1
print(ans)

Solution (Python):


from pprint import pprint
import sys

sys.setrecursionlimit(10 ** 6)


X, Y, A, B, C = map(int, input().split())
apples_A = sorted(list(map(int, input().split())))
apples_B = sorted(list(map(int, input().split())))
apples_C = sorted(list(map(int, input().split())))





apples_rest = sorted(apples_A[-X:] + apples_B[-Y:] + apples_C)
ans = sum(apples_rest[ -(X + Y):])

print(ans)

Solution (Python):


from pprint import pprint
import sys

sys.setrecursionlimit(10 ** 6)


X, Y, A, B, C = map(int, input().split())
apples_A = sorted(list(map(int, input().split())))
apples_B = sorted(list(map(int, input().split())))
apples_C = sorted(list(map(int, input().split())))






apples_rest = sorted(apples_A[-X:] + apples_B[-Y:] + apples_C)
ans = sum(apples_rest[ -(X + Y):])














print(ans)

Solution (Python):
x, y, a, b, c = map(int, input().split())
p = sorted(map(int, input().split()))
q = sorted(map(int, input().split()))
r = sorted(map(int, input().split()))
ans = p[-x:] + q[-y:] + r
ans.sort()
n = len(ans)
cnt = 0
for i in range(x+y):
    cnt += ans[n-1-i]
print(cnt)

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)[:x+y]

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

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

qa = list(map(int,input().split()))
qb = list(map(int,input().split()))
r = list(map(int,input().split()))

qa.sort(reverse=True)
qb.sort(reverse=True)
r.sort(reverse=True)

qa_ans = qa[:X]
qb_ans = qb[:Y]

heapq.heapify(qa_ans)
heapq.heapify(qb_ans)

for i in range(C):
    r_max = r[i]

    qa_min = heapq.heappop(qa_ans)
    qb_min = heapq.heappop(qb_ans)

    if (r_max>qa_min) or (r_max>qb_min):
        if qa_min >qb_min:
            heapq.heappush(qa_ans,qa_min)
            heapq.heappush(qb_ans,r_max)
        else:
            heapq.heappush(qa_ans,r_max)
            heapq.heappush(qb_ans,qb_min)

    else:
        heapq.heappush(qa_ans, qa_min)
        heapq.heappush(qb_ans, qb_min)
        break

print(sum(qa_ans)+sum(qb_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()
r.sort()
w = p[a-x:a] + q[b-y:b] + r
w.sort()
print(sum(w[len(w)-(x+y):len(w)]))

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)
pq = sorted(p[:x] + q[:y])
ans = sum(pq)
i = 0
while i < min(a+b, c):
  if r[i] <= pq[i]:
    break
  ans += r[i] - pq[i]
  i += 1
print(ans)

Solution (Python):
x,y,a,b,c  = map(int,input().split())
p=[int(x) for x in input().rstrip().split()]
q=[int(x) for x in input().rstrip().split()]
r=[int(x) for x in input().rstrip().split()]
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

p=p[:x]
q=q[:y]
pq=p+q
pqr=pq+r
pqr.sort(reverse=True)
print(sum(pqr[:x+y]))

Solution (Python):
from collections import deque
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=deque(sorted(list(map(int,input().split())),reverse=True))
p=deque(p[:x])
q=deque(q[:y])
ans=sum(p)+sum(q)

while p[-1]<r[0] or q[-1]<r[0]:
  if p[-1]<q[-1]:
    ans+=r[0]-p[-1]
    r.popleft()
    p.pop()
  else:
    ans+=r[0]-q[-1]
    r.popleft()
    q.pop()
  if p==deque([]) or q==deque([]) or r==deque([]):
    break
if r==deque([]):
  pass
elif p==deque([]):
  while q[-1]<r[0]:
    ans+=r[0]-q[-1]
    r.popleft()
    q.pop()
    if q==deque([]) or r==deque([]):
      break
elif q==deque([]):
  while p[-1]<r[0]:
    ans+=r[0]-p[-1]
    r.popleft()
    p.pop()
    if p==deque([]) or r==deque([]):
      break
  
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()
q.sort()
list.sort(r, reverse=True)

p = p[(A-X):]
q = q[(B-Y):]

i_p = 0
i_q = 0
for i_r in range(C):
    if i_p >= len(p):
        if q[i_q] < r[i_r]:
            q[i_q] = r[i_r]
            i_q += 1
    elif i_q >= len(q):
        if p[i_p] < r[i_r]:
            p[i_p] = r[i_r]
            i_p += 1
    elif p[i_p] <= q[i_q]:
        if p[i_p] < r[i_r]:
            p[i_p] = r[i_r]
            i_p += 1
    else:
        if q[i_q] < r[i_r]:
            q[i_q] = r[i_r]
            i_q += 1

    if i_p >= len(p) and i_q >= len(q):
        break

res = 0

for i in range(len(p)):
    res += p[i]

for i in range(len(q)):
    res += q[i]

print(res)

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

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

Solution (Python):
(x,y,a,b,c),p,q,r=[[*map(int,i.split())]for i in open(0)]
print(sum(sorted(sorted(p)[-x:]+sorted(q)[-y:]+r)[-x-y:]))

Solution (Python):
def main():
    import heapq
    x,y,a,b,c = map(int,input().split())
    p = sorted(list(map(int,input().split())),reverse=True)[0:x]
    q = sorted(list(map(int,input().split())),reverse=True)[0:y]
    r = sorted(list(map(int,input().split())),reverse=True)
    P,Q = [],[]
    for i in range(x):
        heapq.heappush(P,p[i])
    for i in range(y):
        heapq.heappush(Q,q[i])
    for i in range(c):
        p,q = heapq.heappop(P), heapq.heappop(Q)
        if p>q:
            heapq.heappush(P,p)
            if r[i]>q:
                heapq.heappush(Q,r[i])
            else:
                heapq.heappush(Q,q)
        else:
            heapq.heappush(Q,q)
            if r[i]>p:
                heapq.heappush(P,r[i])
            else:
                heapq.heappush(P,p)
    print(sum(P)+sum(Q))

if __name__ == "__main__":
    main()

Solution (Python):
(x,y,a,b,c),p,q,r=[[*map(int,i.split())]for i in open(0)]
p=sorted(p)[-x:]
q=sorted(q)[-y:]
pq = sorted(p+q)
r.sort(reverse=True)
ans = sum(pq)
for i in range(min(c,x+y)):
    if r[i] > pq[i]:
        ans += r[i] - pq[i]
    else:
        break
print(ans)

Solution (Python):
def main():
    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    p.sort(reverse=True); q.sort(reverse=True); r.sort()

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

    rtmp = r.pop()
    for i in range(len(s)):
        if s[i] < rtmp:
            s[i] = rtmp
            if len(r) == 0:
                break
            rtmp = r.pop()
        else:
            break
    ans = sum(s)
    print(ans)


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)
P = P[:X]
Q.sort(reverse=True)
Q = Q[:Y]
sp = sum(P)
sq = sum(Q)
ans = sp+sq
R.sort(reverse=True)
import heapq  
heapq.heapify(P)  
heapq.heapify(Q)
p = heapq.heappop(P) 
q = heapq.heappop(Q)
r = R.pop(0)
while p<r or q<r:
  
  if r-p > r-q:
    heapq.heappush(P, r)
    ans += r-p
    p = heapq.heappop(P)
  else:
    heapq.heappush(Q, r)
    ans += r-q
    q = heapq.heappop(Q)
  if len(R)==0:
    break
  r = R.pop(0)
  
print(ans)

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

PQ = sorted(P+Q)
ans = sum(PQ)
for r, pq in zip(R, PQ):
    if r > pq:
        ans += r - pq
print(ans)

Solution (Python):
def main():
    X,Y,A,B,C=map(int,input().split())
    P=list(map(int,input().split()))
    Q = list(map(int, input().split()))
    R = list(map(int, input().split()))

    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)
    Pmax=P[:X]
    Qmax=Q[:Y]

    Pmax.extend(Qmax)
    Pmax.extend(R)
    Pmax.sort(reverse=True)
    res=0
    for i in range(X+Y):
        res+=Pmax[i]

    print(res)

if __name__=="__main__":
    main()

Solution (Python):
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[::-1][:x]
q=sorted(list(map(int,input().split())))[::-1][:y]
r=sorted(list(map(int,input().split())))[::-1]
r=r[:min(len(r),x+y)]
l=sum([p,q,r],[])
print(sum(sorted(l)[::-1][: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()))
s = sorted(p)[::-1][:X] + sorted(q)[::-1][:Y] + r
s = sorted(s)[::-1]
ans = sum(s[:X + Y])
print(ans)

Solution (Python):
x, y, a, b, c = map(int, input().split())
rs = [int(i) for i in input().split()]
gs = [int(i) for i in input().split()]
ws = [int(i) for i in input().split()]

rs.sort(reverse=True)
gs.sort(reverse=True)
ws.sort(reverse=True)
weight = 0
rs = rs[:x]
rs = [0] + rs
gs = gs[:y]
gs = [0] + gs
ws = [0] + ws
r = 0
g = 0
w = 0
while r + g + w < x + y:
  if r < x:
    w1 = weight + rs[r + 1]
  else:
    w1 = 0
  if g < y:
    w2 = weight + gs[g + 1]
  else:
    w2 = 0
  if w < c:
    w3 = weight + ws[w + 1]
  else:
    w3 = 0
  weight = max(w1, w2, w3)
  if weight == w1:
    r += 1
  elif weight == w2:
    g += 1
  elif weight == w3:
    w += 1
print(weight)

Solution (Python):
from collections import deque
x,y,a,b,c = map(int,input().split())
ls = []
la = list(map(int,input().split()))
lb = list(map(int,input().split()))
lc = list(map(int,input().split()))
la.sort(reverse=True)
lb.sort(reverse=True)
lc.sort(reverse=True)
for i in range(a):
    ls.append([la[i],1])
for j in range(b):
    ls.append([lb[j],2])
for l in range(c):
    ls.append([lc[l],3])
ls.sort(key=lambda x:x[0],reverse=True)
ls = deque(ls)
s,t,k = 0,0,0
cnt = 0
while True:
    now = ls.popleft()
    if now[1] == 1:
        if s < x:
            cnt += now[0]
            s += 1
    elif now[1] == 2:
        if t < y:
            cnt += now[0]
            t += 1
    else:
        cnt += now[0]
        k += 1
    if s + t + k == x + y:
        print(cnt)
        break

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

Ps.sort(reverse=True)
Qs.sort(reverse=True)

Al = Ps[:X] + Qs[:Y] +Rs
Al.sort(reverse=True)

print(sum(Al[: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)

pq = sorted(P[:X] + Q[:Y])
cnt = 0
for i in range(min(C, X+Y)):
    if R[i] <= pq[i]: 
        break
    cnt += 1

ans = sum(pq[cnt:]) + sum(R[:cnt])

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)

pq = sorted(p[:x] + q[:y])
r = sorted(r)
ans=0
j = r.pop()
for i in pq:
  if i < j:
    ans += j
    j = 0
    if r:
      j = r.pop()
  else:
    ans += i
    
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()
B.sort()
C.sort()

ans = 0
if X < a:
    A = A[a-X:]
if Y < b:
    B = B[b-Y:]
ans = 0
for i in range(X+Y):
    if len(A) == 0:
        A.append(0)
    if len(B) == 0:
        B.append(0)
    if len(C) == 0:
        C.append(0)
    if max(A[-1],B[-1],C[-1]) == A[-1]:
        ans += A[-1]
        A.pop()
    elif max(A[-1],B[-1],C[-1]) == B[-1]:
        ans += B[-1]
        B.pop()
    else:
        ans += C[-1]
        C.pop()
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)
all=sorted(p[:x]+q[:y]+r,reverse=True)
print(sum(all[: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()
cand = P[-X:] + Q[-Y:] + R
cand.sort()
print(sum(cand[-(X + Y):]))

Solution (Python):
import sys,math,collections,itertools,heapq
input = sys.stdin.readline
def f(n):
    return -1*int(n)

x,y,a,b,c=list(map(int,input().split()))
p=sorted(list(map(int,input().split())),reverse=1)[:x]
q=sorted(list(map(int,input().split())),reverse=1)[:y]
r=list(map(f,input().split()))

p = collections.deque(p)
q = collections.deque(q)
heapq.heapify(r)

tmp = -1*heapq.heappop(r)
while tmp > p[-1]:
    p.appendleft(tmp)
    tmp = p.pop()
    tmp = -1* heapq.heappushpop(r,-1*tmp)

while tmp > q[-1]:
    q.appendleft(tmp)
    tmp = q.pop()
    tmp = -1 * heapq.heappushpop(r,-1*tmp)

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

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

Solution (Python):
import sys
from collections import defaultdict, deque, Counter
import math


from bisect import bisect_left, bisect_right
import heapq

sys.setrecursionlimit(1000000)


input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def fact_and_inv(SIZE):
    inv = [0] * SIZE  
    fac = [0] * SIZE  
    finv = [0] * SIZE  
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret


def solve():
    x, y, a, b, c = getList()
    anums = getList()
    bnums = getList()
    cnums = getList()
    q = []
    anums.sort(key=lambda x: -x)
    bnums.sort(key=lambda x: -x)
    cnums.sort(key=lambda x: -x)
    for i, num in enumerate(anums):
        if i == x:
            break
        heapq.heappush(q, -num)
    for i, num in enumerate(bnums):
        if i == y:
            break
        heapq.heappush(q, -num)

    for i, num in enumerate(cnums):
        
        
        heapq.heappush(q, -num)

    ans = 0
    for i in range(x + y):
        ans += heapq.heappop(q)

    print(-ans)

def main():
    n = getN()
    for _ in range(n):
        solve()


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)

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

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

x,y,a,b,c = inpm()
p = list(reversed(sorted(inpl())))
q = list(reversed(sorted(inpl())))
r = list(reversed(sorted(inpl())))
pp = x-1
qq = y-1
rr = 0

tmp = []
tmp.extend(p[:pp+1])
tmp.extend(q[:qq+1])
tmp.extend(r)

tmp = list(reversed(sorted(tmp)))
ans = sum(tmp[:x+y])
print(ans)

Solution (Python):
def main():
    import sys

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

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

if __name__ == '__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    x,y,a,b,c=map(int, input().split())
    p=list(map(int, input().split()))
    q=list(map(int, input().split()))
    r=list(map(int, input().split()))
    p.sort(reverse=True)
    q.sort(reverse=True)
    r.sort(reverse=True)
    p=[10**10]+p[:x]
    q=[10**10]+q[:y]
    r+=[0]*(a+b)
    ans=sum(p)+sum(q)-2*10**10
    pcnt,qcnt=0,0
    for i in range(x+y):
        if p[-1-pcnt] >= r[i] and q[-1-qcnt] >= r[i]:
            break
        elif p[-1-pcnt] > q[-1-qcnt]:
            ans += -q[-1-qcnt] + r[i]
            qcnt +=1
        else:
            ans += -p[-1-pcnt] + r[i]
            pcnt +=1
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    x, y, a, b, c = map(int, input().split())
    print(sum(sorted((sorted(list(map(int, input().split())), reverse=True)[0:x] + sorted(list(map(int, input(
    ).split())), reverse=True)[0:y] + sorted(list(map(int, input().split())), reverse=True)), reverse=True)[0:(x + y)]))


if __name__ == '__main__':
    main()

Solution (Python):
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    x, y, a, b, c = map(int, input().split())
    p = sorted(list(map(int, input().split())), reverse=True)[0:x]
    q = sorted(list(map(int, input().split())), reverse=True)[0:y]
    r = sorted(list(map(int, input().split())), reverse=True)
    pq = sorted((p + q))
    for i in range(min(c, (x + y))):
        if pq[i] > r[i]:
            break
        pq[i] = r[i]
    print(sum(pq))


if __name__ == '__main__':
    main()

Solution (Python):
x, y, a, b, c = map(int, input().split())
p_l = sorted(list(map(int, input().split())), reverse=True)[:x]
q_l = sorted(list(map(int, input().split())), reverse=True)[:y]
r_l = list(map(int, input().split()))
p_l = sorted(p_l + q_l + r_l, reverse=True)

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

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

Solution (Python):
import sys
import itertools

def main():
  x, y, a, b, c = map(int, sys.stdin.buffer.readline().split())
  red = sorted(map(int, sys.stdin.buffer.readline().split()), reverse=True)
  green = sorted(map(int, sys.stdin.buffer.readline().split()), reverse=True)
  colorless = sorted(map(int, sys.stdin.buffer.readline().split()), reverse=True)
  
  apples = sorted(itertools.chain(red[:x], green[:y], colorless), reverse=True)
  print(sum(apples[:x + y]))

main()

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)
S=[]
T=[]
for i in range(X):
    heapq.heappush(S,-p[i])
for i in range(Y):
    heapq.heappush(S,-q[i])
for i in range(C):
    heapq.heappush(T,-r[i])
ans=0
for i in range(X+Y):
    if len(T)>0:
        if S[0]<T[0]:
            ans+=heapq.heappop(S)
        else:
            ans+=heapq.heappop(T)
    else:
        ans+=heapq.heappop(S)
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 = list(map(int, input().split()))
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 = 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)
new_arr = p[:X] + q[:Y] + r
new_arr = sorted(new_arr, reverse=True)
print(sum(new_arr[: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 = 1)
p.append(-1)
pc = 0
q.sort(reverse = 1)
q.append(-1)
qc = 0
r.sort(reverse = 1)
r.append(-1)
rc = 0
count = x + y
ans = 0
while count > 0:
    if x > 0 and y > 0:
        if max(p[pc], max(q[qc], r[rc])) == p[pc]:
            ans += p[pc]
            x -= 1
            count -= 1
            pc += 1
        elif max(q[qc], r[rc]) == r[rc]:
            ans += r[rc]
            rc += 1
            count -= 1
        else:
            ans += q[qc]
            qc += 1
            count -= 1
            y -= 1
    elif y > 0:
        if max(q[qc], r[rc]) == r[rc]:
            ans += r[rc]
            rc += 1
            count -= 1
        else:
            ans += q[qc]
            qc += 1
            count -= 1
            y -= 1
    elif x > 0:
        if max(p[pc], r[rc]) == r[rc]:
            ans += r[rc]
            rc += 1
            count -= 1
        else:
            ans += p[pc]
            pc += 1
            count -= 1
            x -= 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()
Q.sort()
R.sort()

P_new = P[-X::]
Q_new = Q[-Y::]


agg = P_new + Q_new +R
agg.sort()
print(sum(agg[-X-Y::]))

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
from functools import reduce


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

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

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

print(ans)