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

Solution (Python):
from collections import deque

X, Y, A, B, C = map(int, input().split())
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)

r = deque(r)
deque_p = deque(p[:X])
deque_q = deque(q[:Y])
deque_r = deque([])

if r:
    while min(deque_p[-1], deque_q[-1]) < r[0]:
        if deque_p[-1] <= deque_q[-1]:
            deque_p.pop()
            deque_r.append(r.popleft())
        else:
            deque_q.pop()
            deque_r.append(r.popleft())

        if (not r) or (not deque_p) or (not deque_q):
            break

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

        if (not r) or (not deque_p):
            break

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

        if (not r) or (not deque_q):
            break
    

ans = sum(deque_p) + sum(deque_q) + sum(deque_r)

print(ans)

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

ra = list(map(int, input().split()))
gb = list(map(int, input().split()))
sc = list(map(int, input().split()))

ra.sort(reverse=True)
gb.sort(reverse=True)
sc.sort(reverse=True)

curr_red_min_val = ra[x-1]
curr_green_min_val = gb[y-1]
tmp_x = x
tmp_y = y

for i in range(c):
  if tmp_x > 0 and curr_red_min_val < curr_green_min_val:
    if sc[i] > curr_red_min_val:
      ra[tmp_x-1] = sc[i]
      tmp_x -= 1
      if tmp_x != 0:
        curr_red_min_val = ra[tmp_x-1]
      else:
        curr_red_min_val = ra[0]
  elif tmp_y > 0:
    if sc[i] > curr_green_min_val:
      gb[tmp_y-1] = sc[i]
      tmp_y -= 1
      if tmp_y != 0:
        curr_green_min_val = gb[tmp_y-1]
      else:
        curr_green_min_val = gb[0]
      
