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):
def examA():
    S = SI()
    if S[2]==S[3] and S[4]==S[5]:
        print("Yes")
    else:
        print("No")
    return

def examB():
    X = I()
    ans = 0
    ans += (X//500) * 1000
    X %= 500
    ans += (X//5) * 5
    print(ans)
    return

def examC():
    K, N = LI()
    A = LI()
    L = [0]*N
    L[0] = K-A[-1] + A[0]
    for i in range(1,N):
        L[i] = A[i]-A[i-1]
    ans = sum(L) - max(L)
    
    print(ans)
    return

def examD():
    def bfs(n, e, fordfs):
        
        W = [-1] * n
        
        W[e] = 0
        que = deque()
        que.append(e)
        while que:
            now = que.popleft()
            nowW = W[now]
            for ne in fordfs[now]:
                if W[ne] == -1:
                    W[ne] = nowW + 1
                    que.append(ne)
        return W
    N, X, Y = LI()
    V = [[]for _ in range(N)]
    for i in range(N-1):
        V[i].append(i+1)
        V[i+1].append(i)
    V[X-1].append(Y-1)
    V[Y-1].append(X-1)
    
    ans = [0]*(N-1)
    for i in range(N):
        L = bfs(N,i,V)
        for l in L:
            if l==0:
                continue
            ans[l-1] += 1
    for v in ans:
        print(v//2)
    return

def examE():
    X, Y, A, B, C = LI()
    P = LI()
    Q = LI()
    R = LI()
    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)
    cnt = sum(P[:X]) + sum(Q[:Y])
    
    X -= 1; Y -= 1
    for c in range(C):
        if X>=0 and Y>=0:
            if P[X] <= Q[Y]:
                if P[X] >= R[c]:
                    break
                cnt += (R[c] - P[X])
                X -= 1
            else:
                if Q[Y] >= R[c]:
                    break
                cnt += (R[c] - Q[Y])
                Y -= 1
        elif X>=0:
            if P[X] >= R[c]:
                break
            cnt += (R[c] - P[X])
            X -= 1
        elif Y>=0:
            if Q[Y] >= R[c]:
                break
            cnt += (R[c] - Q[Y])
            Y -= 1
    ans = cnt
    print(ans)
    return

def examF():
    N = I()
    V = [[]for _ in range(N)]

    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examE()

"""

"""

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] + q[:y])
i = x-1
j = y-1

for k in r:
    if i >= 0 and j >= 0:
        if p[i] <= q[j] and p[i] < k:
            ans += k - p[i]
            i -= 1
            continue
        elif p[i] > q[j] and q[j] < k:
            ans += k - q[j]
            j -= 1
            continue
    elif i == -1 and j >= 0:
        if q[j] < k:
            ans += k - q[j]
            j -= 1
            continue
    elif i >= 0 and j == -1:
        if p[i] < k:
            ans += k - p[i]
            i -= 1
            continue
    break
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

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

C=P[:X]+Q[:Y]+R
C.sort(reverse=True)

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

x, y, a, b, c = MAP()
p = LIST()
q = LIST()
r = LIST()
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
pq = p[:x] + q[:y]
pq.sort()
pqsum = 0
rsum = 0
d = 0
for i in range(min(c, x + y)):
    pqsum += pq[i]
    rsum += r[i]
    if rsum - pqsum > d:
        d = rsum - pqsum
print(sum(pq) + d)

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()))
que = []
for i in range(a):
    que.append(p[i]*3)
for i in range(b):
    que.append(q[i]*3+1)
for i in range(c):
    que.append(r[i]*3+2)
que.sort(reverse = True)
cnt = [0]*2
sm = 0
up = [x, y]
ans = 0
for i in range(a+b+c):
    v = que[i]
    if v%3 == 2:
        sm+=1
    elif cnt[v%3] == up[v%3]:
        continue
    else:
        cnt[v%3]+=1
        sm+=1
    ans+=v//3
    if sm == x+y:
        break
print(ans)

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

Ps.sort()
Qs.sort()
Ss = Ps[-X:] + Qs[-Y:]
Ss.sort()

Rs.sort()

for i, s in enumerate(Ss):
    r = Rs.pop()
    if s < r:
        Ss[i] = r
    else:
        break
    if len(Rs) == 0:
        break

print(sum(Ss))

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 = sorted(P[:X] + Q[:Y])
ans = sum(a)

for i in range(min(X+Y, C)):
    if a[i] < R[i]:
        ans += R[i] - a[i]

print(ans)

Solution (Python):
from heapq import heappop,heappush
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
p.sort(reverse=1)
q=list(map(int,input().split()))
q.sort(reverse=1)
r=list(map(int,input().split()))+[0]
r.sort(reverse=1)
h=[]
m=p[0]
for i in range(x):
  heappush(h,p[i])
  m=min(m,p[i])
for i in range(y):
  heappush(h,q[i])
  m=min(m,q[i])
i=0
while m<r[i]:
  _=heappop(h)
  heappush(h,r[i])
  m=heappop(h)
  heappush(h,m)
  i+=1
