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 numpy as np
x, y, red_num, green_num, white_num = [int(i) for i in input().split()]
red_list = [int(i) for i in input().split()]
green_list = [int(i) for i in input().split()]
white_list = [int(i) for i in input().split()]
sum = 0

red_list.sort(reverse=True)
green_list.sort(reverse=True)

apple = red_list[:x] + green_list[:y] + white_list
apple.sort(reverse=True)
for i in apple[:(x+y)]:
	sum += i
print(sum)

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)

li = []
for i in range(x):
    li.append(p[i])
for i in range(y):
    li.append(q[i])

sm = 0
v = 0
for e in sorted(li):
    if v < c and r[v] > e:
        sm += r[v]
        v += 1
    else:
        sm += e

print(sm)

Solution (Python):

DATA = """
2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4
""".split("\n")

def get_debug_line():
	for i in DATA:
		yield i

if 1:
	get_line = input
else:
	get_line = get_debug_line().__next__
	get_line()

X, Y, A, B, C = [int(i) for i in get_line().strip().split(" ")]
p = [int(i) for i in get_line().strip().split(" ")]
q = [int(i) for i in get_line().strip().split(" ")]
r = [int(i) for i in get_line().strip().split(" ")]

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

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

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


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

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

pn.sort(reverse=True)
qn.sort(reverse=True)

pqr = pn[:x] + qn[:y] + rn
pqr.sort(reverse=True)
  
print(sum(pqr[:x+y]))

Solution (Python):
X,Y,A,B,C=map(int,input().split())
p=sorted(list(map(int,input().split())))[::-1][:X]
q=sorted(list(map(int,input().split())))[::-1][:Y]
r=list(map(int,input().split()))
ans=sorted(p+q+r)[::-1][:X+Y]
print(sum(ans))

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)

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

print(sum(eatCandi[0:X+Y]))

Solution (Python):
def mangoes(x, y, red, yellow, cc):
	red = sorted(red)
	red.reverse()
	yellow = sorted(yellow)
	yellow.reverse()
	cc = sorted(cc)
	cc.reverse()
	red = red[:x]
	yellow = yellow[:y]
	newa = red + yellow + cc
	newa = sorted(newa)
	newa.reverse()
	ans = sum(newa[:x + y])
	return ans

well = input().split(' ')
x = int(well[0])
y = int(well[1])
a = int(well[2])
b = int(well[3])
c = int(well[4])
red = input().split(' ')
red = [int(x) for x in red]
yellow = input().split(' ')
yellow = [int(x) for x in yellow]
cc = input().split(' ')
cc = [int(x) for x in cc]

print(mangoes(x, y, red, yellow, cc))

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

red.sort(reverse=True)
green.sort(reverse=True)
trans.sort(reverse=True)
apple = red[:X] + green[:Y]
apple.sort()

j = 0
for i in range(X + Y):
    if apple[i] < trans[j]:
        apple[i] = trans[j]
        j = j + 1
        if j == C:
            break
    else:
        continue
print(sum(apple))

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

L=P+Q+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()))

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

red = P[:X]
green = Q[:Y]
ans = sum(red + green)
rg = sorted(red + green)

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

print(ans)

Solution (Python):
from operator import itemgetter
from collections import deque

def main():
    x,y,r,g,b = map(int,input().split())
    red = deque(sorted(list(map(int, input().split())),reverse=True)[:x])
    grn = deque(sorted(list(map(int, input().split())),reverse=True)[:y])
    non = sorted(list(map(int, input().split())),reverse=True)
    for i in non:
        dic = {
            'r' : red.pop(),
            'g' : grn.pop(),
            'b' : i,
        }
        
        
        res = sorted(dic.items(), key=itemgetter(1))[-2:]
        res.sort(key=itemgetter(0),reverse=True)

        key = [i[0] for i in res]
        val = [i[1] for i in res]
        if key == ['r','g']:
            red.append(val[0])
            grn.append(val[1])
        elif key == ['r','b']:
            red.append(val[0])
            grn.appendleft(val[1])
        else:
            grn.append(val[0])
            red.appendleft(val[1])

    print(sum(red)+sum(grn))



if __name__ == '__main__':
    main()

Solution (Python):
from heapq import heapify, heappop, heappush 
x, y, a, b, c = map(int, input().split())
p_List = list(map(int, input().split()))
q_List = list(map(int, input().split()))
r_List = list(map(int, input().split()))
p_List.sort()
q_List.sort()
r_List.sort()

ans = p_List[-x:] + q_List[-y:]
heapify(ans)
for i in r_List[::-1]:
    tmp = heappop(ans)
    if tmp < i:
        heappush(ans, i)
    else:
        heappush(ans, tmp)
        break
