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 heapq
from collections import deque
must_red, must_green, a,b,c = map(int,input().split())
delicious_red_ls = list(map(int, input().split()))
delicious_green_ls = list(map(int, input().split()))
delicious_free_ls = list(map(int, input().split()))
delicious_red_ls.sort(reverse=True)
delicious_green_ls.sort(reverse=True)
first_red = delicious_red_ls[:must_red]
first_green = delicious_green_ls[:must_green]
first_set = first_green + first_red
first_set.sort()
delicious_free_ls.sort()

while delicious_free_ls:
    to_be_erased = heapq.heappop(first_set)
    erase = delicious_free_ls[-1]
    if to_be_erased < erase:
        new = delicious_free_ls.pop()
        heapq.heappush(first_set, new)
    else:
        heapq.heappush(first_set, to_be_erased)
        break
print(sum(first_set))

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

ALL = p + q + r
ALL.sort(reverse=True)
ALL = deque(ALL)

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

p = deque(p)
q = deque(q)
r = deque(r)

ans = 0
p_cnt = 0
q_cnt = 0
r_cnt = 0
loopcnt = 0
while loopcnt < X+Y:
    apple = ALL.popleft()
    if p_cnt < X and apple == p[0]:
        ans += p.popleft()
        p_cnt += 1
        loopcnt += 1
    elif q_cnt < Y and apple == q[0]:
        ans += q.popleft()
        q_cnt += 1
        loopcnt += 1
    elif r_cnt < C and apple == r[0]:
        ans += r.popleft()
        r_cnt += 1
        loopcnt += 1
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)

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

red_no_eat = 0
green_no_eat = 0
for no in r:
    red_worst = red[-red_no_eat - 1] if red_no_eat < X else 10 ** 10
    green_worst = green[-green_no_eat - 1] if green_no_eat < Y else 10 ** 10
    if no > red_worst or no > green_worst:
        if red_worst < green_worst:
            red_no_eat += 1
        else:
            green_no_eat += 1
print(sum(p[:X-red_no_eat]) + sum(q[:Y-green_no_eat]) + sum(r[:red_no_eat+green_no_eat]))

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

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)

x_tmp = P[:x]
y_tmp = Q[:y]

tmp_li = x_tmp+y_tmp
heapq.heapify(tmp_li)

for i in range(c):
    if R[i]>tmp_li[0]:
        heapq.heapreplace(tmp_li,R[i])
print(sum(tmp_li))

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    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)
    L = sorted(P + Q + R, reverse=True)
    res = sum(L[:X + Y])
    print(res)


if __name__ == '__main__':
    resolve()

Solution (Python):
import heapq
import sys
X, Y, A, B, C = map(int, input().split())
Av = list(map(int, input().split()))
Bv = list(map(int, input().split()))
Cv = list(map(int, input().split()))
heapq.heapify(Av)
heapq.heapify(Bv)
heapq.heapify(Cv)
for i in range(A-X):
    heapq.heappop(Av)
for i in range(B-Y):
    heapq.heappop(Bv)
if C > X+Y:
    for i in range(C-(X+Y)):
        heapq.heappop(Cv)
    NotTake = X+Y
else:
    NotTake = C
total = X+Y
C = NotTake
for _ in range(NotTake):
    Amin = heapq.heappop(Av)
    Bmin = heapq.heappop(Bv)
    Cmin = heapq.heappop(Cv)
    if X > 0 and Amin == min(Amin, Bmin, Cmin):
        heapq.heappush(Bv, Bmin)
        heapq.heappush(Cv, Cmin)
        X -= 1
    elif Y > 0 and Bmin == min(Bmin, Cmin):
        heapq.heappush(Av, Amin)
        heapq.heappush(Cv, Cmin)
        Y -= 1
    elif C > 0:
        heapq.heappush(Av, Amin)
        heapq.heappush(Bv, Bmin)
        C -= 1
    if X == 0 or Y == 0 or C == 0:
        break
NotTake = X+Y+C-total
if X == 0:
    Iv = Bv
    Jv = Cv
    I = Y
    J = C
elif Y == 0:
    Iv = Av
    Jv = Cv
    I = X
    J = C
else:
    print(sum(Av)+sum(Bv)+sum(Cv))
    sys.exit()

