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 = deque(sorted(list(map(int,input().split())),reverse=True)[:x])
Q = deque(sorted(list(map(int,input().split())),reverse=True)[:y])
R = deque(sorted(list(map(int,input().split())),reverse=True))
p = P.pop()
q = Q.pop()
r = R.popleft()
ans = 0

while p < r or q < r:
    ans += r
    if len(R) != 0:   
        r = R.popleft()
    else:
        r = 0
    if p < q:
        if len(P) != 0:   
            p = P.pop()
        else:
            p = 10**10
    else:
        if len(Q) != 0:   
            q = Q.pop()
        else:
            q = 10**10
            
ans += sum(P)+sum(Q)
if p != 10**10:
    ans += p
if q != 10**10:
    ans += q
print(ans)

Solution (Python):



def main():
  x, y, na, nb, nc = map(int, input().split())
  la = list(map(int, input().split()))
  la.sort(reverse=True)
  lb = list(map(int, input().split()))
  lb.sort(reverse=True)
  lc = list(map(int, input().split()))
  lc.sort(reverse=True)
  ca, cb, cc = 0, 0, 0,
  
  s = 0
  while True:
    if sum([ca, cb, cc]) == x+y:
      break
      
    a = la[ca] if na > ca and ca < x else -1
    b = lb[cb] if nb > cb and cb < y else -1
    c = lc[cc] if nc > cc            else -1
            
    if a >= b and a >= c:
      s += a
      ca += 1
      continue
      
    if b >= a and b >= c:
      s += b
      cb += 1
      continue
      
    if c >= b and c >= a:
      s += c
      cc += 1
      
  print(s)

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

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

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

Solution (Python):
from functools import lru_cache

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)

red = P[:X]
green = Q[:Y]
best = sum(red) + sum(green)

for x in R:
    a1, a2 = red, green
    if not a1 and not a2:
        break
    if not a1:
        a1 = a2
    if a1 and a2 and a1[-1] > a2[-1]:
        a1, a2 = a2, a1
    if a1[-1] < x:
        best -= a1.pop()
        best += x
print(best)

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)

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

sortp = sorted(p)[::-1]
sortq = sorted(q)[::-1]
redpoints = sortp[:x]
greenpoints = sortq[:y]
sortedpoints = sorted(redpoints+greenpoints+r)[::-1]
print(sum(sortedpoints[:x+y]))

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

reds.sort(reverse=True)
greens.sort(reverse=True)
nos.sort(reverse=True)