print(sum(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()
q.sort()

p = p[::-1][:x]
q = q[::-1][:y]
a = p + q + r
a.sort(reverse=True)

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

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 = np.sort(p)[::-1][:x]
q = np.sort(q)[::-1][:y]
a = np.hstack((p, q, r))
a = np.sort(a)[::-1][:(x+y)]

print(np.sum(a))

Solution (Python):
import sys
import heapq


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    x, y, a, b, c = list(map(int, readline().split()))
    p = list(map(int, readline().split()))
    q = list(map(int, readline().split()))
    r = [-1 * i for i in list(map(int, readline().split()))]
    p.sort(reverse=True)
    q.sort(reverse=True)
    hq = p[:x] + q[:y]
    heapq.heapify(hq)
    heapq.heapify(r)
    while len(r):
        hqv = heapq.heappop(hq)
        rv = -heapq.heappop(r)
        if rv > hqv:
            heapq.heappush(hq, rv)
        else:
            heapq.heappush(hq, hqv)
            break
    print(sum(hq))


if __name__ == '__main__':
    solve()

Solution (Python):
import numpy as np

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=list(np.sort(p)[::-1][0:x])
q=list(np.sort(q)[::-1][0:y])

select=np.sort(p+q+r)[::-1][0:x+y]
print(sum(select))

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]

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

yamm = sum(pqr[:x+y])
print(yamm)

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]

pq = p+q
pq.sort(reverse=True)

pqr = pq + r
pqr.sort(reverse=True)

yamm = sum(pqr[:x+y])
print(yamm)

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]

pq = p+q
pq.sort(reverse=True)

pqr = pq + r
pqr.sort(reverse=True)

yamm = 0
for i in range(x+y):
    yamm += pqr[i]

print(yamm)

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, reverse=True)[:x]
b = sorted(b, reverse=True)[:y]

al = a + b + c
al.sort(reverse=True)

ans = sum(al[: x + y])

print(ans)

Solution (Python):
from collections import deque

N_red_toEat, N_green_toEat, N_red, N_green, N_white = map(int, input().split())

delicious_red = list(map(int, input().split()))
delicious_green = list(map(int, input().split()))
delicious_white = list(map(int, input().split()))

delicious_red.sort(reverse=True)
delicious_green.sort(reverse=True)
delicious_white.sort(reverse=True)

delicious_red = delicious_red[:N_red_toEat]
delicious_green = delicious_green[:N_green_toEat]

Q_red = deque(delicious_red)
Q_green = deque(delicious_green)
Q_white = deque(delicious_white)

summ = 0

for n in range(N_red_toEat + N_green_toEat):
    if (len(Q_red) > 0):
        r_tmp = Q_red.popleft()
    else:
        r_tmp = 0
    
    if (len(Q_green) > 0):
        g_tmp = Q_green.popleft()
    else:
        g_tmp = 0
    
    if (len(Q_white) > 0):
        w_tmp = Q_white.popleft()
    else:
        w_tmp = 0
    
    MAX_tmp = max(r_tmp, g_tmp, w_tmp)
    
    if (MAX_tmp == r_tmp):
        eat = r_tmp
        Q_green.appendleft(g_tmp)
        Q_white.appendleft(w_tmp)
    
    elif (MAX_tmp == g_tmp):
        eat = g_tmp
        Q_red.appendleft(r_tmp)
        Q_white.appendleft(w_tmp)
    
    else:
        eat = w_tmp
        Q_red.appendleft(r_tmp)
        Q_green.appendleft(g_tmp)
    
    summ += eat
    

print(summ)

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

