Problem:
 Score : 500 points    Problem Statement You are going to eat X red apples and Y green apples. You have A red apples of deliciousness p_1,p_2, \dots, p_A , B green apples of deliciousness q_1,q_2, \dots, q_B , and C colorless apples of deliciousness r_1,r_2, \dots, r_C . Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively. From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible. Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.      Constraints  1 \leq X \leq A \leq 10^5  1 \leq Y \leq B \leq 10^5  1 \leq C \leq 10^5  1 \leq p_i \leq 10^9  1 \leq q_i \leq 10^9  1 \leq r_i \leq 10^9  All values in input are integers.         Input Input is given from Standard Input in the following format:  X  Y  A  B  C  p_1  p_2  ...  p_A  q_1  q_2  ...  q_B  r_1  r_2  ...  r_C       Output Print the maximum possible sum of the deliciousness of the eaten apples.        Sample Input 1 1 2 2 2 1
2 4
5 1
3      Sample Output 1 12  The maximum possible sum of the deliciousness of the eaten apples can be achieved as follows:   Eat the 2 -nd red apple.  Eat the 1 -st green apple.  Paint the 1 -st colorless apple green and eat it.        Sample Input 2 2 2 2 2 2
8 6
9 1
2 1      Sample Output 2 25       Sample Input 3 2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4      Sample Output 3 74

Solution (Python):
from collections import defaultdict


def inp():
    return(int(input().rstrip()))
def inlt():
    return(list(map(int,input().rstrip().split())))
def insr():
    s = input().rstrip()
    return(s[:len(s) - 1])
def invr():
    return(map(int,input().rstrip().split()))

X,Y,a,b,c = invr()
red = inlt() ; red.sort(reverse = True)
green = inlt(); green.sort(reverse = True)
colorless = inlt(); colorless.sort(reverse = True)

red = red[:X]
green = green[:Y]

red.reverse()
green.reverse()

r_index = 0
g_index = 0
c_index = 0
while True:
    if r_index >= len(red) or g_index >= len(green) or c_index >= len(colorless):
        break
    if red[r_index] > green[g_index]:
        if colorless[c_index] > green[g_index]:
            green[g_index] = colorless[c_index]
            g_index += 1
            c_index += 1
        else:
            break
    else:
        if colorless[c_index] > red[r_index]:
            red[r_index] = colorless[c_index]
            r_index += 1
            c_index += 1
        else:
            break

if r_index < len(red):
    if c_index < len(colorless):
        while r_index < len(red) and c_index < len(colorless):
            if red[r_index] < colorless[c_index]:
                red[r_index] = colorless[c_index]
                r_index+= 1
                c_index += 1
            else:
                break

if g_index < len(green):
    if c_index < len(colorless):
        while g_index < len(green) and c_index < len(colorless):
            if green[g_index] < colorless[c_index]:
                green[g_index] = colorless[c_index]
                g_index+= 1
                c_index += 1
            else:
                break

print(sum(red) + sum(green))

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

S = P[:X] + Q[:Y]
S.sort(reverse=True)
S_wa = []
wa = 0
for s in S[::-1]:
    wa += s
    S_wa.append(wa)
big = S_wa[-1]
ans = S_wa[-1]

R_wa = []
wa = 0
for r in R:
    wa += r
    R_wa.append(wa)

for i in range(min(X + Y, C)):
    ans = max(ans, big + R_wa[i] - S_wa[i])
print(ans)

Solution (Python):
import heapq
from collections import deque

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

r.sort()

if A < X:
  p += r[-(X - A):]
  r = r[:-(X - A)]
  A = X

if B < Y:
  q += r[-(Y - B):]
  r = r[:-(Y - B)]
  B = Y

p.sort()
q.sort()

pq = deque(heapq.merge(p[A - X:], q[B - Y:]))

while r and pq[0] < r[-1]:
  pq.popleft()
  pq.append(r.pop())

print(sum(pq))

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)
red_index = x-1
green_index = y-1
white_index = 0