bests = reds[:X]+greens[:Y]+nos
bests.sort(reverse=True)
print(sum(bests[: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)

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

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

p = [int(x) for x in input().split()]
p.sort(reverse=True)
p = p[:x]

q = [int(x) for x in input().split()]
q.sort(reverse=True)
q = q[:y]
r = [int(x) for x in input().split()]
r.sort(reverse=True)

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

Solution (Python):
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

if __name__ == "__main__":
    X, Y, A, B, C = MI()
    p = LI()
    p.sort(reverse=True)
    q = LI()
    q.sort(reverse=True)
    pq = p[:X] + q[:Y] + LI()
    pq.sort(reverse=True)
    print(sum(pq[: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)

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

Solution (Python):
(x,y,*_),*t=[map(int,t.split())for t in open(0)]
s=sorted
p,q,r=map(s,t)
print(sum(s(p[-x:]+q[-y:]+r)[-x-y:]))

Solution (Python):


X,Y,A,B,C = [int(i) for i in 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.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

r_len = min(X+Y, len(R))
V = P[:X] + Q[:Y] + R[:r_len]
V.sort(reverse=True)

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

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


if __name__ == '__main__':
    main()

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()))
ans = 0
z = 0
while x + y + z > 0:
    if p[-1] > max(q[-1], r[-1]) and x:
        x -= 1
        ans += p.pop()
        if not p or not x:
            p.append(-1)
    elif q[-1] > r[-1] and y:
        y -= 1
        ans += q.pop()
        if not q or not y:
            q.append(-1)
    else:
        z -= 1
        ans += r.pop()
        if not r:
            r.append(-1)
print(ans)

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

s_a = [int(i) for i in list(input().split())]
s_b = [int(i) for i in list(input().split())]
s_c = [int(i) for i in list(input().split())]

s_a.sort(reverse = True)
s_b.sort(reverse = True)
s_c.sort(reverse = True)

x_a = s_a[0:x]
x_b = s_b[0:y]


sum_a = x_a + x_b + s_c
sum_a.sort(reverse = True)
sum_a = sum_a[0:x+y]
print(sum(sum_a))

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)

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


ans = 0


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

anslist = list()


for i in range(x):
    anslist.append(p[i])

for i in range(y):
    anslist.append(q[i])

anslist.extend(r)

anslist.sort()
anslist.reverse()

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


print(ans)

Solution (Python):
import heapq
X, Y, a, b, c = map(int, input().split())
p = list(map(lambda x: -int(x), input().split()))
q = list(map(lambda x: -int(x), input().split()))
r = list(map(lambda x: -int(x), input().split()))
p.sort()
q.sort()
t = p[:X] + q[:Y] + r

heapq.heapify(t)

ans = 0
for _ in range(X+Y):
    ap = heapq.heappop(t)
    ans -= ap

print(ans)

Solution (Python):
import sys,math,copy,queue,itertools
from fractions import gcd
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
INF = 10**18
MOD = 10**9 + 7
DD = ((1,0),(0,1),(-1,0),(0,-1))
X,Y,A,B,C = LI()
p = LI()
q = LI()
r = LI()
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
pa =  [0] + list(itertools.accumulate(p))
qa =  [0] + list(itertools.accumulate(q))
p = [INF] + p
q = [INF] + q
red = X
green = Y
t = 0
pl = 0
while p[red] < r[t] or q[green] < r[t]:
    pl += r[t]
    t += 1
    if red == 0:
        green -= 1
    elif green == 0:
        red -= 1

    elif p[red] < q[green] :
        red -= 1
    else:
        green -= 1
    if t >=C or (green ==0 and red ==0): break
print (pa[red] + qa[green] + pl)

Solution (Python):
x,y,a,b,c = list(map(int,input().split()))
p = list(map(int,input().split()))
p = sorted(p,reverse=True)
q = list(map(int,input().split()))
q = sorted(q,reverse=True)
r = list(map(int,input().split()))
r = sorted(r)
c_ori = c
while c >= 1 and ((x >= 1 and p[x-1] < r[c-1]) or (y >= 1 and q[y-1] < r[c-1])):
    if x >= 1 and y >= 1 and p[x-1] < q[y-1]:
        x = x-1
        c = c-1
    elif x >= 1 and y >= 1 and p[x-1] >= q[y-1]:
        y = y-1
        c = c-1
    elif y == 0:
        x = x-1
        c = c-1
    else:
        y = y-1
        c = c-1
               
sum = 0
if x >= 1:
    for i in range(x):
        sum += p[i]

if y >= 1:
    for i in range(y):
        sum += q[i]

if c_ori > c:
    for i in range(c,c_ori):
        sum += r[i]
print(sum)

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 = list(map(int, input().split()))
for i in range(x): r.append(p[a-i-1])
for i in range(y): r.append(q[b-i-1])
r.sort()
print(sum(r[len(r)-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)

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

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

print(sum(apple[:x + y]))

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

plist = sorted(list(map(int, input().split())))[::-1][:X]
qlist = sorted(list(map(int, input().split())))[::-1][:Y]
rlist = sorted(list(map(int, input().split())))
plist.extend(qlist)
plist.extend(rlist)

print(sum(sorted(plist, reverse=True)[:X + Y]))

Solution (Python):
import heapq

X, Y, A, B, C = map(int, input().split())
p = list(map(lambda x:int(x)*(-1), input().split()))
q = list(map(lambda x:int(x)*(-1), input().split()))
r = list(map(lambda x:int(x)*(-1), input().split()))
heapq.heapify(p)
heapq.heapify(q)

for _ in range(X):
    r.append(heapq.heappop(p))
for _ in range(Y):
    r.append(heapq.heappop(q))
heapq.heapify(r)

ans = 0
for _ in range(X+Y):
    ans += (-1) * heapq.heappop(r)
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):




def main():
  x, y, na, nb, nc = map(int, input().split())
  la = list(map(int, input().split()))
  la.sort(reverse=True)
  lb = list(map(int, input().split()))
  lb.sort(reverse=True)
  lc = list(map(int, input().split()))
  lc.sort(reverse=True)
  ca, cb, cc = 0, 0, 0
  
  lx = la[:x] + lb[:y] + lc
  lx.sort(reverse=True)
  print(sum(lx[:x+y]))

if __name__=='__main__':
  main()

Solution (Python):
X,Y,A,B,C=list(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)


s=sorted(p[:X]+q[:Y])

for i in range(min(len(r),len(s))):
    if s[i]<r[i]:
        s[i]=r[i]
    else:
        break

print(sum(s))

Solution (Python):


import numpy as np
X,Y,A,B,C = list(map(int,input().split()))
p =list(map(int,input().split()))
p.append(0)
p.sort(reverse = True)

q=list(map(int,input().split()))
q.append(0)
q.sort(reverse = True)
r = list(map(int,input().split()))
r.append(0)
r.sort(reverse = True)
 
p = np.array(p)
q = np.array(q)
r = np.array(r)
kotae = 0
a,b,c = 0,0,0
d,e =False,False
for i in range(X+Y):
    if a >= X:
        if d == False:
            p = p* 0
            d = True
    if b >= Y:
        if e == False:
            q = q*0
            e = True
    if p[a] > q[b]:
        if p[a] > r[c]:
            kotae += p[a]
            a +=1
        else:
            kotae += r[c]
            c += 1
    else:
        if q[b] > r[c]:
            kotae += q[b]
            b +=1
        else:
            kotae += r[c]
            c += 1
    
print(kotae)

Solution (Python):


iim = lambda: map(int, input().rstrip().split())

def resolve():
    X, Y, A, B, C = iim()
    P = list(iim())
    Q = list(iim())
    R = list(iim())

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

    p1 = [0]*(X+1)
    for i in range(X):
        p1[i+1] = p1[i] + P[i]
    q1 = [0]*(Y+1)
    for i in range(Y):
        q1[i+1] = q1[i] + Q[i]

    si = [X-1, Y-1]
    S = [P, Q]
    if P[si[0]] < Q[si[1]]:
        idx = 0
    else:
        idx = 1
    ans = 0
    swap = True
    for i in range(C):
        if S[idx][si[idx]] < R[i]:
            si[idx] -= 1
            ans += R[i]

            if si[idx] < 0:
                idx ^= 1
                if si[idx] <= 0:
                    break
                swap = False
            elif not swap:
                continue
            elif P[si[0]] < Q[si[1]]:
                idx = 0
            else:
                idx = 1
        else:
            break

    print(p1[si[0]+1] + q1[si[1]+1] + ans)

if __name__ == "__main__":
    resolve()

Solution (Python):
x, y, a, b, c = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
ABC = A[:x] + B[:y] + C
ABC.sort(reverse=True)
print(sum(ABC[:(x+y)]))

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 = list(map(int, input().split()))

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

Solution (Python):
def main():
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    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)
    print(sum(sorted((p+q+r), reverse=True)[:x+y]))

if __name__ == '__main__':
    main()

Solution (Python):
from collections import deque
x,y,a,b,c = list(map(int, input().split()))
r = sum(sorted(sorted(list(map(int, input().split())), reverse = True)[:x] + sorted(list(map(int, input().split())), reverse = True)[:y] + list(map(int, input().split())), reverse = True)[:x+y])








print(r)

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)
B = sorted(B)

A = A[len(A)-x:]
B = B[len(B)-y:]
C = list(map(lambda x: x*(-1), C))

import heapq
heapq.heapify(A)
heapq.heapify(B)
heapq.heapify(C)

flag = True
while flag:
  a = heapq.heappop(A)
  b = heapq.heappop(B)
  c = heapq.heappop(C)*(-1)
  if c < a and c < b:
    heapq.heappush(A, a)
    heapq.heappush(B, b)
    flag = False
  else:
    if a > b:
      heapq.heappush(A, a)
      heapq.heappush(B, c)
      if not C:
        break
    else:
      heapq.heappush(A, c)
      heapq.heappush(B, b)
      if not C:
        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()))
 
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
 