p.sort(reverse=True)
q.sort(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, = map(int, input().split())
*q, = map(int, input().split())
*r, = map(int, input().split())

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

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

Solution (Python):
x, y, a, b, c = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
xs = sorted(p, reverse = True)[:x] + sorted(q, reverse = True)[:y] + sorted(r, reverse = True)
print(sum(sorted(xs, reverse = True)[: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 = list(map(int, input().split()))
ans = sum(sorted(p + q + r, reverse=True)[:X + Y])
print(ans)

Solution (Python):
import math
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()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)

X,Y,A,B,C=nm()
p = sorted(nl(),reverse=True)
q = sorted(nl(),reverse=True)
r = nl()
u = sorted(p[0:X] + q[0:Y] + r,reverse=True)[0:X+Y]

print(sum(u))

Solution (Python):
x, y, a, b, c = map(int, input().split())
apples = []
apples += sorted(list(map(int, input().split())), reverse=True)[:x]
apples += sorted(list(map(int, input().split())), reverse=True)[:y]
apples += list(map(int, input().split()))
print(sum(sorted(apples, reverse=True)[: x + y]))

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

Solution (Python):
x, y, a, b, c = map(int, input().split())
Lista = sorted(list(map(int, input().split())), reverse = True)
Listb = sorted(list(map(int, input().split())), reverse = True)
Listc = sorted(list(map(int, input().split())), reverse = True)
if x < a:
    del Lista[x : a]
if y < b:
    del Listb[y : b]
List = sorted(Lista + Listb, reverse = True)
i = -1
for n in range(min(x + y, c)):
    if List[-n-1] < Listc[n]:
        i = n
    else:
        break
del List[x + y - i -1 : x + y]
del Listc[i + 1 : c]
print(sum(List) + sum(Listc))

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()))
assert len(p) == a and len(q) == b and len(r) == c

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

pi = x - 1
qi = y - 1
ri = 0
while ri < c:
    if pi >= 0 and p[pi] < r[ri] and (qi < 0 or p[pi] <= q[qi]):
        p[pi] = r[ri]
        pi -= 1
        ri += 1
    elif qi >= 0 and q[qi] < r[ri] and (pi < 0 or q[qi] <= p[pi]):
        q[qi] = r[ri]
        qi -= 1
        ri += 1
    else:
        break

print(sum(p[:x] + q[: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()))
assert len(p) == a and len(q) == b and len(r) == c

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

pi = x - 1
qi = y - 1
ri = 0
while ri < c:
    if pi >= 0 and qi >= 0 and p[pi] <= q[qi] < r[ri]:
        p[pi] = r[ri]
        pi -= 1
        ri += 1
    elif pi >= 0 and qi >= 0 and q[qi] <= p[pi] < r[ri]:
        q[qi] = r[ri]
        qi -= 1
        ri += 1
    elif pi >= 0 and p[pi] < r[ri]:
        p[pi] = r[ri]
        pi -= 1
        ri += 1
    elif qi >= 0 and q[qi] < r[ri]:
        q[qi] = r[ri]
        qi -= 1
        ri += 1
    else:
        break

print(sum(p[:x] + q[: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())))


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

Solution (Python):
x,y,a,b,c = map(int, input().split())
p1 = list(map(int, input().split()))
p2 = list(map(int, input().split()))
p3 = list(map(int, input().split()))
p1.sort(reverse= True)
p2.sort(reverse= True)
ans =p1[:x]+p2[:y]+p3
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()]
q = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]
p.sort(reverse = True)
q.sort(reverse = True)
p = p[:X]
q = q[:Y]
ans = p+q+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()]
q = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]
p.sort(reverse = True)
q.sort(reverse = True)
p = p[:X]
q = q[:Y]
ans = p+q+r
ans.sort(reverse = True)
print(sum(ans[: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)
p = p[:x]
q = q[:y]
all = p + q + r
all.sort(reverse=True)
print(sum(all[: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, reverse=True)
q = sorted(q, reverse=True)
r = sorted(r, reverse=True)
p = [int(1e10)]+p[:x]
q = [int(1e10)]+q[:y]
k = 0
i, j = x, y

while 1:
   if k >= c:
      break
   if min(p[i], q[j]) >= r[k] :
      break
   if p[i] < q[j]:
      p[i] = r[k]
      i -= 1
   else :
      q[j] = r[k]
      j -=1
   k += 1
print(sum(p[1:])+sum(q[1:]))

Solution (Python):
X,Y,A,B,C = map(int, 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)
newp = p[:X]
newq = q[:Y]
lis = newp + newq
lis.sort(reverse = True)
s = sum(lis)
for i in range(len(r)):
    if lis[-i-1] < r[i]:
        s = s - lis[-i-1] + r[i]
    else:
        break
print(s)

Solution (Python):
X, Y, A, B, C = map(int, input().split())
p = sorted(sorted([int(x) for x in input().split()])[-X:] + sorted([int(x) for x in input().split()])[-Y:] + [int(x) for x in input().split()])

print(sum(p[-X-Y:]))

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

x, y, a, b, c = map(int, input().split())
P = sorted(map(int, input().split()))[-x:]
Q = sorted(map(int, input().split()))[-y:]
heapq.heapify(P)
heapq.heapify(Q)
for r in map(int, input().split()):
  p = P[0]
  q = Q[0]
  if r > p or r > q:
    if p <= q:
      heapq.heapreplace(P, r)
    else:
      heapq.heapreplace(Q, r)
ans = sum(P) + sum(Q)
print(ans)

Solution (Python):
x, y, a, b, c = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
s = p[:x] + q[:y]
s.sort()
for i, j in zip(enumerate(s), r):
    if i[1] > j:
        break
    else:
        s[i[0]] = j
print(sum(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()))

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

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

def input_list(N):
  list = []
  for i in input().split():
    list.append(int(i))
  list.sort(reverse=True)
  return list

P = input_list(A)
Q = input_list(B)
R = input_list(C)
Top = P[:X] + Q[:Y] + R
Top.sort(reverse=True)
sum = 0
for i in range(X+Y):
  sum += Top[i]
print(sum)

Solution (Python):
import heapq

X, Y, A, B, C= list(map(int, input().split()))
P = list(map(int, input().split()))
P.sort(reverse=True)
P = P[:X]
heapq.heapify(P)
Q = list(map(int, input().split()))
Q.sort(reverse=True)
Q = Q[:Y]
heapq.heapify(Q)
R = list(map(int, input().split()))
R.sort(reverse=True)
for r in R:
    p_min = P[0]
    q_min = Q[0]
    if p_min <= q_min and p_min < r:
        heapq.heapreplace(P, r)
    elif q_min <= p_min and q_min < r:
        heapq.heapreplace(Q, r)
    else:
        break
print(sum(P) + sum(Q))

Solution (Python):
x,y,a,b,c = map(int,input().split())
print(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)]))

Solution (Python):
from collections import deque
x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
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 = 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 = P[:X]
Q = Q[:Y]
A = P + Q + R
A.sort(reverse=True)
ans = sum(A[:X+Y])
print(ans)

Solution (Python):
def main():
    x, y, a, b, c = map(int, input().split())
    p = list(sorted(list(map(int, input().split())), reverse=True))[:x]
    q = list(sorted(list(map(int, input().split())), reverse=True))[:y]
    r = list(map(int, input().split()))
    print(sum(list(sorted(p+q+r, reverse=True))[:(x+y)]))
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()
p.reverse()
q.sort()
q.reverse()
new = p[0:X] + q[0:Y] + r
new.sort()
new.reverse()
print(sum(new[0:X+Y]))

Solution (Python):
x,y,a,b,c = list(map(int,input().split()))
parr = list(map(int,input().split()));parr.sort(reverse=True);parr = parr[:x]
qarr = list(map(int,input().split()));qarr.sort(reverse=True);qarr = qarr[:y]
rarr = list(map(int,input().split()))
arr = parr+qarr+rarr
arr.sort(reverse=True)
print(sum(arr[: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)
ans=sorted(p[:x]+q[:y],reverse=True)
for i in range(c):
    if ans[-i-1]<r[i]:
        ans[-i-1]=r[i]
    else:
        break
print(sum(ans))

Solution (Python):
x,y,a,b,c=map(int,input().split())
taste=[sorted(list(map(int,input().split())),reverse=True) for i in range(3)]
red=taste[0][:x]
green=taste[1][:y]
noclo=taste[2]
print(sum(sorted(red+green+noclo)[-(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()

res = []
res += p[-X:]
res += q[-Y:]
res += r
res.sort()

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

pnum, qnum, rnum = 0, 0, 0
ans = 0
time = 0
while time < x+y:
    
    
    if pnum >= x:
        p = 0
    else:
        p = P[pnum]
    
    if qnum >= y:
        q = 0
    else:
        q = Q[qnum]
    
    if rnum >=  c:
        r = 0
    else:
        r = R[rnum]
    Option = [p, q, r]

    
    m = 0
    color = 0
    for i in range(3):
        if m < Option[i]:
            m = Option[i]
            color = i
        else:
            pass
    ans += m

    
    if color == 0:
        pnum += 1
    elif color == 1:
        qnum += 1
    elif color == 2:
        rnum += 1
    else:   
        print('error')

    
    time += 1

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

Solution (Python):
from collections import deque

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())), reverse = True)

s = []

for i in range(x):
    p_e = p.pop()
    s.append(p_e)

for i in range(y):
    q_e = q.pop()
    s.append(q_e)

S = sum(s)
s.sort(reverse = True)

lim = c
if x + y < c:
    lim = x + y


k = x+y-1

for i in range(lim):
    if r[i] > s[k]:
        S += r[i]
        S -= s[k]        
        k -= 1
    if r[i] <= s[k]:
        break

print(S)

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

Solution (Python):
import heapq

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

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

ans = 0
apples = []
for v in P[:X]: apples.append(v)
for v in Q[:Y]: apples.append(v)

apples.sort()

trans_apple = R.pop()


for i in range(len(apples)):
    if apples[i] < trans_apple:
        apples[i] = trans_apple
        if len(R) == 0: break
        trans_apple = R.pop()
    else:
        break

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_new=sorted(P,reverse=True)[:X]
Q_new=sorted(Q,reverse=True)[:Y]

S=sorted(P_new+Q_new+R,reverse=True)[:X+Y]

print(sum(S))

Solution (Python):
X, Y, R, G, W = map(int, input().split())
red = list(map(lambda x: (int(x), 0), input().split()))
green = list(map(lambda x: (int(x), 1), input().split()))
white = list(map(lambda x: (int(x), 2), input().split()))

apples = sorted(red + green + white, key=lambda x: x[0])

choice = X + Y
res = 0

while apples and choice:
    val, color = apples.pop()
    if color == 0:
        if X > 0:
            res += val
            X -= 1
            choice -= 1
        continue
    if color == 1:
        if Y > 0:
            res += val
            Y -= 1
            choice -= 1
        continue
    if color == 2:
        res += val
        choice -= 1

print(res)

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

a_list = sorted(a_list)[-1 * X:]
b_list = sorted(b_list)[-1 * Y:]



all_list = sorted(a_list + b_list + c_list)

print(sum(all_list[-1 * (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)

p_counter = 0
q_counter = 0
r_counter = 0
total = 0
p2 = p[ p_counter]
q2 = q[ q_counter]
r2 = r[ r_counter]
l = [ r2, p2, q2]
while p_counter +q_counter+r_counter < X+Y:
    m = max(l)
    total+=m
    index = l.index(m)


    if index == 0:
        r_counter+=1
        if r_counter >= len(r):
            r2 = 0
        else:
            r2 = r[r_counter]
    elif index == 1:
        p_counter +=1
        if p_counter >= X:
            p2 = 0
        else:
            p2 = p[p_counter]
    else:
        q_counter+=1
        if q_counter >= Y:
            q2 = 0
        else:
            q2 = q[q_counter]
    l = [r2, p2, q2]
print(total)

Solution (Python):
import heapq
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()))
    pp = select(p, x)
    qq = select(q, y)
    res = select(pp + qq + r, x + y)
    print(sum(res))



def select(array, length):
    ins = []
    res_l = []
    for part in array:
        heapq.heappush(ins,-part)
    for _ in range(length):
        res = heapq.heappop(ins)
        res_l.append(-res)
    return res_l


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

Solution (Python):
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())

def main():
    X, Y, A, B, C = mis()
    p = sorted(lmis(), reverse=True)[:X]
    q = sorted(lmis(), reverse=True)[:Y]
    r = lmis()
    print(sum(sorted(p+q+r, reverse=True)[:X+Y]))

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()))
d=[]
for i in p:
    d.append((i,0))
for i in q:
    d.append((i,1))
for i in r:
    d.append((i,2))
d.sort(reverse=True)
ss=x+y
cnt=0
ans=0
xx=0
yy=0
z=0
for i ,j in d:
    if j==0:
        if x>0:
            
            ans+=i
            x-=1
            cnt+=1
    elif j==1 :
        if y>0:
            ans+=i
            cnt+=1
            y-=1
    else:
        ans+=i
        cnt+=1
    if ss==cnt:
        break
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()
q.sort()
nums = p[-x:] + q[-y:] + r
nums.sort()
print(sum(nums[-(x+y):]))

Solution (Python):
want_red, want_green, have_red, have_green, have_white = [int(n) for n in input().rstrip().split()]

red_shortage = want_red-have_red
green_shortage = want_green-have_green

red_deliciousness = sorted([int(n) for n in input().rstrip().split()], reverse=True)[:want_red]
green_deliciousness = sorted([int(n) for n in input().rstrip().split()], reverse=True)[:want_green]
white_deliciousness = sorted([int(n) for n in input().rstrip().split()], reverse=True)[:want_red+want_green]

happiness = sum(sorted(red_deliciousness+green_deliciousness+white_deliciousness,reverse=True)[:want_red+want_green])
print(happiness)

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    x, y, a, b, c = list(map(int, input().strip().split()))
    p = sorted(list(map(int, input().strip().split())), reverse=True)
    q = sorted(list(map(int, input().strip().split())), reverse=True)
    r = sorted(list(map(int, input().strip().split())), reverse=True)
    print(sum(sorted((p[:x]+q[:y]+r), reverse=True)[:x+y]))

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()))
sum = 0
P.sort(reverse = True)
Q.sort(reverse = True)
for i in range(x):
    R.append(P[i])
for i in range(y):
    R.append(Q[i])
R.sort(reverse = True)
for i in range(x + y):
    sum += R[i]
print(sum)

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

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

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

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