while white_index < c:
  if red[red_index] < green[green_index]:
    if red[red_index] < white[white_index]:
      red[red_index] = white[white_index]
      red_index = max(red_index-1, 0)
      white_index += 1
    else:
      break
  else:
    if green[green_index] < white[white_index]:
      green[green_index] = white[white_index]
      green_index = max(green_index-1, 0)
      white_index += 1  
    else:
      break
print(sum(red[0:x])+sum(green[0:y]))

Solution (Python):
import heapq as hq
X,Y,A,B,C = map(int,input().split())
heap = []
for p in map(int,input().split()):
    hq.heappush(heap,(-p, 0))
for p in map(int,input().split()):
    hq.heappush(heap,(-p, 1))
for p in map(int,input().split()):
    hq.heappush(heap,(-p, 2))
xs = 0
ys = 0
zs = 0
ans = 0
while xs+ys+zs < X+Y:
    p, i = hq.heappop(heap)
    p = -p
    if i == 0 and xs < X:
        xs += 1
        ans += p
    elif i == 1 and ys < Y:
        ys += 1
        ans += p
    elif i == 2:
        zs += 1
        ans += p
print(ans)

Solution (Python):
from collections import deque
x,y,a,b,c = map(int,input().split())
p1 = list(map(int,input().split()))
q1 = list(map(int,input().split()))
r1 = list(map(int,input().split()))
ans = []
p1.sort(reverse=1)
q1.sort(reverse=1)
r1.sort(reverse=1)


p=deque(p1[0:x])
q=deque(q1[0:y])
r=deque(r1[0:x+y])

lp = p.pop()
lq = q.pop()

rr = r.popleft()

while 1:

    if (x > 0 and lp <= lq) or y == 0:
        if lp >= rr:
            ans.append(lp)
            
        else:
            ans.append(rr)
            r.append(0)
            rr = r.popleft()
        if x > 1:
                lp = p.pop()
        x -= 1
    else:
        if lq >= rr:
            ans.append(lq)
            
        else:
            ans.append(rr)
            r.append(0)
            rr = r.popleft()
        if y > 1:
                lq = q.pop()
        y -= 1
    if x == 0 and y == 0:
        print(sum(ans))
        exit()

Solution (Python):
X, Y, A, B, C = [int(x) for x in input().split()]
p_l = sorted([int(x) for x in input().split()], reverse=True)
q_l = sorted([int(x) for x in input().split()], reverse=True)
r_l = sorted([int(x) for x in input().split()], reverse=True)
L = p_l[:X] + q_l[:Y]
L = sorted(L)
for i in range(min(X+Y, C)):
  if L[i] < r_l[i]:
    L[i] = r_l[i]
  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.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

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

p.extend(q)
p.sort()
r=r[:x+y]
lenR=len(r)

temp=p[:lenR]
temp.extend(r)
temp.sort(reverse=True)
temp=temp[:lenR]

print(sum(p[lenR:])+sum(temp))

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=[]

delicious=0
for i in range(X):
    l.append(p[i])
for i in range(Y):
    l.append(q[i])
l.sort(reverse=True)

for i in range(len(l)-C):
    
    delicious=delicious+l[i]
lidx=max(0,len(l)-C)

cidx=0

for j in range(min(C,X+Y)):
    if (l[lidx]<=r[cidx])or(lidx>len(l)):
        delicious=delicious+r[cidx]
        cidx=cidx+1
    else:
        delicious = delicious + l[lidx]
        lidx=lidx+1
    
print(delicious)

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.append(0)
q.append(0)
r += [0] * (10 ** 3)


wa = x + y

lsp = x - 1
lsq = y - 1

pi = 0
qi = 0
ri = 0

ans = 0

for i in range(wa):
    if x > 0 and p[pi] == max(p[pi], q[qi], r[ri]):
        ans += p[pi]
        pi += 1
        x -= 1
    elif y > 0 and q[qi] == max(p[pi], q[qi], r[ri]):
        ans += q[qi]
        qi += 1
        y -= 1
    elif r[ri] == max(p[pi], q[qi], r[ri]):
        ans += r[ri]
        ri += 1
        if y > 0 and p[lsp] >= q[lsq]:
            y -= 1
            if lsq == 0:
                continue
            else:
                lsq -= 1
        elif x > 0 and p[lsp] < q[lsq]:
            x -= 1
            if lsp == 0:
                continue
            else:
                lsp -= 1