print(sum(ra[:x])+sum(gb[: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 = sorted(list(map(int, input().split())), reverse=True)

opt_p = deque(p[:x])
opt_q = deque(q[:y])
opt_r = deque(r[:x+y])

while len(opt_r) > 0:
    if opt_p[-1] < opt_r[0] or opt_q[-1] < opt_r[0]:
        if opt_p[-1] < opt_q[-1]:
            opt_p.pop()
            opt_p.appendleft(opt_r.popleft())
        else:
            opt_q.pop()
            opt_q.appendleft(opt_r.popleft())
    else:
        break

print(sum(opt_p) + sum(opt_q))

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

i=0
j=0
k=0
lea=len(A)
leb=len(B)
while(True):
    if len(C)<1:
        break
    if i<lea and j<leb:
        if A[i]>B[j]:
            if B[j]<C[0]:
                B[j]=C.pop(0)
                
                j+=1
            else:
                break
        else:
            if A[i]<C[0]:
                A[i]=C.pop(0)
                i+=1
            else:
                break
    elif i<lea and j>=leb:
        if A[i]<C[0]:
                A[i]=C.pop(0)
                i+=1
        else:
            break
    elif i>=lea and j<leb:
        if B[j]<C[0]:
                B[j]=C.pop(0)
                j+=1
        else:
            break
    else:
        break
sum=0


for s in range(len(A)):
    sum+=A[s]
for t in range(len(B)):
    sum+=B[t]
print(sum)

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

eat = []


p.sort(reverse=True)
if X > A:
    eat.extend(p)
else:
    eat.extend(p[:X])

q.sort(reverse=True)
if Y > B:
    eat.extend(q)
else:
    eat.extend(q[:Y])
loss = X+Y - len(eat)


while loss > 0:
    r.sort(reverse=True)
    eat.append(r.pop(0))    
    loss -= 1


eat.sort()
r.sort()
for i in range(len(eat)):
    if len(r) != 0 and eat[i] < r[-1]:
        eat[i] = r.pop(-1)
    else:
        break

print(sum(eat))

Solution (Python):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  x,y,a,b,c=LI()
  la=LI()
  lb=LI()
  lc=LI()

  la.sort(reverse=True)
  lb.sort(reverse=True)
  lc.sort(reverse=True)

  ans_list=[]
  ans_list+=la[:x]
  ans_list+=lb[:y]
  ans_list+=lc[:(x+y)]

  ans_list.sort(reverse=True)


  
  return sum(ans_list[:x+y])


print(main())

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

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

P = P[A-X:]
Q = Q[B-Y:]

P.append(10**9+1)
Q.append(10**9+1)
R.append(0)


i = 0
j = 0


while min(P[i],Q[j])<R[i+j]:
    if P[i] < Q[j]:
        i += 1
    else:
        j += 1
    if i+j == C:
        break

P.remove(10**9+1)
Q.remove(10**9+1)
R.remove(0)

ans = 0
for e in P[i:]:
    ans = ans + e
for e in Q[j:]:
    ans = ans + e
for a in range(i+j):
    ans = ans + R[a]

print(ans)

Solution (Python):




from collections import deque


def main():
    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)

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

    li = sorted(pp + qq + r, reverse=True)
    M = sum(li[:X+Y])

    print(M)



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)
q.sort(reverse=True)
r.sort()
from collections import deque
cr = 0
cg = 0
p = p[:x]
q = q[:y]
p = deque(p)
q = deque(q)
for i in range(c-1, -1, -1):
    x = p.pop()
    y = q.pop()
    z = min(x, y)
    if x < y:
        q.append(y)
        if r[i] > z:
            p.appendleft(r[i])
        else:
            p.append(x)
    else:
        p.append(x)
        if r[i] > z:
            q.appendleft(r[i])
        else:
            q.append(y)
print(sum(p) + sum(q))

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

tmp = list(map(int, input().split()))
tmp.sort(reverse=True)
red = [2e+9]
red.extend(tmp)

tmp = list(map(int, input().split()))
tmp.sort(reverse=True)
green = [2e+9]
green.extend(tmp)
none = list(map(int, input().split()))
none.sort(reverse=True)

n_red = x
n_green = y
n_none = 0


while(True):
  if(red[n_red] >= green[n_green]):
    if(green[n_green] <= none[n_none]):
      n_green -= 1
      n_none += 1
    else:
      break
  else: 
    if(red[n_red] <= none[n_none]):
      n_red -= 1
      n_none += 1
    else:
      break
  if(n_none == len(none)):
    break


print(int(sum(red[1:n_red+1])
          +sum(green[1:n_green+1])
          +sum(none[:n_none])))

Solution (Python):
import heapq

x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
p = list(map(lambda x: x*(-1), p))
q=list(map(int,input().split()))
q = list(map(lambda x: x*(-1), q))
r=list(map(int,input().split()))
r = list(map(lambda x: x*(-1), r))



p.sort()
p=p[:x]
q.sort()
q=q[:y]
r.sort()
r=r[:min(len(r),x+y)]


heapq.heapify(p)
heapq.heapify(q)
heapq.heapify(r)

result=0

xx=x
yy=y
result=0
rrr=min(len(r),x+y)
for _ in range(x+y):
    
    

    if xx>0 and yy>0 and rrr>0:
        qq=heapq.heappop(q)
        pp=heapq.heappop(p)
        rr=heapq.heappop(r)
        
        maximum=min(pp,qq,rr)
        if qq==maximum:
            result+=-1*qq
            yy=yy-1
            heapq.heappush(p, pp) 
            heapq.heappush(r, rr) 
        elif pp==maximum:
            result+=-1*pp
            xx=xx-1
            heapq.heappush(q,qq)
            heapq.heappush(r, rr) 
        else:
            result+=-1*rr
            rrr=rrr-1
            heapq.heappush(p, pp)
            heapq.heappush(q, qq) 
    
    elif yy>0 and rrr>0:
        qq=heapq.heappop(q)
        rr=heapq.heappop(r)
        
        maximum=min(qq,rr)
        if qq==maximum:
            result+=-1*qq
            yy=yy-1
            heapq.heappush(r, rr) 
        else:
            result+=-1*rr
            rrr=rrr-1
            heapq.heappush(q, qq) 
    elif xx>0  and rrr>0:
        pp=heapq.heappop(p)
        rr=heapq.heappop(r)
        
        maximum=min(pp,rr)
        if pp==maximum:
            result+=-1*pp
            xx=xx-1
            heapq.heappush(r, rr) 
        else:
            result+=-1*rr
            rrr=rrr-1
            heapq.heappush(p, pp)
    else:
        qq=heapq.heappop(q)
        pp=heapq.heappop(p)
        
        maximum=min(pp,qq)
        if qq==maximum:
            result+=-1*qq
            yy=yy-1
            heapq.heappush(p, pp) 
        elif pp==maximum:
            result+=-1*pp
            xx=xx-1
            heapq.heappush(q,qq)
        
    
    

print(result)

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

T = [(0, "r")] * (A+B+C)
for a in range(A):
    T[a] = (P[a], "r")
for b in range(B):
    T[b+A] = (Q[b], "g")
for c in range(C):
    T[c+A+B] = (R[c], "t")

T.sort(reverse=True)

countR = 0
countG = 0
countT = 0

ans = 0
i = 0
while countR + countG + countT < X + Y:
    v, color = T[i]
    if color == "r":
        if countR < X:
            ans += v
            countR += 1
    elif color == "g":
        if countG < Y:
            ans += v
            countG += 1
    else:
        ans += v
        countT += 1
    i += 1

print(ans)

Solution (Python):
def main():
  x,y,a,b,c=map(int,input().split())
  ps=sorted(list(map(int,input().split())))
  qs=sorted(list(map(int,input().split())))
  rs=sorted(list(map(int,input().split())))
  points=sorted(ps[-x:]+qs[-y:])
  return sum(sorted(points+rs)[-x-y:])
print(main())

Solution (Python):
import heapq


X, Y, A, B, C = map(int,(input().split()))
ps = list(map(int,(input().split())))
qs = list(map(int,(input().split())))
rs = list(map(lambda x:int(x)*-1,(input().split())))

ps.sort()
qs.sort()
rs.sort()

ps = ps[-X:]
qs = qs[-Y:]

heapq.heapify(ps)
heapq.heapify(qs)
heapq.heapify(rs)

while True:
    if len(rs) == 0:
        break
    max_r = heapq.heappop(rs)
    min_p = heapq.heappop(ps)
    min_q = heapq.heappop(qs)

    min_pq = min(min_p, min_q)

    if max_r*-1 > min_pq:
        if min_p < min_q:
            heapq.heappush(ps, max_r*-1)
            heapq.heappush(qs, min_q)
        else:
            heapq.heappush(qs, max_r*-1)
            heapq.heappush(ps, min_p)
    else:
        heapq.heappush(qs, min_q)
        heapq.heappush(ps, min_p)
        break


print(sum(ps) + sum(qs))

Solution (Python):
import sys

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

P = list(map(int, sys.stdin.readline().strip().split()))
Q = list(map(int, sys.stdin.readline().strip().split()))
R = list(map(int, sys.stdin.readline().strip().split()))

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

P = P[:X]
P.sort()
Q = Q[:Y]
Q.sort()

ans = 0
i, j, k = 0, 0, 0
while C > k:
    if X > i and Y > j:

        if P[i] >= Q[j]:
            if R[k] > Q[j] and Y > j:
                Q[j] = R[k]
                j += 1
                k += 1
            elif R[k] > P[i] and X > i:
                P[i] = R[k]
                i += 1
                k += 1
            else:
                break
 
        elif P[i] < Q[j]:
            if R[k] > P[i] and X > i:
                P[i] = R[k]
                i += 1
                k += 1
            elif R[k] > Q[j] and Y > j:
                Q[j] = R[k]
                j += 1
                k += 1
            else:
                break
    elif X > i:
        if R[k] > P[i]:
            P[i] = R[k]
            i += 1
            k += 1
        else:
            break
    elif Y > j:
        if R[k] > Q[j]:
            Q[j] = R[k]
            j += 1
            k += 1
    else:
        break



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

Solution (Python):
x,y,a,b,c=map(int,input().split())
la=input().split()
lb=input().split()
lc=input().split()
A=[]
B=[]
C=[]
for i in range(len(la)):
    A.append(int(la[i]))
for i in range(len(lb)):
    B.append(int(lb[i]))
for i in range(len(lc)):
    C.append(int(lc[i]))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
A=A[:x]
B=B[:y]
C=C[:c]
L=A+B+C
L.sort(reverse=True)
s=0
for i in range(x+y):
    s+=L[i]
print(s)

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

p.sort()
q.sort()
r.sort()
ans=0

z=x+y

while(z!=0):
    while((x!=0)and(y!=0)):
            a=[]
            a.append(p[-1])
            a.append(q[-1])
            a.append(r[-1])
            if max(a)==p[-1]:
                x-=1
                z-=1
                ans+=p[-1]
                p.pop()
            elif max(a)==q[-1]:
                y-=1
                z-=1
                ans+=q[-1]
                q.pop()
            else:
                z-=1
                ans+=r[-1]
                r.pop()
            if z==0:
                break
            if  len(r)==0:
                break
    if len(r)==0:
        break
    if z==0:
        break
        
    if x==0:
        if q[-1]>=r[-1]:
            y-=1
            z-=1
            ans+=q[-1]
            q.pop() 
        else:
            z-=1
            ans+=r[-1]
            r.pop()
            
            
    elif y==0:
        if p[-1]>=r[-1]:
            x-=1
            z-=1
            ans+=p[-1]
            p.pop()
        else:
            z-=1
            ans+=r[-1]
            r.pop()

            
            
if len(r)==0:
    while(z!=0):
        while((x!=0)and(y!=0)):
            a=[]
            a.append(p[-1])
            a.append(q[-1])
            if max(a)==p[-1]:
                x-=1
                z-=1
                ans+=p[-1]
                p.pop()
            elif max(a)==q[-1]:
                y-=1
                z-=1
                ans+=q[-1]
                q.pop()
            if z==0:
                break
        if z==0:
            break
        if x==0:
            y-=1
            z-=1
            ans+=q[-1]
            q.pop() 
        else: 
            x-=1
            z-=1
            ans+=p[-1]
            p.pop()
        
        
        
        
        
        
        
        
        
        
        
        
        
print(ans)

Solution (Python):
import heapq
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)
PQ = P[:X] + Q[:Y]
heapq.heapify(PQ)
i = 0
for r in R:
    if PQ[0] < r:
        heapq.heappop(PQ)
        heapq.heappush(PQ, r)
        i += 1
        if i == (X + Y):
            break
