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

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

arr = []
for p in P:
  arr.append((p, 0))
for q in Q:
  arr.append((q, 1))
for r in R:
  arr.append((r, 2))
arr.sort()

remain = X + Y
ret = 0
while remain > 0:
  a, t = arr.pop()
  if t == 0 and X > 0:
    X -= 1
    remain -= 1
    ret += a
  elif t == 1 and Y > 0:
    Y -= 1
    remain -= 1
    ret += a
  elif t == 2:
    remain -= 1
    ret += a
print(ret)

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 = sorted(a)[::-1]
b = sorted(b)[::-1]
c = sorted(c)[::-1]

a = a[:x]
b = b[:y]
ans = a+b
ans = sorted(ans)

index = 0


for i in range(0,C):
    if(c[i] > ans[index]):
        ans[index] = c[i]
        index = index + 1
    else:
        break

    if(index == x+y):
        break

print(sum(ans))

Solution (Python):
hoge = list(map(int,input().split()))
X, Y, A, B, C = hoge[0], hoge[1], hoge[2], hoge[3], hoge[4]
r_apple = sorted(list(map(int,input().split())),reverse=True)
g_apple = sorted(list(map(int,input().split())),reverse=True)
b_apple = sorted(list(map(int,input().split())),reverse=True)

eat_list = []
for i in range(X):
  eat_list.append(r_apple[i])
for i in range(Y):
  eat_list.append(g_apple[i])

sort_eat_list = sorted(eat_list)

for i in range(len(sort_eat_list)):
  if sort_eat_list[i] < b_apple[0]:
    sort_eat_list[i] = b_apple.pop(0)
    if len(b_apple) == 0:
      break

print(sum(sort_eat_list))

Solution (Python):
x,y,a,b,c=map(int,input().split())
p=[int(i) for i in input().split()]
q=[int(i) for i in input().split()]
r=[int(i) for i in input().split()]
p.append(-1)
q.append(-1)
r.append(-1)
ps=sorted(p)
qs=sorted(q)
rs=sorted(r)
d=0
e=0
f=0
ans=0
def me1():
    global ans
    
    if max(ps[-1],qs[-1],rs[-1])==ps[-1]:
        ans+=ps[-1]
        ps.pop(-1)
        global d
        d+=1
    elif max(ps[-1],qs[-1],rs[-1])==qs[-1]:
        ans+=qs[-1]
        qs.pop(-1)
        global e
        e+=1
    else:
        ans+=rs[-1]
        rs.pop(-1)
        global f
        f+=1
def me2():
    global ans
    if max(ps[-1],rs[-1])==ps[-1]:
        ans+=ps[-1]
        ps.pop(-1)
        global d
        d+=1
    else:
        ans+=rs[-1]
        rs.pop(-1)
        global f
        f+=1
def me3():
    global ans
    if max(qs[-1],rs[-1])==qs[-1]:
        ans+=qs[-1]
        qs.pop(-1)
        global e
        e+=1
    else:
        ans+=rs[-1]
        rs.pop(-1)
        global f
        f+=1
for i in range(x+y):
    
    
    
    if d>=x:
        
        me3()
    elif e>=y:
        
        me2()
    else:
        
        me1()
print(ans)

Solution (Python):
x,y,a,b,c=map(int,input().split())
P=sorted(list(map(int,input().split())))[::-1]
Q=sorted(list(map(int,input().split())))[::-1]
R=list(map(int,input().split()))
L=sorted(P[:x]+Q[:y]+R)[::-1]
print(sum(L[:x+y]))

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

for _ in range(X+Y):
    if len(R) == 0:
        break
    s = R[-1]
    if len(P) == 0:
        p = 1000000000000000
    else:
        p = P[-1]
    if len(Q) == 0:
        q = 1000000000000000
    else:
        q = Q[-1]
    
    if p >= q:
        if q < s:
            del Q[-1]
            del R[-1]
            S.append(s)
        else:
            break
    else:
        if p < s:
            del P[-1]
            del R[-1]
            S.append(s)
        else:
            break
    
ans = 0
for i in P:
    ans += i
for i in Q:
    ans += i
for i in S:
    ans += i
print(ans)

Solution (Python):
import heapq

X, Y, A, B, C = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]

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

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


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