for _ in range(NotTake):
    Imin = heapq.heappop(Iv)
    Jmin = heapq.heappop(Jv)
    if I > 0 and Imin == min(Imin, Jmin):
        heapq.heappush(Jv, Jmin)
        I -= 1
    elif J > 0:
        heapq.heappush(Iv, Imin)
        J -= 1
    if J == 0 or I == 0:
        break

print(sum(Av)+sum(Bv)+sum(Cv))

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)

s = p[:x] + q[:y]
s.sort()
ans = sum(s)
for si, ri in zip(s, r):
    if si < ri:
        ans += ri - si

print(ans)

Solution (Python):
import numpy as np

x, y, a, b, c = 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()
q.sort()
r.sort()

ans = p[-x:].sum()+q[-y:].sum()

p_cnt = 0
q_cnt = 0
r_cnt = 0
while not(-x+p_cnt == 0 and -y+q_cnt == 0) and -1-r_cnt >= -c:
  if -x+p_cnt == 0:
    if r[-1-r_cnt] > q[-y+q_cnt]:
      ans += r[-1-r_cnt] - q[-y+q_cnt]
      q_cnt += 1
      r_cnt += 1
    else:
      break
  
  elif -y+q_cnt == 0:
    if r[-1-r_cnt] > p[-x+p_cnt]:
      ans += r[-1-r_cnt] - p[-x+p_cnt]
      p_cnt += 1
      r_cnt += 1
    else:
      break

  elif p[-x+p_cnt] <= q[-y+q_cnt] and r[-1-r_cnt] > p[-x+p_cnt]:
    ans += r[-1-r_cnt] - p[-x+p_cnt]
    p_cnt += 1
    r_cnt += 1

  elif p[-x+p_cnt] > q[-y+q_cnt] and r[-1-r_cnt] > q[-y+q_cnt]:
    ans += r[-1-r_cnt] - q[-y+q_cnt]
    q_cnt += 1
    r_cnt += 1

  else:
    break

print(ans)

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

i=j=k=0
oi=0
while i<c:
  if x>j and y>k:
    if p[j]>=q[k] and q[k]<r[i]:
      q[k]=r[i]
      k+=1
      i+=1
    elif p[j]<q[k] and p[j]<r[i]:
      p[j]=r[i]
      j+=1
      i+=1
  elif x>j:
    if p[j]<r[i]:
      p[j]=r[i]
      j+=1
      i+=1
  elif y>k:
    if q[k]<r[i]:
      q[k]=r[i]
      k+=1
      i+=1
  if oi==i:break
  oi=i

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

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

p.append(0)
q.append(0)
r.append(0)
for i in range(X,A):
    p[i] = 0
for i in range(Y,B):
    q[i] = 0

a = 0
b = 0
c = 0
cnt = 0

for i in range(X+Y):
    if (not a == X) and p[a] >= q[b] and p[a] >= r[c]:
        cnt += p[a]
        a += 1
    elif (not b == Y) and q[b] >= r[c]:
        cnt += q[b]
        b += 1
    else:
        cnt += r[c]
        c += 1
print(cnt)

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()
apples = p[:x] + q[:y]
heapq.heapify(apples)
while r:
    val = r.pop()
    apple = heapq.heappop(apples)
    if apple>= val:
        heapq.heappush(apples,apple)
        break
    else:
        heapq.heappush(apples,val)
print(sum(apples))

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)

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

Solution (Python):

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

cand = sorted(P[-X:] + Q[-Y:] + R)
print(sum(cand[-X-Y:]))

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)

apples = sorted(P + Q + R, reverse=True)[:X + Y]

print(sum(apples))

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

apples = []
for p in map(int, input().split(' ')):
    apples.append((p, 0))

for q in map(int, input().split(' ')):
    apples.append((q, 1))

for r in map(int, input().split(' ')):
    apples.append((r, 2))

apples.sort(reverse=True)

pq = []
r = []
x = X
y = Y

for d, t in apples:
    if t == 0:
        if x > 0:
            x -= 1
            pq.append(d)
        else:
            continue
    elif t == 1:
        if y > 0:
            y -= 1
            pq.append(d)
        else:
            continue
    else:
        r.append(d)