print(sum(PQ))

Solution (Python):
def main():
    X, Y, A, B, C = [int(i) for i in input().split()]
    red = [int(i) for i in input().split()]
    blue = [int(i) for i in input().split()]
    noc = [int(i) for i in input().split()]
    red = sorted(red)[-X:]
    blue = sorted(blue)[-Y:]
    rb = sorted(red + blue)
    score = sum(rb)
    noc = sorted(noc)[::-1]

    s_noc = 0
    s_rb = 0
    for i in range(min(len(rb), len(noc))):
        if rb[i] > noc[i]:
            break
        s_noc += noc[i]
        s_rb += rb[i]

    print(score + s_noc - s_rb)


if __name__ == '__main__':
    main()

Solution (Python):


from collections import deque

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

def sort(L):
  if len(L)==1:
    return L
  left = sort(L[:len(L)//2])
  right = sort(L[len(L)//2:])
  result = []
  left.append(-1)
  right.append(-1)
  left_index = 0
  right_index = 0
  while len(result)<len(L):
    if left[left_index]>=right[right_index]:
      result.append(left[left_index])
      left_index += 1
    else:
      result.append(right[right_index])
      right_index += 1
  return result

P = sort(P)[:X]
Q = sort(Q)[:Y]
R = sort(R)

P_index = X-1
Q_index = Y-1
R_index = 0

while True:
  if P[P_index] <= Q[Q_index] and R[R_index]>P[P_index]:
    P[P_index] = R[R_index]
    P_index = max(0, P_index-1)
    R_index += 1
  elif P[P_index] > Q[Q_index] and R[R_index]>Q[Q_index]:
    Q[Q_index] = R[R_index]
    Q_index = max(0, Q_index-1)
    R_index += 1
  else:
    break
  if R_index>=len(R):
    break

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

Solution (Python):
from itertools import accumulate

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

num_red = 0
num_green = 0


def top_pop(*lst):
    
    if len(lst[-1]) == 0:
        lst = lst[:-1]
    top = max(map(lambda x: x[-1], lst))
    for i in range(len(lst)):
        if lst[i][-1] == top:
            return (lst[i].pop(), i)

def func(i):
    global num_red, num_green
    if i == 0:
        num_red += 1
    elif i == 1:
        num_green += 1
    else:
        pass

ans = 0
for i in range(x+y):
    if num_red < x and num_green < y:
        popped, i = top_pop(p, q, r)
    elif num_red < x:
        popped, i = top_pop(p, r)
    elif num_green < y:
        popped, i = top_pop(q, r)
    else:
        raise RuntimeError
    func(i)
    ans += popped

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)
red = x-1
gre = y-1
mu = 0
while True:
    if mu == c:
        break
    else:
        if red >= 0:
            badr = p_[red]
        else:
            badr = 1000000000
        if gre >= 0:
            badg = q_[gre]
        else:
            badg = 1000000000
        badmu = r_[mu]
        if badr <= badg:
            if badr < badmu:
                red = red-1
                mu = mu+1
            else:
                break
        else:
            if badg < badmu:
                gre = gre-1
                mu = mu+1
            else:
                break
ans = 0
for i in range(red+1):
    ans += p_[i]
for i in range(gre+1):
    ans += q_[i]
for i in range(mu):
    ans += r_[i]
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)

bag = []
for i in range(X):
    bag.append(p[i])
for j in range(Y):
    bag.append(q[j])

bag = sorted(bag)
for i in range(len(bag)):
    if len(r) == 0:
        break
    if bag[i] < r[0]:
        bag[i] = r.pop(0)
        i += 1
    else:
        break

print(sum(bag))

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 = sum(P[:X])+sum(Q[:Y])
pt_x,pt_y = X-1,Y-1
for r in range(len(R)):
    if pt_x >= 0 and pt_y >= 0:
        if P[pt_x] < Q[pt_y]:
            if P[pt_x] < R[r]:
                ans = ans + R[r] - P[pt_x]
                pt_x -= 1
        else:
            if Q[pt_y] < R[r]:
                ans = ans + R[r] - Q[pt_y]
                pt_y -= 1
    elif pt_x >= 0:
        if P[pt_x] < R[r]:
            ans = ans + R[r] - P[pt_x]
            pt_x -= 1
        else:
            break
    elif pt_y >= 0:
        if Q[pt_y] < R[r]:
            ans = ans + R[r] - Q[pt_y]
            pt_y -= 1
        else:
            break
    else:
        break

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())))[::-1]