A_p = p[:X]
B_q = q[:Y]
C_r = r
 
ans = A_p + B_q + C_r
ans.sort(reverse=True)
print(sum(ans[: X+Y]))

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

pl = sorted(pl)
ql = sorted(ql)
rl = sorted(rl)
ansl = pl[-x:] + ql[-y:]

ansl += rl

ansl = sorted(ansl)
print(sum(ansl[-(x+y):]))

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

i = 0
ans = 0
for a in l:
    if i < C and r[i] <= a:
        ans += a
    elif i < C and r[i] > a:
        ans += r[i]
        i += 1
    else:
        ans += a

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 = list(map(int, input().split()))

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

Solution (Python):
import sys


from collections import Counter, deque, defaultdict





import math



readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

import heapq


class Reverse:
    def __init__(self, val):
        self.val = val

    def __lt__(self, other):
        return self.val > other.val

    def __repr__(self):
        return repr(self.val)


class PriorityQueue:

    def __init__(self, x=[], desc=False):
        if desc:
            for i in range(len(x)):
                x[i] = Reverse(x[i])
        self._desc = desc
        self._container = x
        heapq.heapify(self._container)

    @property
    def is_empty(self):
        return not self._container

    def pop(self):
        if self._desc:
            return heapq.heappop(self._container).val
        else:
            return heapq.heappop(self._container)

    def push(self, item):
        if self._desc:
            heapq.heappush(self._container, Reverse(item))
        else:
            heapq.heappush(self._container, item)

    def top(self):
        if self._desc:
            return self._container[0].val
        else:
            return self._container[0]

    def sum(self):
        return sum(self._container)

    def __len__(self):
        return len(self._container)