pq_len = len(pq)
for i in range(len(r)):
    if i >= pq_len:
        break

    if r[i] <= pq[-(i + 1)]:
        break

    pq[-(i + 1)] = r[i]

print(sum(pq))

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 = p[:X]
green = q[:Y]

all_apple = red+green+r
all_apple.sort(reverse=True)

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

Solution (Python):
x, y, a, b, c = map(int, input().split())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))
list_C = list(map(int, input().split()))
list_A.sort(reverse=True)
list_B.sort(reverse=True)
list_C.sort(reverse=True)

list_N = list_A[:x] + list_B[:y] + list_C[:min(c, x + y)]
list_N.sort(reverse=True)
print(sum(list_N[: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)
print(sum(sorted(P[:x]+Q[:y]+R, reverse=True)[:x+y]))

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

P = [[] for _ in range(3)]

for p in map(int, input().split()):
    P[0].append((p,0))
for p in map(int, input().split()):
    P[1].append((p,1))
for p in map(int, input().split()):
    P[2].append((p,2))
P[0].sort(reverse=True)
P[1].sort(reverse=True)
P[2].sort()

P[0] = P[0][:X]
P[1] = P[1][:Y]

data = P[0] + P[1]
data.sort(reverse=True)
num = [A,B]
res = sum(map(lambda x: x[0], data))
while True:
    p, i = data.pop()
    q, _ = P[2].pop()
    if p >= q:
        break
    if num[i] - 1 >= 0:
        num[i] -= 1
        res += q - p
    if sum(num) == 0:
        break
    if len(P[2]) == 0:
        break

print(res)

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    X, Y, A, B, C, *PQR = map(int, read().split())
    P = PQR[:A]
    Q = PQR[A : A + B]
    R = PQR[A + B :]

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

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    X, Y, A, B, C, *PQR = map(int, read().split())
    P = PQR[:A]
    Q = PQR[A : A + B]
    R = PQR[A + B :]

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

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    X, Y, A, B, C, *PQR = map(int, read().split())
    P = PQR[:A]
    Q = PQR[A : A + B]
    R = PQR[A + B :]

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

    P = P[:X]
    Q = Q[:Y]
    S = []

    while R and (P or Q):
        if not P:
            vec = Q
        elif not Q:
            vec = P
        elif P[-1] < Q[-1]:
            vec = P
        else:
            vec = Q

        if vec[-1] < R[-1]:
            S.append(R.pop())
            vec.pop()
        else:
            break

    ans = sum(P) + sum(Q) + sum(S)

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

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

bag = p + q + r
bag = sorted(bag, reverse=True)
print(sum(bag[:(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)

sa = sum(p[:X])
sb = sum(q[:Y])

p.append(float('inf'))
q.append(float('inf'))


ans = sa + sb
nr = 0
np = X-1
nq = Y-1
while nr < len(r):
  if r[nr] <= min(p[np], q[nq]):
    break
  elif p[np] > q[nq]:
    ans += r[nr] - q[nq]
    nr += 1
    nq -= 1
    continue
  else:
    ans += r[nr] - p[np]
    nr += 1
    np -= 1
    continue

  
print(ans)

Solution (Python):
''' 1.降序排列，选出x个红苹果，y个绿苹果
    2.使用c个无色苹果去更新这x+y个苹果中的小值，直到最小也比无色苹果的大为止'''
nums = [int(i) for i in input().split()]
x = nums[0]
y = nums[1]
a = nums[2]
b = nums[3]
c = nums[4]
redApples = [int(i) for i in input().split()]
greenApples = [int(i) for i in input().split()]
colorless = [int(i) for i in input().split()]

redApples.sort(reverse=True)
greenApples.sort(reverse=True)
colorless.sort(reverse=True)
redApples = redApples[:x]
greenApples = greenApples[:y]

res = redApples+greenApples
res.sort(reverse=True)
currIndex = len(res)-1
for i in range(len(colorless)):
    if colorless[i] <= res[currIndex]:
        break
    res[currIndex] = colorless[i]
    currIndex -= 1
    if currIndex < 0:
        break

print(sum(res))

Solution (Python):
import heapq as hq
import sys


def main():
    input = sys.stdin.buffer.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()))
    p = sorted(p, reverse=True)[:x]
    q = sorted(q, reverse=True)[:y]
    r.sort(reverse=True)
    hq.heapify(p)
    hq.heapify(q)
    
    r_pointer = 0
    while True:
        red_min = p[0]
        green_min = q[0]
        if red_min < green_min and red_min < r[r_pointer]:
            hq.heappop(p)
            hq.heappush(p, r[r_pointer])
            r_pointer += 1
            if r_pointer >= c:
                break
        elif red_min >= green_min and green_min < r[r_pointer]:
            hq.heappop(q)
            hq.heappush(q, r[r_pointer])
            r_pointer += 1
            if r_pointer >= c:
                break
        else:
            break
    print(sum(p) + sum(q))


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)
eat_p = p[:X]
eat_q = q[:Y]

all_apple = eat_p + eat_q + r
all_apple.sort(reverse=True)

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

Solution (Python):
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort()
q.sort()
r.sort()
top_red = p[-x:]
top_green = q[-y:]
final = top_red+top_green+r
final.sort()
print(sum(final[-(x+y):]))

Solution (Python):
x,y,a,b,c = map(int, input().split())
li_p = list(map(int, input().split()))
li_q = list(map(int, input().split()))
li_r = list(map(int, input().split()))
li_p.sort(reverse=True)
li_q.sort(reverse=True)
li_r.sort(reverse=True)
r = []
for i in range(x):
  r.append(li_p[i])
for i in range(y):
  r.append(li_q[i])
for i in range(c):
  r.append(li_r[i])
r.sort(reverse=True)
print(sum(r[:x+y]))

Solution (Python):
from heapq import heappop, heappush
X, Y, A, B, C = map(int, input().split())
h = []
for p in map(int, input().split()):
    heappush(h, (-p, 1))
for q in map(int, input().split()):
    heappush(h, (-q, 2))
for r in map(int, input().split()):
    heappush(h, (-r, 3))

ans = 0
cnt = 0
total = X + Y
while cnt < total:
    point, color = heappop(h)
    if color == 1:
        if X > 0:
            ans += -point
            X -= 1
            cnt += 1
    elif color == 2:
        if Y > 0:
            ans += -point
            Y -= 1
            cnt += 1
    elif color == 3:
        ans += -point
        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()))

    sorted_p = sorted(p, reverse=True)[:X]
    sorted_q = sorted(q, reverse=True)[:Y]
    sorted_r = sorted(r, reverse=True)

    p_itr, q_itr, r_itr = X-1, Y-1, 0
    
    while r_itr < C:
        look_p = sorted_p[p_itr]
        look_q = sorted_q[q_itr]
        look_r = sorted_r[r_itr]

        if look_p <= look_q and p_itr >=0:
            if look_p <= look_r:
                sorted_p[p_itr] = look_r
                p_itr -= 1
                r_itr += 1
            else:
                break

        elif q_itr >= 0:
            if look_q <= look_r:
                sorted_q[q_itr] = look_r
                q_itr -= 1
                r_itr += 1
            else:
                break

        else:
            break

    res = sum(sorted_p) + sum(sorted_q)
    print(res)