print(ans)

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

x, y = x-1, y-1
z = 0
red, green = 0, 0
ans = 0
while True:
    finish = True
    if p[x] <= q[y] or y < 0:
        if z < c and p[x] < r[z]:
            x -= 1
            z += 1
            finish = False
    elif p[x] >= q[y] or x < 0:
        if z < c and q[y] < r[z]:
            y -= 1
            z += 1
            finish = False
    if finish:
        break
print(sum(p[:x+1]) + sum(q[:y+1]) + sum(r[:z]))

Solution (Python):
x, y, a, b, c = map(int, input().split())
p_list = sorted(list(map(int, input().split())))
q_list = sorted(list(map(int, input().split())))
r_list = sorted(list(map(int, input().split())))

p_list = p_list[a - x:]
q_list = q_list[b - y:]

pqr_list = p_list + q_list + r_list
pqr_list = sorted(pqr_list,reverse=True)
pqr_list = pqr_list[:x + y]

print(sum(pqr_list))

Solution (Python):
import sys
import math
import fractions
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10**7)

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

p = deque(p[-X:])
q = deque(q[-Y:])
r = deque(r)

while min(p[0], q[0]) < r[-1]:
    x = r.pop()
    if p[0] < q[0]:
        p.popleft()
        p.append(x)
    else:
        q.popleft()
        q.append(x)
    if len(r) == 0:
        break

cnt = 0
for x in p:
    cnt += x
for y in q:
    cnt += y

print(cnt)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a,b,X,Y,Z = inpl()
x = sorted(inpl())
y = sorted(inpl())
c = sorted(inpl())
c = c[::-1]
res = sum(x[X-a:]) + sum(y[Y-b:])
x += [INF]; y += [INF]
i = X-a; j = Y-b
ind = 0
iok = True; jok = True
while ind < Z:
    if x[i] <= y[j]:
        if x[i] < c[ind]:
            res += c[ind] - x[i]
            ind += 1
            i += 1
        else:
            break
    else:
        if y[j] < c[ind]:
            res += c[ind] - y[j]
            ind += 1
            j += 1
        else:
            break
    
print(res)

Solution (Python):

X,Y,A,B,C = map(int,input().split())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
R = list(map(int,input().split()))

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

rp = []
rq = []
rr = []

for i in range(A):
    if i == 0:
        rp.append(P[0])
    else:
        rp.append(rp[-1]+P[i])
for i in range(B):
    if i == 0:
        rq.append(Q[0])
    else:
        rq.append(rq[-1]+Q[i])
for i in range(C):
    if i == 0:
        rr.append(R[0])
    else:
        rr.append(rr[-1]+R[i])
    
p = 0
q = 0
r = 0
ans = 0
inf = float("inf")
for _ in range(X+Y):
    np,nq,nr = 0,0,0
    if p < A and p < X:
        np = P[p]
    if q < B and q < Y:
        nq = Q[q]
    if r < C:
        nr = R[r]
        
    if np == max(np,nq,nr):
        ans+=np
        p+=1
    elif nq == max(np,nq,nr):
        ans+=nq
        q+=1
    elif nr == max(np,nq,nr):
        ans+=nr
        r+=1
    
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)

ans = sum(P) + sum(Q)
idxp = -1
idxq = -1

for ri in range(C):
    r = R[ri]
    if idxp >= -X and idxq >= -Y:
        if P[idxp] <= Q[idxq] and P[idxp] < R[ri]:
            ans += R[ri] - P[idxp]
            idxp -= 1
        elif Q[idxq] <= P[idxp] and Q[idxq] < R[ri]:
            ans += R[ri] - Q[idxq]
            idxq -= 1
    elif idxp >= -X:
        if P[idxp] < R[ri]:
            ans += R[ri] - P[idxp]
            idxp -= 1
    elif idxq >= -Y:
        if Q[idxq] < R[ri]:
            ans += R[ri] - Q[idxq]
            idxq -= 1