def main():
    x, y, a, b, c = list(map(int, readline().split()))
    p = list(map(int, readline().split()))
    q = list(map(int, readline().split()))
    r = list(map(int, readline().split()))

    p.sort()
    q.sort()
    r = PriorityQueue(r,desc=True)

    eat = p[-x:]
    eat.extend(q[-y:])
    eat = PriorityQueue(eat)

    while eat.top() < r.top():
        _ = eat.pop()
        eat.push(r.pop())
        c -= 1
        if c == 0:
            break

    print(eat.sum())





if __name__ == '__main__':
    main()

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)

p.insert(0, 10**9)
p.append(0)
q.insert(0, 10**9)
q.append(0)
r.append(0)

result = sum(p[1:x+1]) + sum(q[1:y+1])
i = 0
red_min = x
blue_min = y
flag = True

while flag == True:
    if r[i] > p[red_min] or r[i] > q[blue_min]:
        if p[red_min] < q[blue_min]:
            result = result - p[red_min] + r[i]
            i += 1
            red_min -= 1
        else:
            result = result - q[blue_min] + r[i]
            i += 1
            blue_min -= 1
    else:
        flag = False
print(result)

Solution (Python):
x,y,a,b,c=[int(i) for i in 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=sorted(p)[::-1]
q=sorted(q)[::-1]

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

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)