if __name__ == "__main__":
    main()

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

ans = sum(sorted(p+q+r, reverse=True)[:X+Y])
print(ans)

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

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

n = 0
np = 0
nq = 0
ans = 0
while n < x + y:
    cs = []
    if p and np < x:
        cs.append(p[-1])
    if q and nq < y:
        cs.append(q[-1])
    if r:
        cs.append(r[-1])
    m = max(cs)
    if r and m == r[-1]:
        ans += r.pop()
    elif p and m == p[-1]:
        ans += p.pop()
        np += 1
    else:
        ans += q.pop()
        nq += 1
    n += 1

print(ans)

Solution (Python):

import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()


INF = float('inf')


x, y, a, b, c = LI()
p = sorted(LI())[::-1][:x]
q = sorted(LI())[::-1][:y]
r = sorted(LI())[::-1][:x+y]
bucket = []
bucket += [i for i in p]
bucket += [i for i in q]
bucket += [i for i in r]
bucket = sorted(bucket)[::-1]
ans = sum(bucket[:x+y])
print(ans)

Solution (Python):

import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()


INF = float('inf')


x, y, a, b, c = LI()
p = sorted(LI())[::-1][:x]
q = sorted(LI())[::-1][:y]
r = sorted(LI())[::-1][:x+y]