print(ans)

Solution (Python):
def inputs(): return [int(x) for x in input().split()]
from collections import defaultdict
import heapq
x,y,a,b,c = inputs()
p = inputs()
p.sort()
p = p[::-1]
p = p[:x]
heapq.heapify(p)
q = inputs()
q.sort()
q = q[::-1]
q=q[:y]
heapq.heapify(q)
r = inputs()
r.sort()
r=r[::-1]
ans = 0
for i in r:
    red = heapq.heappop(p)
    green = heapq.heappop(q)
    
    if red<i and green<i:
        if red<green:
            heapq.heappush(p, i)
            heapq.heappush(q, green)
        else:
            heapq.heappush(q, i)
            heapq.heappush(p, red)
    elif red<i:
        heapq.heappush(p, i)
        heapq.heappush(q, green)
    elif green<i:
        heapq.heappush(q, i)
        heapq.heappush(p, red)
    else:
        heapq.heappush(q, green)
        heapq.heappush(p, red)
        break
print(sum(p)+sum(q))

Solution (Python):
X,Y,A,B,C=map(int,input().split())
a_list=list(map(int,input().split()))
b_list=list(map(int,input().split()))
c_list=list(map(int,input().split()))
A_list=sorted(a_list,reverse=True)
B_list=sorted(b_list,reverse=True)
apples=[]
for i in range(X):
    apples.append(A_list[i])
for i in range(Y):
    apples.append(B_list[i])
D_list= apples + c_list
ans=0
E_list=sorted(D_list,reverse=True)
for i in range(X+Y):
   ans+=E_list[i]
print(ans)

Solution (Python):
import sys
import heapq
from operator import itemgetter
 
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

X,Y,A,B,C = IL()
p = IL()
q = IL()
r = IL()

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

d = []
heappop = heapq.heappop
heappush = heapq.heappush
for i in range(A):
  heappush(d, (-p[i],0))
for i in range(B):
  heappush(d, (-q[i],1))
for i in range(C):
  heappush(d, (-r[i],2))

acnt ,bcnt, ccnt = 0,0,0
cnt = 0
ans = 0
while acnt+bcnt+ccnt != X+Y:
  score,num = heappop(d)
  if num == 0:
    if acnt < X:
      acnt += 1
      ans -= score
  elif num == 1:
    if bcnt < Y:
      bcnt += 1
      ans -= score
  else:
    ccnt += 1
    ans -= score
print(ans)

Solution (Python):
import sys
from heapq import *

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
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 LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    x,y,a,b,c=MI()
    pp=LI()
    qq=LI()
    rr=LI()
    hp=[]
    for p in pp:heappush(hp,(-p,0))
    for q in qq:heappush(hp,(-q,1))
    for r in rr:heappush(hp,(-r,2))
    cnt=[0]*3
    lim=[x,y,10**9]
    ans=0
    while hp and sum(cnt)<x+y:
        d,i=heappop(hp)
        if cnt[i]==lim[i]:continue
        ans-=d
        cnt[i]+=1
    print(ans)



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

l = p[0:x] + q[0:y] + r[0:(x+y)]
l = sorted(l, reverse=True)
ans = 0
for i in range (0,(x+y)):
    ans = ans + l[i]

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()))
unchip = sorted(p)[::-1]
dsrxqp = unchip[0:x]
unchiq = sorted(q)[::-1]
dsrxqq = unchiq[0:y]
unchipqr = sorted(r+dsrxqq+dsrxqp)[::-1]
print(sum(unchipqr[0:x+y]))

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

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

a = [10**10]*(10**5)
a.extend(p[:X])
b = [10**10]*(10**5)
b.extend(q[:Y])
p_c = -1
q_c = -1
r_c = 0
k = 0