pq = sorted(p[-X:] + q[-Y:])
ans = sum(pq)

if pq[0] < max(r):
    left = 0
    right = len(r)
    while left < right - 1:
        mid = (left + right) // 2
        if pq[mid] >= r[mid]:
            right = mid
        else:
            left = mid
    ans = ans + sum(r[:right]) - sum(pq[:right])

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)
ans=sum(P[:X])+sum(Q[:Y])
pi=X-1
qi=Y-1
ri=0
for i in range(min(C,X+Y)):
	if pi==-1:
		temp=ans-Q[qi]
		qi-=1
	elif qi==-1:
		temp=ans-P[pi]
		pi-=1
	elif P[pi]<=Q[qi]:
		temp=ans-P[pi]
		pi-=1
	else:
		temp=ans-Q[qi]
		qi-=1

	if ans<temp+R[i]:
		ans=temp+R[i]
	else:
		break

print(ans)

Solution (Python):
X,Y,A,B,C=map(int,input().split())
listD=[0]*(A+B+C)
listA=list(map(int,input().split()))
listB=list(map(int,input().split()))
listC=list(map(int,input().split()))

listA.sort(reverse=True)
listB.sort(reverse=True)
listC.sort(reverse=True)

for i in range(X):
    listD[i]=listA[i]