for i in range(C):
    if len(p) > 0 and r[i] > p[0] and p[0] <= q[0]:  
        heapq.heappop(p)
        heapq.heappush(p, r[i])
    elif len(q) > 0 and r[i] > q[0]:
        heapq.heappop(q)
        heapq.heappush(q, r[i])

ans = 0
while len(p) > 0:
    
    ans += heapq.heappop(p)
while len(q) > 0:
    
    ans += heapq.heappop(q)

print(ans)

Solution (Python):
X,Y,A,B,C =map(int,input().rstrip().split(" "))
RA = list(map(int,input().rstrip().split(" ")))
GA = list(map(int,input().rstrip().split(" ")))
WA = list(map(int,input().rstrip().split(" ")))
RA.sort()
RA.reverse()
GA.sort()
GA.reverse()
WA.sort()
WA.reverse()
eatRA = X
eatGA = Y
eatWA = 0
ans = 0
while RA[eatRA - 1] < WA[eatWA] or GA[eatGA -1] < WA[eatWA]:
  n= 1
  while RA[eatRA - n] == GA[eatGA -n] and n != min(eatRA,eatGA):
    n += 1
  if RA[eatRA - n] > GA[eatGA - n]:
    eatGA -= 1
  else:
    eatRA -= 1
  eatWA += 1
  if eatWA == C or eatRA == 0 or eatGA == 0:
    break
if eatRA == 0 and eatGA != 0 and eatWA != C:
  while GA[eatGA -1] < WA[eatWA]:
    eatGA -= 1
    eatWA += 1
    if eatWA == C or eatGA == 0:
      break
elif eatRA != 0 and eatGA == 0 and eatWA != C:
  while RA[eatRA -1] < WA[eatWA]:
    eatRA -= 1
    eatWA += 1
    if eatWA == C or eatRA == 0:
      break
for i in range(eatRA):
  ans += RA[i]
for i in range(eatGA):
  ans += GA[i]
for i in range(eatWA):
  ans += WA[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()))

ans_p = sorted(p, reverse=True)[:x][::-1]
ans_q = sorted(q, reverse=True)[:y][::-1]
r.sort(reverse=True)

p_index = 0
q_index = 0
used_r_sum = 0

for max_r in r:
    ans_p_p_index = ans_p[p_index] if p_index < x else float('inf')
    ans_q_q_index = ans_q[q_index] if q_index < y else float('inf')
    if ans_p_p_index < ans_q_q_index:
        if ans_p_p_index < max_r:
            p_index += 1
            used_r_sum += max_r
        else:
            break
    else:
        if ans_q_q_index < max_r:
            q_index += 1
            used_r_sum += max_r
        else:
            break


print(sum(ans_p[p_index:])+sum(ans_q[q_index:])+used_r_sum)

Solution (Python):
import heapq
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
p=p[-1*x:]
q=list(map(int,input().split()))
q.sort()
pq=p
pq.extend(q[-1*y:])
r=list(map(lambda x:-1*int(x),input().split()))
heapq.heapify(pq)
heapq.heapify(r)
while(len(r)>0):
    max_r=-1*heapq.heappop(r)
    min_pq=heapq.heappop(pq)



    if(min_pq < max_r):
        heapq.heappush(pq,max_r)
    else:
        heapq.heappush(pq,min_pq)
        break
print(sum(pq))

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

a=[]
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

u=p[0:x]
v=q[0:y]
if len(r)<x+y:
    w=r
else:
    w=r[0:x+y]