eat_r = p[:x]
eat_g = q[:y]
eat = eat_r + eat_g
sort_eat = sorted(eat)
for i in r:
    if sort_eat[0] < i:
        sort_eat.append(i)
sort_eat.sort(reverse=True)

print(sum(sort_eat[: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()

for _ in range(x):
    r.append(p.pop(-1))

for _ in range(y):
    r.append(q.pop(-1))

r.sort()

d = 0
for _ in range(x + y):
    d += r.pop(-1)

print(d)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

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

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

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
INF = 10 ** 10
MOD = 10 ** 9 + 7
from heapq import heapify,heappop,heappush
input = sys.stdin.readline

def main():
    x,y,a,b,c = map(int,input().split())
    R = list(map(int,input().split()))
    G = list(map(int,input().split()))
    M = list(map(int,input().split()))
    R.sort(reverse = True)
    G.sort(reverse = True)
    M.sort(reverse = True)
    apple = R[:x] + G[:y] + M
    apple.sort(reverse = True)
    ans = sum(apple[:x + y])
    print(ans)
if __name__=='__main__':
    main()

Solution (Python):
from sys import stdin

input = 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)

lis = []

for i in range(X):
    lis.append(P[i])

for i in range(Y):
    lis.append(Q[i])

for i in range(min(len(R), X + Y)):
    lis.append(R[i])

lis.sort(reverse=True)

ans = 0

for i in range(X + Y):
    ans += lis[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)
all = []
for i in range(x):
    all.append(p[i])
for i in range(y):
    all.append(q[i])
for i in range(c):
    all.append(r[i])
all = sorted(all, reverse=True)
res = 0
for i in range(x + y):
    res += all[i]
print(res)

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

e = sorted(P)[-x:]
e += sorted(Q)[-y:]
e += R
print(sum(sorted(e,reverse=True)[: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()
p.reverse()
q.sort()
q.reverse()
del p[X:]
del q[Y:]
p.extend(q)
p.extend(r)
p.sort()
p.reverse()
del p[X+Y:]
d = sum(p)
print(d)

Solution (Python):
import heapq


class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)

    def pop(self):
        return heapq.heappop(self.hq) * self.sign

    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)

    def top(self):
        return self.hq[0] * self.sign


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

red = [int(i) for i in input().split()]
green = [int(i) for i in input().split()]
clear = [int(i) for i in input().split()]

red = Heapq(red, True)
green = Heapq(green, True)
clear = Heapq(clear, True)

ans = []
for i in range(x):
    clear.push(red.pop())
for j in range(y):
    clear.push(green.pop())
ans = 0
for k in range(x + y):
    ans += clear.pop()
print(ans)

Solution (Python):
x, y, a, b, c = map(int, input().split())
arrayP = list(map(int, input().split()))
arrayQ = list(map(int, input().split()))
arrayR = list(map(int, input().split()))
arrayP.sort(reverse=True)
arrayQ.sort(reverse=True)
arrayR.sort(reverse=True)
arrayAns = []
for i in range(x):
    arrayAns.append(int(arrayP[i]))
for i in range(y):
    arrayAns.append(int(arrayQ[i]))
arrayAns.sort()
for i in range(min(len(arrayR), len(arrayAns))):
    if arrayAns[i] <= int(arrayR[i]):
        arrayAns[i] = int(arrayR[i])
    else:
        break
print(sum(arrayAns))

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()))
ans=[]
ans+=p[A-X:]
ans+=q[B-Y:]
ans.sort()
j=0
k=0
for i in ans:
	if len(r)>1:
		k=r[-1]
	elif len(r)==1:
		k=r[0]
	else:
		break
	if i<k:
		ans[j]=r.pop()
		j+=1
	else:
		break
print(sum(ans))

Solution (Python):
from heapq import heappush, heappop

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)

ans = sum(P[:X]) + sum(Q[:Y])
apples = []
for p in P[:X]:
    heappush(apples, p)