for i in range(Y):
    listD[A+i]=listB[i]
for i in range(C):
    listD[A+B+i]=listC[i]

listD.sort(reverse=True)

list_answer=[0]*(X+Y)

for i in range(X+Y):
    list_answer[i]=listD[i]

sum1=sum(list_answer)


print(sum1)

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)
if len(r) > x + y:
  r = r[:x+y]

ans = sum(p) + sum(q)
cp = x - 1
cq = y - 1
for tmp in r:
  if cp >= 0 and cq >= 0:
    if p[cp] > q[cq]:
      if tmp > q[cq]:
        ans += tmp - q[cq]
        cq -= 1
      else:
        break
    else:
      if tmp > p[cp]:
        ans += tmp - p[cp]
        cp -= 1
      else:
        break
  elif cp < 0:
    if tmp > q[cq]:
      ans += tmp - q[cq]
      cq -= 1
    else:
      break
  elif cq < 0:
    if tmp > p[cp]:
      ans += tmp - p[cp]
      cp -= 1
    else:
      break
      
  else:
    break
print(ans)

Solution (Python):



import sys
from collections import deque


s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    X, Y, A, B, C = i2nn()
    p = deque(sorted(map(int, i2s().split(' ')), reverse=True)[:X])
    q = deque(sorted(map(int, i2s().split(' ')), reverse=True)[:Y])
    r = deque(sorted(map(int, i2s().split(' '))))
    s = 0
    while p or q:
        if p and q:
            t = p if p[-1] < q[-1] else q
        else:
            t = p if p else q
        if r and t[-1] < r[-1]:
            t.pop()
            s += r.pop()
        else:
            s += t.pop()
    print(s)
    return