print(sum(h))

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)
pre = sorted(p[:x]+q[:y])
for i in range(min(x+y,c)):
  if pre[i] < r[i]:
    pre[i] = r[i]
  else:
    break
print(sum(pre))

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

tmp = p[-x:] + q[-y:]
tmp.sort()

from collections import deque
tmp = deque(tmp)

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

print(sum(list(tmp)))

Solution (Python):
from heapq import heappush,heappop
x,y,a,b,c = map(int,input().split())
r = list(map(int,input().split()))
g = list(map(int,input().split()))
b = list(map(int,input().split()))
r.sort()
g.sort()
b.sort()
hq = []
for i in range(x):
  heappush(hq,r[-i-1])
for i in range(y):
  heappush(hq,g[-i-1])
while b:
  a = heappop(hq)
  if a < b[-1]:
    c = b.pop()
    heappush(hq,c)
  else:
    heappush(hq,a)
    break
print(sum(hq))

Solution (Python):
X, Y, A, B, C = map(int, input().split())
P = [int(a) for a in input().split()]
Q = [int(a) for a in input().split()]
R = [int(a) for a in input().split()]
S = sorted([p * 4 for p in P] + [q * 4 + 1 for q in Q] + [r * 4 + 2 for r in R])[::-1]

Z = X + Y
ans = 0
for s in S:
    a, t = s>>2, s & 3
    if t == 0:
        if X:
            ans += a
            X -= 1
            Z -= 1
    elif t == 1:
        if Y:
            ans += a
            Y -= 1
            Z -= 1
    else:
        ans += a
        Z -= 1
    if not Z: break
print(ans)

Solution (Python):
from heapq import heappush, heappop, heapify
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)


R, B = p[:x], q[:y]
heapify(R)
heapify(B)
for i in range(c):
	if min(R[0], B[0]) > r[i]:
		break
	if R[0] < B[0]:
		heappop(R)
		heappush(R, r[i])
	else:
		heappop(B)
		heappush(B, r[i])

print(sum(R) + sum(B))

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline

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

    apple = []
    for p in P:
        apple.append((p, 1))
    for q in Q:
        apple.append((q, 2))
    for r in R:
        apple.append((r, 3))
    apple.sort(key=lambda x: x[0])

    XY = X+Y
    ans = 0
    while True:
        s, flg = apple.pop()
        if flg == 1 and X == 0:
            continue
        if flg == 2 and Y == 0:
            continue
        ans += s
        if flg == 1:
            X -= 1
        elif flg == 2:
            Y -= 1
        XY -= 1
        if XY == 0:
            break
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

X, Y, A, B, C = na()
P = na()
Q = na()
R = na()
ls = []
for lp in P:
    ls.append([lp, 0])
for lp in Q:
    ls.append([lp, 2])
for lp in R:
    ls.append([lp, 1])
ls.sort(reverse=True)

up = 0
down = 0
ans = 0
for item in ls:
    if item[1] == 0:
        if X > 0:
            X -= 1
            ans += item[0]
        elif X == 0 and Y > 0 and up > 0:
            up -= 1
            down += 1
            Y -= 1
            ans += item[0]
    elif item[1] == 2:
        if Y > 0:
            Y -= 1
            ans += item[0]
        elif Y == 0 and X > 0 and down > 0:
            down -= 1
            up += 1
            X -= 1
            ans += item[0]
    else:
        if X > 0:
            X -= 1
            ans += item[0]
            up += 1
        elif Y > 0:
            Y -= 1
            ans += item[0]
            down += 1
print(ans)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
from re import split
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy
import re

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


x, y, a, b, c = LI()
P = LI()
Q = LI()
R = LI()
L = []
for p in P:
    L += [(p, 0)]

for q in Q:
    L += [(q, 1)]

for r in R:
    L += [(r, 2)]

L.sort(reverse=True)
ret = 0
z = 0
for l, i in L:
    if i == 0 and x:
        x -= 1
        ret += l
    elif i == 1 and y:
        y -= 1
        ret += l
    elif i == 2:
        z += 1
        ret += l
    if x + y == z:
        break


print(ret)

Solution (Python):
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

x,y,a,b,c = nm()
p = nl()
q = nl()
r = nl()
p.sort()
q.sort()
l = p[-x:] + q[-y:]
l.sort()
r.sort()
for i in range(min(x+y, c)):
    if l[i] < r[-1]:
        l[i] = r.pop()
    else:
        break
print(sum(l))

Solution (Python):
from collections import defaultdict, deque
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7


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


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


def inpl_str(): return list(sys.stdin.readline().split())


X, Y, A, B, C = inpl()
pp = inpl()
qq = inpl()
rr = inpl()

apples = []
apples += [(p, 1) for p in pp]
apples += [(q, 2) for q in qq]
apples += [(r, 3) for r in rr]

apples.sort(reverse=True)

ans = 0
S = X+Y
for a, i in apples:
    if i == 1 and X > 0:
        ans += a
        X -= 1
        S -= 1
    elif i == 2 and Y > 0:
        ans += a
        Y -= 1
        S -= 1
    elif i == 3:
        ans += a
        S -= 1

    if S == 0:
        break

print(ans)