for q in Q[:Y]:
    heappush(apples, q)

for r in R:
    amin = heappop(apples)
    if r >= amin:
        heappush(apples, r)
        ans += (r - amin)
    else:
        break

print(ans)

Solution (Python):
import numpy as np
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())), reverse=True)

PQ=sorted(P+Q)

ans=0
for i in range(len(PQ)):
  if len(R)>0:
    
    now=max(PQ[i], R.pop(0))
  else:
    now=PQ[i]
  ans+=now
  
print(ans)

Solution (Python):
import heapq

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 = sorted(map(int, input().split()), reverse=True)

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

heapq.heapify(red)
heapq.heapify(green)

for nc in nocolor:
    R = red[0]
    G = green[0]
    if R > nc and G > nc:
        break
    elif nc > R and nc > G:
        if R > G:
            q = heapq.heappop(green)
            heapq.heappush(green, nc)
        else:
            q = heapq.heappop(red)
            heapq.heappush(red, nc)
    elif nc > R:
        q = heapq.heappop(red)
        heapq.heappush(red, nc)
    elif nc > G:
        q = heapq.heappop(green)
        heapq.heappush(green, nc)

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

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())))
S=sorted(P[A-X:]+Q[B-Y:])
ans=sum(S)
for i in range(min(len(R),len(S))):
    if S[i]<R[-1-i]:
        S[i]=R[-1-i]
    else:
        break
print(sum(S))

Solution (Python):
from itertools import *
from heapq import *

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

S = sum(islice(merge(islice(P, X),islice(Q, Y),R), X+Y))

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

a = []
for i in range(x):
    a.append(p[i])

for i in range(y):
    a.append(q[i])

for i in range(c):
    a.append(r[i])

a.sort(reverse=True)
ans = 0
for i in range(x + y):
    ans += a[i]

print(ans)

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

pp = x - 1
qp = y - 1
rp = 0
while rp < c:
    if pp < 0 and r[rp] > q[qp]:
        q[qp] = r[rp]
        qp -= 1
    elif qp < 0 and r[rp] > p[pp]:
        p[pp] = r[rp]
        pp -= 1 
    elif pp < 0 and qp < 0:
        break
    elif r[rp] > p[pp] or r[rp] > q[qp]:
        if p[pp] > q[qp]:
            q[qp] = r[rp]
            qp -= 1
        else:
            p[pp] = r[rp]
            pp -= 1
    rp += 1
 

print(sum(p[:x]) + sum(q[:y]))

Solution (Python):
from pprint import pprint
from bisect import bisect_left
import numpy


def read():
    X, Y, A, B, C = list(map(int, input().strip().split()))
    P = list(map(int, input().strip().split()))
    Q = list(map(int, input().strip().split()))
    R = list(map(int, input().strip().split()))
    return X, Y, A, B, C, P, Q, R

def argsort(x, reverse=False):
    return sorted(range(len(x)), key=lambda k: x[k], reverse=reverse)

def solve(X, Y, A, B, C, P, Q, R):
    P = list(sorted(P, reverse=True))
    Q = list(sorted(Q, reverse=True))
    R = list(sorted(R, reverse=True))

    i = X
    j = Y
    score = sum(P[0:i]) + sum(Q[0:j])
    for r in R:
        if i > 0 and j > 0:
            if P[i-1] < Q[j-1] and P[i-1] < r:
                score = score - P[i-1] + r
                i -= 1
            elif Q[j-1] <= P[i-1] and Q[j-1] < r:
                score = score - Q[j-1] + r
                j -= 1
            else:
                break
        elif i > 0:
            if P[i-1] < r:
                score = score - P[i-1] + r
                i -= 1
            else:
                break
        elif j > 0:
            if Q[j-1] < r:
                score = score - Q[j-1] + r
                j -= 1
            else:
                break
        else:
            break
    return sum(P[:i] + Q[:j] + R[:(X-i)+(Y-j)])

if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))