A=u+v+w
A.sort(reverse=True)
print sum(A[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 = sorted(p)[::-1]
q = sorted(q)[::-1]
r = sorted(r)[::-1]

Ca = 0
Cb = 0
Cc = 0

ans = 0

while Ca + Cb + Cc != X + Y:
    if Cc == C:
        if q[Cb] > p[Ca]:
            ans = ans + q[Cb]
            Cb = Cb + 1
        else:
            ans = ans + p[Ca]
            Ca = Ca + 1
    else:
        if Ca == X:
            if q[Cb] > r[Cc]:
                ans = ans + q[Cb]
                Cb = Cb + 1
            else:
                ans = ans + r[Cc]
                Cc = Cc + 1
        else:
            if Cb == Y:
                if p[Ca] > r[Cc]:
                    ans = ans + p[Ca]
                    Ca = Ca + 1
                else:
                    ans = ans + r[Cc]
                    Cc = Cc + 1
            else:
                if p[Ca] >= q[Cb] and p[Ca] > r[Cc]:
                    ans = ans + p[Ca]
                    Ca = Ca + 1
                elif q[Cb] > p[Ca] and q[Cb] > r[Cc]:
                    ans = ans + q[Cb]
                    Cb = Cb + 1
                else:
                    ans = ans + r[Cc]
                    Cc = Cc + 1
print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

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

    xcnt = 0
    ycnt = 0
    rcnt = 0
    ans = 0

    for r in R:
        p = float("inf")
        if X - 1 - xcnt >= 0:
            p = P[X - 1 - xcnt]
        q = float("inf")
        if Y - 1 - ycnt >= 0:
            q = Q[Y - 1 - ycnt]
        if p >= r and q >= r:
            break

        if (r - p) > 0 and r - p > r - q:
            xcnt += 1
            rcnt += 1
            ans += r
        else:
            ycnt += 1
            rcnt += 1
            ans += r

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

    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()
p1=p[-x:]
q.sort()
q1=q[-y:]
r.sort()
r.reverse()

for i in p1:
  r.append(i)
for i in q1:
  r.append(i)
r.sort()
r.reverse()
ans=0
for i in range(x+y):
  ans+=r[i]
print(ans)

Solution (Python):
import numpy as np
import heapq

H = []

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

ps = list(map(int,input().split()))
ps.sort()

qs = list(map(int, input().split()))
qs.sort()

rs = list(map(int, input().split()))
rs.sort()

ans = np.zeros(1, dtype=np.uint64)

for i in range(x):
    heapq.heappush(H, ps[-(i+1)])
    ans += ps[-(i+1)]

for i in range(y):
    heapq.heappush(H, qs[-(i+1)])
    ans += qs[-(i+1)]

for i in range(min(c, (x+y))):
    minimum = heapq.heappop(H)
    if minimum > rs[-(i+1)]:
        break
    else:
        ans = ans - minimum + rs[-(i+1)]

print(ans[0])

Solution (Python):
import heapq

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())))
pp=p[a-x:a]
qq=q[b-y:b]
heapq.heapify(pp)
heapq.heapify(qq)
for i in range(c):
     s=heapq.heappop(pp)
     t=heapq.heappop(qq)
     if r[c-i-1] > s or r[c-i-1] > t:
          if s >= t:
               heapq.heappush(pp, s)
               heapq.heappush(qq, r[c-i-1])
          else:
               heapq.heappush(qq, t)
               heapq.heappush(pp, r[c-i-1])


     else:
          heapq.heappush(pp, s)
          heapq.heappush(qq, t)
          break
print(sum(pp)+sum(qq))

Solution (Python):
x,y,a,b,c=map(int,input().split())
aka,ao,musyoku=[sorted(list(map(int,input().split())),reverse=1) for i in range(3)]
ans=0
A,B,C=0,0,0
while C+A+B<x+y and x>A and y>B and c>C:
    q,w,e=aka[A],ao[B],musyoku[C]
    ans+=max(q,w,e)
    if max(q,w,e)==e:C+=1
    elif q>w:A+=1
    else:B+=1
if C+A+B==x+y:print(ans);exit()
  
if x<=A:
    cnt=x+y-A-B-C
    CC=y-B
    while cnt and CC:
        ans+=max(ao[B],musyoku[C])
        if max(ao[B],musyoku[C])==ao[B]:B+=1
        else:C+=1;CC-=1
        cnt-=1
    if cnt:
        ans+=sum(ao[B:B+cnt]) 
elif y<=B:
    cnt=x+y-A-B-C
    CC=x-A
    while cnt and CC:
        ans+=max(aka[A],musyoku[C])
        if max(aka[A],musyoku[C])==aka[A]:
            A+=1
        else:C+=1;CC-=1
        cnt-=1
    if cnt :
        ans+=sum(aka[A:A+cnt])