main()

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

alist = AList[0:X] + BList[0:Y]
clist = CList
alist.sort()
ans = sum(alist)
cnt = 0

for i in range(C):
  a = clist[i]
  b = bisect.bisect_left(alist,a)
  if i < b:
    ans += a
    cnt += 1



aa = sum(alist[:cnt])

print(int(ans -aa))

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

alist = AList[0:X] + BList[0:Y]
clist = CList
alist.sort()
ans = sum(alist)
cnt = 0

for i in range(C):
  a = clist[i]
  b = bisect.bisect_left(alist,a)
  if i < b:
    ans += a
    cnt += 1



aa = sum(alist[:cnt])

print(int(ans -aa))

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()))
res = 0

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

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

p_sum = sum(p)
q_sum = sum(q)

p_num = -1
q_num = -1

for i in r:
    if p_num >= (len(p) * -1):
        p_temp = (p_sum - p[p_num] + i)
    else:
        p_temp = -1
    if q_num >= (len(q) * -1):
        q_temp = (q_sum - q[q_num] + i)
    else:
        q_temp = -1

    if p_temp >= p_sum or q_temp >= q_sum:        
        if p_temp - p_sum > q_temp - q_sum:
            p_sum = p_temp
            p_num -= 1        
        else:
            q_sum = q_temp
            q_num -= 1        
    else:
        break
    




print(p_sum + q_sum)

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

S = P + Q + R
S = sorted(S)

a = 0
for i in range(A):
  if P[i] >= S[A+B+C-(X+Y)]:
    a += 1

b = 0
for i in range(B):
  if Q[i] >= S[A+B+C-(X+Y)]:
    b += 1

if a <= X and b <= Y:
  c = 0
  for i in range(A+B+C-(X+Y),A+B+C,1):
    c += S[i]
  print(c)