ans = sum(p[:X])+sum(q[:Y])
while(True):
    if a[p_c] >= b[q_c]:
        if b[q_c] < r[r_c] and q_c >= - Y:
            ans += ( r[r_c] - b[q_c] )
            r_c += 1
            q_c -= 1
        else:
            k = 1

    else:
        if a[p_c] < r[r_c]:
            ans += (r[r_c] - a[p_c])
            r_c += 1
            p_c -= 1
        else:
            k = 1

    if k == 1 or r_c >= C:
        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)
x=0
y=0
R=0
z=0
s=0
while (x<X or y<Y) and z<X+Y:
  if (max(p[0],q[0],r[0])==p[0] or (y==Y and r[0]<p[0])) and x<X:
    s+=p[0]
    x+=1
    if x<A:
      p[0]=p[x]
    else:
      p[0]=0
    z+=1
  elif (max(p[0],q[0],r[0])==q[0] or (x==X and r[0]<q[0])) and y<Y:
    s+=q[0]
    y+=1
    if y<B:
      q[0]=q[y]
    else:
      q[0]=0
    z+=1
  else:
    s+=r[0]
    R+=1
    if R<C:
      r[0]=r[R]
    else:
      r[0]=0
    z+=1
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()))

ri=sorted(r)[::-1]

qi=q[::]
pi=p[::]
pi=sorted(pi)[::-1]
pi=pi[:x]
qi=sorted(qi)[::-1]
qi=qi[:y]

l=pi+qi
l=sorted(l)
k=0
for i in range(min(c,x+y)):
    if l[i]>ri[i]:
        break
    else:
        k=i+1
print(sum(l[k:])+sum(ri[:k]))

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

p2 = heapq.nlargest(x, p)
q2 = heapq.nlargest(y, q)
r2 = heapq.nlargest(x+y, r)
p2.append(0)
q2.append(0)
r2.append(0)

pi = 0
qi = 0
ri = 0

val = 0

for _ in range(x+y):
    if p2[pi] >= q2[qi] and p2[pi] >= r2[ri]:
        val += p2[pi]
        pi += 1
    elif p2[pi] <= q2[qi] and q2[qi] >= r2[ri]:
        val += q2[qi]
        qi += 1
    else:
        val += r2[ri]
        ri += 1

print(val)

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)[::-1][:x][::-1]
q =sorted(q)[::-1][:y][::-1]
r =sorted(r)[::-1][:x+y]

pp = 0
qq = 0
pf = True
qf = True
for rr in r:
    lll = False
    if pf == True and qf == True:
        if p[pp]<rr and q[qq]<rr:
            lll = True
            if p[pp]<q[qq] and pf == True:
                p[pp] = rr
                pp += 1
                if pp == x:
                    pf = False
            elif qf == True:
                q[qq] = rr
                qq +=1
                if qq == y:
                    qf = False
    if pf == True and lll == False:
        if p[pp]<rr:
            lll = True
            if pf == True:
               p[pp] = rr
               pp += 1
               if pp == x:
                  pf = False
    if qf == True and lll == False:
        if q[qq]<rr:
            lll = True
            if qf == True:
                q[qq] = rr
                qq +=1
                if qq == y:
                    qf = False

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

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

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

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]

ans = sum(P[:X]) + sum(Q[:Y])

p = P.pop()
q = Q.pop()
r = R.pop()

INF = 10 ** 10


while True:
    m = min(p, q, r)

    if m == r or m == INF:
        break

    if m == p:
        ans += (r - p)

        if P:
            p = P.pop()
        else:
            p = INF
    elif m == q:
        ans += (r - q)

        if Q:
            q = Q.pop()
        else:
            q = INF

    if R:
        r = R.pop()
    else:
        break

print(ans)

Solution (Python):

X, Y, A, B, C = map(int, input().split())
p_list = list(map(int, input().split()))
p_list.sort(reverse=True)

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

r_list = list(map(int, input().split()))

red_list = p_list[:X]
green_list = q_list[:Y]
min_num = min(red_list[-1], green_list[-1])
white_list = [i for i in r_list if i > min_num]