else:
    cnt=x+y-A-B-C
    while cnt:
        ans+=max(aka[A],ao[B])
        if max(aka[A],ao[B])==aka[A]:A+=1
        else:B+=1
        cnt-=1

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

     p_cut = p[-x:]
     q_cut = q[-y:]

     
     

     
     red_del = sum(p_cut)
     gre_del = sum(q_cut)
     base_ans = red_del + gre_del

     red_eat = 0
     gre_eat = 0
     cle_eat = 0
     
     for i in range(c):
          if red_eat < x and gre_eat < y:
               if p_cut[red_eat] < q_cut[gre_eat]:
                    change = p_cut[red_eat]
                    if change < r[cle_eat]:
                         cle_eat += 1
                         red_eat += 1
                    else:
                         break
               else:
                    change = q_cut[gre_eat]
                    if change < r[cle_eat]:
                         cle_eat += 1
                         gre_eat += 1
                    else:
                         break
          elif red_eat >= x and gre_eat < y:
               change = q_cut[gre_eat]
               if change < r[cle_eat]:
                    cle_eat += 1
                    gre_eat += 1
               else:
                    break
          elif red_eat < x and gre_eat >= y:
               change = p_cut[red_eat]
               if change < r[cle_eat]:
                    cle_eat += 1
                    red_eat += 1
               else:
                    break
          else:
               break

     ans = sum(p_cut[red_eat:]) + sum(q_cut[gre_eat:]) + sum(r[:cle_eat])
     print(ans)

if __name__ == "__main__":
    main()

Solution (Python):

X, Y, A, B, C = [int(str) for str in input().strip().split()]
ps = [int(str) for str in input().strip().split()]
qs = [int(str) for str in input().strip().split()]
rs = [int(str) for str in input().strip().split()]

def sums(li):
    ret = [0]
    for i in range(len(li)):
        ret.append(ret[-1] + li[i])
    return ret

def f(n):
    return red_and_green_sums[X + Y - n] + r_sums[n]

ps.sort(reverse=True)
qs.sort(reverse=True)
rs.sort(reverse=True)

r_sums = sums(rs)

red_and_green = ps[:X] + qs[:Y]
red_and_green.sort(reverse=True)
red_and_green_sums = sums(red_and_green)


print(max([f(i) for i in range(min(X + Y, C) + 1)]))

Solution (Python):
def main():
    import sys
    import numpy as np

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

    p = sorted(p,reverse=True)
    q = sorted(q,reverse=True)
    r = sorted(r,reverse=True)

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

    i = max(r)
    j = sum(x > i for x in p)
    k = sum(x > i for x in q)

    pd = p[j:]
    qd = q[k:]

    m = (x-j) + (y-k)

    rem = sorted(pd + qd + r,reverse=True)
    ans = sum(p[:j] + q[:k]) + sum(rem[:m])
    print(ans)



if __name__ == '__main__':
    main()

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

i=-X
j=-Y
k=0
deru=0
while deru==0 and k<C and (r[k]>p[i] or r[k]>q[j]):
  if p[i]>q[j] and j<0:
    j+=1
    k+=1
  elif p[i]>q[j] and j>=0 and i<0 and p[i]<r[k]:
    i+=1
    k+=1
  elif p[i]<=q[j] and i<0:
    i+=1
    k+=1
  elif p[i]<=q[j] and i>=0 and j<0 and q[j]<r[k]:
    j+=1
    k+=1
  else:
    deru=1
    
if i==0:
  a=0
else:
  a=sum(p[i:])
  
if j==0:
  b=0
else:
  b=sum(q[j:])
  
if k==0:
  c=0
else:
  c=sum(r[:k])
  
print(a+b+c)

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()
red = []
green = []
less = []
for i in range(x):
    red.append(p[-i-1])
for i in range(y):
    green.append(q[-i-1])

for i in range(c):
    if len(red) > 0 and len(green) > 0:
        if red[-1] < green[-1]:
            if red[-1] < r[-i-1]:
                del red[-1]
                less.append(r[-i-1])
        else:
            if green[-1] <= r[-i-1]:
                del green[-1]
                less.append(r[-i-1])
    elif len(red) > 0:
        if red[-1] < r[-i-1]:
            del red[-1]
            less.append(r[-i-1])
    elif len(green) > 0:
        if green[-1] <= r[-i-1]:
            del green[-1]
            less.append(r[-i-1])
ans = sum(red) + sum(green) + sum(less)

print(ans)

Solution (Python):
import heapq