bucket = []
bucket += [[i, 'p'] for i in p]
bucket += [[i, 'q'] for i in q]
bucket += [[i, 'r'] for i in r]
bucket = sorted(bucket, key=lambda x: x[0])

d = {'p': 0, 'q': 0}
ans = 0
cnt = 0
while cnt < x + y:
    if bucket[-1][1] == 'p' and d[bucket[-1][1]] < x:
        ans += bucket.pop()[0]
        d['p'] += 1
        cnt += 1
    elif bucket[-1][1] == 'q' and d[bucket[-1][1]] < y:
        ans += bucket.pop()[0]
        d['q'] += 1
        cnt += 1
    else:
        ans += bucket.pop()[0]
        cnt += 1
print(ans)

Solution (Python):


import math

import itertools
from collections import deque
from collections import Counter



import bisect
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)
ansp=p[:x]
ansq=q[:y]
ans=sum(ansp)+sum(ansq)
ep=x-1
eq=y-1
for i in range(c):
    if ep<0 and eq<0:
        break
    if (ep>=0 and eq<0) or (ep>=0 and eq>=0 and ansp[ep]<ansq[eq]):
        if ansp[ep]<r[i]:
            ans=ans-ansp[ep]+r[i]
            ep-=1 
        else:
            break
    elif (eq>=0 and ep<0) or (ep>=0 and eq>=0 and ansq[eq]<=ansp[ep]):
        if ansq[eq]<r[i]:
            ans=ans-ansq[eq]+r[i]
            eq-=1
        else:
          break
print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 

from decimal import *


	
X, Y, A, B, C = MAP()
p = deque(sorted(LIST(), reverse=True))
q = deque(sorted(LIST(), reverse=True))
r = deque(sorted(LIST(), reverse=True) + [0])

x = 0
y = 0
z = 0
ans = 0
while x+y+z < X+Y:
	compare = (p[0], q[0], r[0])

	if p[0] == max(compare):
		x += 1
		ans += p.popleft()
		if x == X:
			p = [0]
	elif q[0] == max(compare):
		y += 1
		ans += q.popleft()
		if y == Y:
			q = [0]
	else:
		z += 1
		ans += r.popleft()

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 

from decimal import *


	
X, Y, A, B, C = MAP()
p = deque(sorted(LIST(), reverse=True) + [0])
q = deque(sorted(LIST(), reverse=True) + [0])
r = deque(sorted(LIST(), reverse=True) + [0])

x = 0
y = 0
z = 0
ans = 0
while x+y+z < X+Y:
	compare = (p[0], q[0], r[0])

	if p[0] == max(compare):
		x += 1
		ans += p.popleft()
		if x == X:
			p = [0]
	elif q[0] == max(compare):
		y += 1
		ans += q.popleft()
		if y == Y:
			q = [0]
	else:
		z += 1
		ans += r.popleft()

print(ans)

Solution (Python):
X,Y,A,B,C = map(int,input().split())
AList = sorted(list(map(int,input().split())),reverse=True)
BList = sorted(list(map(int,input().split())),reverse=True)
CList = sorted(list(map(int,input().split())),reverse=True)
FullList = sorted(AList[:X] + BList[:Y])
counter = 0
for i in range(min(C,X+Y)):
  if CList[i] <= FullList[i]:
    break
  else:
    counter += 1
ans = sum(CList[:counter])+sum(FullList[counter:])
print(ans)

Solution (Python):
X, Y, A, B, C = [int(_) for _ in input().split()]
P = [int(_) * 3 for _ in input().split()]
Q = [int(_) * 3 + 1 for _ in input().split()]
R = [int(_) * 3 + 2 for _ in input().split()]
S = sorted(P + Q + R)
cnt = [0, 0, 0]
ans = [0, 0, 0]
limit = [X, Y, 10**10]
while S:
    s = S.pop()
    q, r = divmod(s, 3)
    if cnt[r] >= limit[r]:
        continue
    cnt[r] += 1
    ans[r] += q
    if sum(cnt) == X + Y:
        print(sum(ans))
        exit()

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()))
import heapq as hp
s = x+y
u = []
hp.heapify(u)
for i in range(a):
    hp.heappush(u,[-p[i],'r'])