ans_list = red_list + green_list + white_list
ans_list.sort(reverse=True)
ans_list = ans_list[:X + Y]
print(sum(ans_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.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)
ans = 0
L = P[:X] + Q[:Y]
L.sort()
idx = 0
for i in range(X+Y):
    if idx >= C:
        break
    if L[i] < R[idx]:
        L[i] = R[idx]
        idx += 1
print(sum(L))

Solution (Python):
import heapq

x, y, a, b, c = map(int, input().split())
pp = list(map(lambda x: (-int(x), 1), input().split()))
qq = list(map(lambda x: (-int(x), 2), input().split()))
rr = list(map(lambda x: (-int(x), 3), input().split()))

xx = pp + qq + rr
heapq.heapify(xx)
t = x + y
ans = 0
for _ in range(t):
    while len(xx) > 0:
        v = heapq.heappop(xx)
        if v[1] == 1 and x <= 0:
            continue
        if v[1] == 2 and y <= 0:
            continue
        break

    if v[1] == 1:
        x -= 1
    if v[1] == 2:
        y -= 1
    ans += v[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()
p.reverse()
q.sort()
q.reverse()
P = p[:x]
Q = q[:y]
R = P+Q+r
R.sort()
R.reverse()
T = R[:x+y]
ans = sum(T)
print(ans)

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

X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
rev = lambda x: -int(x)
R = list(map(int, input().split()))
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)
red = []
green = []
heapify(red)
heapify(green)

red_sum = 0
for i in range(X):
    red_sum += P[i]
    heappush(red, P[i])

green_sum = 0
for i in range(Y):
    green_sum += Q[i]
    heappush(green, Q[i])

min_p = heappop(red)
min_q = heappop(green)
for i in range(C):
    r = R[i]
    if min_p < min_q:
        if r > min_p:
            heappush(red, r)
            red_sum -= min_p
            red_sum += r
            min_p = heappop(red)
    else:
        if r > min_q:
            heappush(green, r)
            green_sum -= min_q
            green_sum += r
            min_q = heappop(green)
print(green_sum + red_sum)

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

ans = 0
p = p[:x]
q = q[:y]
ans += sum(p) + sum(q)
pq = p+q
pq.sort()

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

Solution (Python):
from sys import stdin
def main():
    readline=stdin.readline
    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)

    res=sum(p[:X])+sum(q[:Y])
    i=X-1
    j=Y-1
    k=0
    while True:
        if k==C:
            break
        if i!=-1 and j!=-1:
            if q[j]<=p[i]:
                if q[j]<r[k]:
                    res-=q[j]
                    res+=r[k]
                    j-=1
                    k+=1
                else:
                    break
            else:
                if p[i]<r[k]:
                    res-=p[i]
                    res+=r[k]
                    i-=1
                    k+=1
                else:
                    break
        elif i==-1:
            if q[j]<r[k]:
                res-=q[j]
                res+=r[k]
                j-=1
                k+=1
            else:
                break
        elif j==-1:
            if p[i]<r[k]:
                res-=p[i]
                res+=r[k]
                i-=1
                k+=1
            else:
                break
        else:
            break

    print(res)

if __name__=="__main__":
    main()

Solution (Python):
X, Y, A, B, C = map(int, input().split())
p_A = list(map(int, input().split()))
q_B = list(map(int, input().split()))
r_C = list(map(int, input().split()))
p_A2 = sorted(p_A, reverse=True)
q_B2 = sorted(q_B, reverse=True)
r_C2 = sorted(r_C, reverse=True)

ans = []
ans += p_A2[:X]
ans += q_B2[:Y]
ans = sorted(ans)

cnt = 0
for i in range(len(ans)):
    if cnt <= C-1:
        if ans[i] < r_C2[cnt]:
            ans[i] = r_C2[cnt]
            cnt += 1
print(sum(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)
Z = X+Y
P = p[:X]
Q = q[:Y]
R = r[:Z]
ans = 0
if X <= Y:
  S = P + R
  S.sort(reverse=True)
  a = S[:X]
  b = S[X:]
  ans += sum(a)
  T = Q + b
  T.sort(reverse=True)
  c = T[:Y]
  ans += sum(c)
else:
  S = Q + R
  S.sort(reverse=True)
  a = S[:Y]
  b = S[Y:]
  ans += sum(a)
  T = P + b
  T.sort(reverse=True)
  c = T[:X]
  ans += sum(c)
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)
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):