elif a > X:
  c = 0
  P = sorted(P)
  for i in range(A-X,A,1):
    c += P[i]
  T = Q + R
  T = sorted(T)
  for i in range(B+C-Y,B+C,1):
    c += T[i]
  print(c)
else:
  c = 0
  Q = sorted(Q)
  for i in range(B-Y,B,1):
    c += Q[i]
  U = P + R
  U = sorted(U)
  for i in range(A+C-X,A+C,1):
    c += U[i]
  print(c)

Solution (Python):
from collections import deque
x, y, a, b, c = list(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)
ql.sort(reverse=True)
rl.sort(reverse=True)


ans = 0
if x > a:
    ans += sum(pl)
    dif_x = x-a
    ans += rl[:dif_x]
    del rl[:dif_x]
    if y > b:
        ans += sum(ql)
        dif_y = y-b
        ans += sum(rl[:dif_y])
    else:
        qd = deque(ql)
        rd = deque(rl)
        for i in range(y):
            if qd and rd:
                if qd[0] > rd[0]:
                    ans += qd.popleft()
                else:
                    ans += rd.popleft()
            else:
                if qd:
                    ans += qd.popleft()
                else:
                    ans += rd.popleft()
else:
    if y > b:
        ans += sum(ql)
        dif_y = y-b
        ans += rl[:dif_y]
        del rl[:dif_y]
        pd = deque(pl)
        rd = deque(rl)
        for i in range(x):
            if pd and rd:
                if pd[0] > rd[0]:
                    ans += pd.popleft()
                else:
                    ans += rd.popleft()
            else:
                if pd:
                    ans += pd.popleft()
                else:
                    ans += rd.popleft()
    else:
        pd = deque(pl)
        qd = deque(ql)
        rd = deque(rl)
        c_x = 0
        c_y = 0
        for i in range(x+y):
            if pd and qd and rd:
                if (pd[0] == max([pd[0], qd[0], rd[0]]) and c_x < x) or (not c_y < y and pd[0] >= rd[0]):
                    ans += pd.popleft()
                    c_x += 1
                elif (qd[0] == max([pd[0], qd[0], rd[0]]) and c_y < y) or (not c_x < x and qd[0] >= rd[0]):
                    ans += qd.popleft()
                    c_y += 1
                else:
                    ans += rd.popleft()
            else:
                target = [-1, -1, -1]
                if pd:
                    target[0] = pd[0]
                if qd:
                    target[1] = qd[0]
                if rd:
                    target[2] = rd[0]
                t_max = max(target)
                ans += t_max
                idx = target.index(t_max)
                if idx == 0:
                    pd.popleft()
                elif idx == 1:
                    qd.popleft()
                else:
                    rd.popleft()

print(ans)

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


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

red = list(map(int, input().split()))
green = list(map(int, input().split()))
colorless = list(map(int, input().split()))

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

red = red[:X]
green = green[:Y]
colorless = colorless[:(X + Y)]

heapify(red)
heapify(green)

for m in colorless:
  if m < red[0] and m < green[0]:
    break
  
  if red[0] < green[0]:
    heappop(red)
    heappush(red, m)
  else:
    heappop(green)
    heappush(green, m)
    
print(sum(red) + sum(green))

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)
p=p[:x]
q=q[:y]
heapq.heapify(p)
heapq.heapify(q)
for i in range(c):
  pp=heapq.heappop(p)
  pq=heapq.heappop(q)
  if pp<r[i] and pq>=r[i]:
    heapq.heappush(p,r[i])
    heapq.heappush(q,pq)
  elif pp>=r[i] and pq<r[i]:
    heapq.heappush(q,r[i])
    heapq.heappush(p,pp)
  elif pp<r[i] and pq<r[i]:
    if r[i]-pp>=r[i]-pq:
      heapq.heappush(p,r[i])
      heapq.heappush(q,pq)
    else:
      heapq.heappush(q,r[i])
      heapq.heappush(p,pp)
  else:
    heapq.heappush(q,pq)
    heapq.heappush(p,pp)
print(sum(p)+sum(q))