X, Y, A, B, C = map(lambda x: int(x), input().split(" "))
Ps = sorted(list(map(lambda x: int(x), input().split(" "))), reverse=True)
Qs = sorted(list(map(lambda x: int(x), input().split(" "))), reverse=True)
Rs = sorted(list(map(lambda x: int(x), input().split(" "))), reverse=True)

results = []
results.extend(Ps[:X])
results.extend(Qs[:Y])
results.sort()

heapq.heapify(results)
for r in Rs:
    a = heapq.heappop(results)
    if a >= r:
        heapq.heappush(results, a)
        break
    else:
        heapq.heappush(results, r)

print(sum(results))

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)

answer = sum(p[:x]) + sum(q[:y])

i = x-1
j = y-1

for k in range(C):
	
	if (i >= 0) and (j >= 0) :
		if r[k] > min(p[i],q[j]):
			answer += r[k]
			
			if p[i] < q[j]:
				answer -= p[i]
				i -= 1
		
			else:
				answer -= q[j]
				j -= 1
				
		else:
			break
				
	elif (i >= 0) and (j<0):
		if r[k] > p[i]:
			answer += r[k]
			answer -= p[i]
			i -= 1
		
		else:
			break
	
	elif (j >= 0) and (i < 0):
		if r[k] > q[j]:
			answer += r[k]
			answer -= q[j]
			j -= 1
		
		else:
			break
	

	else:
		break
		
print(answer)

Solution (Python):
import numpy as np

X,Y,A,B,C=list(map(int, input().split()))
p = np.array(list(map(int, input().split())))
q = np.array(list(map(int, input().split())))
r = np.array(list(map(int, input().split())))
p_sort = np.sort(p)[-X:]
q_sort = np.sort(q)[-Y:]
pq_xy=np.concatenate([p_sort, q_sort], 0)
pqr=np.concatenate([r, pq_xy], 0)
pqr_sort = np.sort(pqr)[-X-Y:]
print(np.sum(pqr_sort))

Solution (Python):
x, y, na, nb, nc = map(int, input().split()) 
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
a = a[:x]
b = b[:y]

ai = len(a) - 1
bi = len(b) - 1

for i in c:
    if a[ai] < b[bi]:
        if i > a[ai] and ai >= 0:
            a[ai] = i
            ai -= 1
        elif i > b[bi] and bi >= 0:
            b[bi] = i
            bi -= 1
        else:
            break
    else:
        if i > b[bi] and bi >= 0:
            b[bi] = i
            bi -= 1
        elif i > a[ai] and ai >= 0:
            a[ai] = i
            ai -= 1
        else:
            break
print(sum(a)+sum(b))

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()))
Pl = 0
Ql = 0
Rb = 0

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

P = P[0:x]
Q = Q[0:y]



while Pl != len(P) or Ql != len(Q):
    if Pl == len(P):
        if Q[-1 - Ql] < R[0 + Rb]:
            Q[-1 - Ql] = R[0 + Rb]
            Ql = Ql + 1
        else:
            break
    elif Ql == len(Q):
        if P[-1 - Pl] < R[0 + Rb]:
            P[-1 - Pl] = R[0 + Rb]
            Pl = Pl + 1
        else:
            break

    elif Q[-1 - Ql] >= P[-1 - Pl] and P[-1 - Pl] < R[0 + Rb]:
        P[-1 - Pl] = R[0 + Rb]
        Pl = Pl + 1
    elif P[-1 - Pl] > Q[-1 - Ql] and Q[-1 - Ql] < R[0 + Rb]:
        Q[-1 - Ql] = R[0 + Rb]
        Ql = Ql + 1

    else:
        break

    Rb = Rb + 1
    if Rb == len(R):
        break

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

Solution (Python):
x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort()
p.reverse()
q.sort()
q.reverse()
r.sort()
ans = 0
ele = []
for i in range(x):
    ele.append(p[i])
for i in range(y):
    ele.append(q[i])
for i in range(c):
    ele.append(r[i])
ele.sort()
ele.reverse()
"""a1 = x-1
b1 = y-1
a2 = True
b2 = True
for i in range(c):
    if r[i] > p[a1] and p[a1] <= q[b1] and a2:
        ans += r[i] - p[a1]
        a1 -= 1
        if a1 < 0:
            a2 = False
    elif r[i] > q[b1] and q[b1] < p[a1] and b2:
        ans += r[i] - q[b1]
        b1 -= 1
        if b1 < 0:
            b2 = False"""