from sys import stdin


def main():
    X, Y, A, B, C = list(map(int, stdin.readline().split()))
    p = list(map(int, stdin.readline().split()))
    q = list(map(int, stdin.readline().split()))
    r = list(map(int, stdin.readline().split()))

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

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


if __name__ == "__main__":
    main()

Solution (Python):
from heapq import *
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)
X=p[:x]
Y=q[:y]
heapify(X)
heapify(Y)

for i in r:
    if X[0]>=i and Y[0]>=i:
        break
    if X[0]<Y[0]:
        heappushpop(X,i)
    else:
        heappushpop(Y,i)

print(sum(X)+sum(Y))

Solution (Python):
import heapq
def E():
    X, Y, A, B, C = map(int, input().split())
    reds = []
    heapq.heapify(reds)
    for n in input().split():
        heapq.heappush(reds, int(n))
    greens = []
    heapq.heapify(greens)
    for n in input().split():
        heapq.heappush(greens, int(n))
    colorless = []
    heapq.heapify(colorless)
    for n in input().split():
        heapq.heappush(colorless, -int(n))
    
    redx = heapq.nlargest(X, reds)
    greeny = heapq.nlargest(Y, greens)
    colorless_val = 0
    while True:
        if not colorless:
            break
        cur = abs(heapq.heappop(colorless))
        if redx and cur > redx[-1]:
            if greeny and redx[-1] > greeny[-1]:
                greeny.pop()
            else:
                redx.pop()
            colorless_val += cur
        elif greeny and cur > greeny[-1]:
            if redx and greeny[-1] > redx[-1]:
                redx.pop()
            else:
                greeny.pop()
            colorless_val += cur
        else:
            break
    print(sum(redx)+sum(greeny)+colorless_val)

E()

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

ans = 0
at = a[:X]
bt = b[:Y]
ap = X - 1
bp = Y - 1
cp = 0
cl = len(c)
while cp < cl and (at[ap] < c[cp] or bt[bp] < c[cp]):
    if at[ap] < bt[bp]:
        if at[ap] < c[cp]:
            at[ap] = c[cp]
            ap -= 1
            cp += 1
    else:
        if bt[bp] < c[cp]:
            bt[bp] = c[cp]
            bp -= 1
            cp += 1
print(sum(at) + sum(bt))

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





r.sort(reverse=True)
p.sort(reverse=True)
q.sort(reverse=True)
maze = p[:x] + q[:y]
ans = sum(maze)
dpc = [0]*(c+1)
dpa = [0]*(a+b+1)
maze.sort()
for i in range(c):
    dpc[i+1] = dpc[i] + r[i] 
for i in range(x+y):
    dpa[i+1] = dpa[i]+maze[i]
maxans = ans
for i in range(min(x+y,c)):
    ans = max(ans,maxans - dpa[i+1] + dpc[i+1])
print(ans)

Solution (Python):
import heapq

x,y,a,b,c = map(int, input().split())
pl = list(map(int, input().split()))
ql = list(map(int, input().split()))
rl = list(map(int, input().split()))

pl.sort(reverse=True)
pl = pl[:x]
heapq.heapify(pl)
ql.sort(reverse=True)
ql = ql[:y]
heapq.heapify(ql)
rl.sort(reverse=True)

for r in rl:
    dp = r-pl[0]
    dq = r-ql[0]
    if dp<=0 and dq<=0:
        break
    if dp>dq:
        heapq.heappushpop(pl,r)
    else:
        heapq.heappushpop(ql,r)

print(sum(pl)+sum(ql))

Solution (Python):
'''
Created on 2020/03/28

@author: fanta
'''
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()]
WHITE = [int(x) for x in input().split()]
out = 0
apples = []

RED.sort(key=None, reverse=True)
GREEN.sort(key=None, reverse=True)
WHITE.sort(key=None, reverse=True)

apples = RED[:X] + GREEN[:Y] + WHITE
apples.sort(key=None, reverse=True)


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