for i in range(c):
    hp.heappush(u,[-r[i],'m'])
v = []
hp.heapify(v)
for i in range(b):
    hp.heappush(v,[-q[i],'g'])
for i in range(c):
    hp.heappush(v,[-r[i],'m'])
z = []
ans = 0
hp.heapify(z)
for i in range(a):
    hp.heappush(z,[-p[i],'r'])
for i in range(b):
    hp.heappush(z,[-q[i],'g'])
for i in range(c):
    hp.heappush(z,[-r[i],'m'])
while s and x and y:
    t = hp.heappop(z)
    ans += -t[0]
    if t[1] == 'r':
        x -= 1
        s -=1
    elif t[1] == 'g':
        y -= 1
        s -= 1
    else:
        s -= 1
if s > 0 and x > 0:
    while s:
        t = hp.heappop(z)
        if t[1] == 'g':
            continue
        else:
            ans += -t[0]
            s -= 1
elif s > 0 and y > 0:
    while s:
        t = hp.heappop(z)
        if t[1] == 'r':
            continue
        else:
            ans += -t[0]
            s -= 1
print(ans)

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

a_list=list(map(int,input().split()))
a_list=sorted(a_list)
b_list=list(map(int,input().split()))
b_list=sorted(b_list)
a_list=a_list[-x:]
b_list=b_list[-y:]
c_list=list(map(int,input().split()))
for i in range(c):
    c_list[i]=-c_list[i]
import heapq
heapq.heapify(a_list)
heapq.heapify(b_list)
heapq.heapify(c_list)

flag=True
while flag and c_list:
    x=heapq.heappop(c_list)
    x=x*(-1)
    
    min_a=heapq.heappop(a_list)
    min_b=heapq.heappop(b_list)
    if min(min_a,min_b)>=x:
        flag=False
        heapq.heappush(a_list,min_a)
        heapq.heappush(b_list,min_b)
    else:
        if min_a>=min_b:
            heapq.heappush(a_list,min_a)
            heapq.heappush(b_list,x)
         
        elif min_a<min_b:
            heapq.heappush(b_list,min_b)
            heapq.heappush(a_list,x)

sum_a=sum(list(a_list))
sum_b=sum(list(b_list))

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

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





p = 0
q = 0
r = 0
ans = 0
for i in range(x+y):
    if p < x:
        red = P[p]
    else:
        red = 0
    if q < y:
        green = Q[q]
    else:
        green = 0
    if r < c:
        white = R[r]
    else:
        white = 0
    
    choice = max(red, green, white)
    
    ans += choice
    
    if choice == red:
        p += 1
    elif choice == green:
        q += 1
    else:
        r += 1
print(ans)

Solution (Python):
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()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
l = p[:X]+q[:Y]
l.sort()
s = sum(l)
ans = s
pre = s

for i in range(min(len(l), C)):
    ans = max(ans, pre-l[i]+r[i])
    pre = pre-l[i]+r[i]

print(ans)

Solution (Python):
X, Y, A, B, C = map(int, input().split())
Ap = list(map(int, input().split()))
Bq = list(map(int, input().split()))
Cr = list(map(int, input().split()))

Ap.sort()
Bq.sort()

print(sum(sorted(Ap[A-X:] + Bq[B-Y:] + Cr)[C:]))

Solution (Python):
X, Y, A, B, C = map(int, input().split())
Ap = list(map(int, input().split()))
Bq = list(map(int, input().split()))
Cr = list(map(int, input().split()))

Ap.sort(reverse = True)
Bq.sort(reverse = True)

L = sorted(Ap[:X] + Bq[:Y] + Cr, reverse = True)

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

Solution (Python):
X, Y, A, B, C = map(int, input().split())
Ap = list(map(lambda x: (int(x), 0), input().split()))
Bq = list(map(lambda x: (int(x), 1), input().split()))
Cr = list(map(lambda x: (int(x), 2), input().split()))

INF = 2 * 10**5 + 1

L = Ap + Bq + Cr
L.sort(reverse = True)

cnt = [0, 0, 0]
cntM = [X, Y, INF]
s = 0

ans = 0

for x, i in L:
  if s == X + Y:
    break
  elif cnt[i] < cntM[i]:
    ans += x
    cnt[i] += 1
    s += 1
  else:
    pass

print(ans)