for i in range(x+y):
    ans += ele[i]
print(ans)

Solution (Python):

import heapq


def submit():
    x, y, a, b, c = map(int, input().split())
    reds = list(map(int, input().split()))
    greens = list(map(int, input().split()))
    uncs = list(map(int, input().split()))

    
    reds.sort(reverse=True)
    reds = reds[:x]
    heapq.heapify(reds)
    greens.sort(reverse=True)
    greens = greens[:y]
    heapq.heapify(greens)

    
    uncs = [-u for u in uncs]
    heapq.heapify(uncs)

    
    
    while True:
        if not uncs:
            break

        unc = -heapq.heappop(uncs)
        if unc <= reds[0] and unc <= greens[0]:
            break
        
        if reds[0] < greens[0]:
            heapq.heapreplace(reds, unc)
        else:
            heapq.heapreplace(greens, unc)
            
    print(sum(reds) + sum(greens))

    
submit()

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



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



ac=x-1
bc=y-1
for i in range(c):
    
    if p[ac]<q[bc] and p[ac]<r[i]:
        p[ac]=r[i]
        ac=max(0,ac-1)
    
    elif p[ac] >= q[bc] and q[bc]<r[i]:
        q[bc]=r[i]
        bc=max(0,bc-1)


for i in range(x):
    ans+=p[i]

    
for i in range(y):
    ans+=q[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()))
p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)
p = p[: x]
q = q[: y]
t = []
for i in p: t.append(i)
for i in q: t.append(i)
t.sort()
it = 0
for i in range(x + y):
    if it == c: break
    if t[i] < r[it]:
        t[i] = r[it]
        it -= -1
print(sum(t))

Solution (Python):
inputs = open(0).readlines()
x, y, a, b, c = map(int, inputs[0].split())
*P, = map(int, inputs[1].split())
*Q, = map(int, inputs[2].split())
*R, = map(int, inputs[3].split())
P.sort(reverse=1)
Q.sort(reverse=1)
R.sort(reverse=1)
P, Q, R = P[:x][::-1], Q[:y][::-1], R[:x+y]

pi = qi = 0
ri = 0
while ri < len(R):
    if pi < x and qi < y: 
        if P[pi] < Q[qi]:
            if P[pi] < R[ri]:
                P[pi] = R[ri]
                pi += 1
                ri += 1
            else:
                break
        else:
            if Q[qi] < R[ri]:
                Q[qi] = R[ri]
                Q
                qi += 1
                ri += 1
            else:
                break
    elif pi < x and qi == y:
        if P[pi] < R[ri]:
            P[pi] = R[ri]
            pi += 1
            ri += 1
        else:
            break
    elif pi == x and qi < y:
        if Q[qi] < R[ri]:
            Q[qi] = R[ri]
            qi += 1
            ri += 1
        else:
            break
    else:
        raise ValueError('Error')
print(sum(P)+sum(Q))

Solution (Python):
import heapq
import sys
from itertools import accumulate
from collections import defaultdict

input = sys.stdin.readline

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()))
    ans = 0
    P_d = defaultdict(int)
    Q_d = defaultdict(int)
    R_d = defaultdict(int)

    for i in range(len(P)):
        P[i] = -P[i]
        P_d[P[i]] += 1
        
    for i in range(len(Q)):
        Q[i] = -Q[i]
        Q_d[Q[i]] += 1

    
    for i in range(len(R)):
        R[i] = -R[i]
        R_d[R[i]] += 1

    H = P + Q + R
    heapq.heapify(H)
    red = 0
    green = 0
    nocl = 0
    ans = 0
    for i in range(A + B + C):
        tmp = heapq.heappop(H)
        if red + green + nocl == X + Y:
            print(-ans)
            exit()

        if P_d[tmp] >= 1 and red < X:
            P_d[tmp] -= 1
            red += 1
            ans += tmp
        elif Q_d[tmp] >= 1 and green < Y:
            Q_d[tmp] -= 1
            green += 1
            ans += tmp
        elif R_d[tmp] >= 1:
            R_d[tmp] -= 1
            nocl += 1
            ans += tmp
    





if __name__ == "__main__":
    main()

Solution (Python):
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if self.v is None:
            self.v = n
        else:
            self.v = self.f(self.v, n) 

def SS(L):
    S = [0] * (len(L))
    for i, l in enumerate(L):
        S[i + 1] = S[i] + l

    return S


def main():
    X, Y, A, B, C = read_values()
    P = sorted(read_list(), reverse=True) + [-1]
    Q = sorted(read_list(), reverse=True) + [-1]
    R = sorted(read_list(), reverse=True) + [-1]

    x = 0
    y = 0
    r = 0

    res = 0
    for _ in range(X + Y):
        a = P[x]
        b = Q[y]
        c = R[r]

        if c >= a and c >= b:
            res += c
            r += 1
            continue
        
        if x == X:
            if c >= b:
                res += c
                r += 1
            else:
                res += b
                y += 1
            continue

        if y == Y:
            if c >= a:
                res += c
                r += 1
            else:
                res += a
                x += 1
            continue

        if a >= b:
            res += a
            x += 1
        else:
            res += b
            y += 1

    print(res)
    
        
if __name__ == "__main__":
    main()

Solution (Python):

x,y,a,b,c = map(int, input().split())
A = list(map(int, input().split())) 
B = list(map(int, input().split())) 
C = list(map(int, input().split())) 

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

X = A[len(A)-x:]
Y = B[len(B)-y:]



xi = 0
yi = 0
ci = 0
for ci in range(c):
    
    if xi < len(X) and yi < len(Y):
        if C[ci] <= X[xi] and C[ci] <= Y[yi]:
            break
        
        if X[xi] < Y[yi]:
            if C[ci] > X[xi]:
                X[xi] = C[ci]
                xi = xi + 1
        else:
            if C[ci] > Y[yi]:
                Y[yi] = C[ci]
                yi = yi + 1
                
    elif xi < len(X):
        if C[ci] <= X[xi]:
            break
        
        if C[ci] > X[xi]:
            X[xi] = C[ci]
            xi = xi + 1
        
    elif yi < len(Y):
        if C[ci] <= Y[yi]:
            break
        
        if C[ci] > Y[yi]:
            Y[yi] = C[ci]
            yi = yi + 1
            
    else:
        break

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

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

red = sorted(red, reverse=True)[:X]
green = sorted(green, reverse=True)[:Y]
no = sorted(no, reverse = True)[:X+Y]

co = sorted(red+green)

for i in range(len(no)):
    if no[i]>co[i]:
        co[i] = no[i]
    else:
        break
        
print(sum(co))

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 = [(p, 0) for p in P[:X]] + [(q, 1) for q in Q[:Y]]
PQ = sorted(PQ)

y = 0
for v, t in PQ:
    y += v

ans = y
r = 0
n = [X, Y]
for v, t in PQ:
    if n[t]==0: continue
    if r<C and v<R[r]:
       y += R[r]-v
       n[t] -= 1
       ans = max(ans, y)
       r += 1
       
print(ans)

Solution (Python):
X, Y, A, B, C = map(int, input().split())
P = [-1] + sorted(list(map(int, input().split())))
Q = [-1] + sorted(list(map(int, input().split())))
R = [-1] + sorted(list(map(int, input().split())))

ans = 0
r = 0
N = X+Y
while N > 0:
  max_V = max(P[-1], Q[-1], R[-1])
  if P[-1] == max_V:
    P.pop(-1)
    if X < 1:
      continue
    X -= 1
  elif Q[-1] == max_V:
    Q.pop(-1)
    if Y < 1:
      continue
    Y -= 1
  else:
    R.pop(-1)
    r += 1
    
  ans += max_V
  N = X+Y-r
  
print(ans)

Solution (Python):
def main():
    x,y,a,b,c=map(int,input().split())
    P=list(map(int,input().split()))
    P.sort(reverse=True)
    Q=list(map(int,input().split()))
    Q.sort(reverse=True)
    R=list(map(int,input().split()))
    R.sort(reverse=True)
    PQ=P[:x]+Q[:y]
    ans=sum(PQ)
    PQ.sort()
    r=0
    for pq in PQ:
        if r>=c:
            break
        else:
            if pq<R[r]:
                ans-=pq
                ans+=R[r]
                r+=1
    print(ans)
    
if __name__=='__main__':
    main()