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 = [int(n) for n in input().split()]
Q = [int(n) for n in input().split()]
R = [int(n) for n in input().split()]

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

PQ = deque(sorted(P[-X:] + Q[-Y:]))
R = deque(R)

while True:
    if not R or R[0] <= PQ[0]:
        break
    if R[0] > PQ[0]:
        PQ.append(R.popleft())
        PQ.popleft()

print(sum(PQ))

Solution (Python):
import heapq

X, Y, A, B, C = [int(s) for s in input().split()]
p = [(-int(s), 'r') for s in input().split()]
q = [(-int(s), 'g') for s in input().split()]
r = [(-int(s), 'n') for s in input().split()]
h = p + q + r
heapq.heapify(h)
x, y, z = 0, 0, 0
s = 0
while x + y + z < X + Y:
    d, c = heapq.heappop(h)
    if c == 'r':
        if x < X:
            x += 1
            s += -d
    if c == 'g':
        if y < Y:
            y += 1
            s += -d
    if c == 'n':
        z += 1
        s += -d
print(s)

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)

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





S = []
S = P + Q + R
S.sort(reverse=True)

S2 = S[:X+Y]
ans = sum(S2)
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 = sorted(p)[-X:]
q = sorted(q)[-Y:]
r = sorted(r)
a = p+q+r
a.sort(reverse=1)
ans = a[:X+Y]
print(sum(ans))

Solution (Python):


import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

x, y, a, b, c = na()
p = na()
q = na()
r = na()
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

ans = []
ans.extend(p[:x])
ans.extend(q[:y])
ans.extend(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()
q.sort()
L=p[a-x:a]+q[b-y:b]+r
L.sort()
L.reverse()
print(sum(L[0:x+y]))

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

p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

ps = sorted(p,reverse=True)
qs = sorted(q,reverse=True)
rs = sorted(r,reverse=True)

psc = ps[:x]
qsc = qs[:y]

d = []

d.extend(psc)
d.extend(qsc)
d.extend(rs)

ds = sorted(d,reverse=True)

dsc = ds[:(x+y)]

print(sum(dsc))

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()))
r += sorted(p)[-x:]
r += sorted(q)[-y:]
ans = sum(sorted(r)[-(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 = sorted(p)[::-1]
q = sorted(q)[::-1]
r += p[:x]
r += q[:y]
ans = sum(sorted(r)[::-1][:x+y])
print(ans)

Solution (Python):
from collections import deque
def main():
    X, Y, A, B, C = map(int, input().split())
    
    apple = []
    red = sorted(map(int, input().split()), reverse=True)[:X]
    green = sorted(map(int, input().split()), reverse=True)[:Y]
    nocolor = list(map(int, input().split()))
    apple.extend(red)
    apple.extend(green)
    apple.extend(nocolor)
    
    print(sum(sorted(apple, reverse=True)[:X+Y]))      
        

if __name__ == "__main__":
    main()

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)
pq=p[:x]+q[:y]
heapq.heapify(pq)

for i in range(c):
    a=heapq.heappop(pq)
    if a<r[i]:
        heapq.heappush(pq,r[i])
    else:
        heapq.heappush(pq,a)
        break

print(sum(pq))

Solution (Python):
x,y,a,b,c = map (int ,input().split())
al = [int(x) for x in(input().split())]
bl = [int(x) for x in(input().split())]
cl = [int(x) for x in(input().split())]


al.sort()
bl.sort()

d = al[-x:]+bl[-y:]+cl
d.sort(reverse = True)
ans = 0
for i in range(x + y):
  ans += d[i]
print(ans)

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

p = list(map(lambda x: (int(x), 0), input().split()))
p += list(map(lambda x: (int(x), 1), input().split()))
p += list(map(lambda x: (int(x), 2), input().split()))
p = sorted(p, reverse=True)

from collections import deque
p = deque(p)
_n = x+y
ans = 0

D = [x, y ,x+y]
while _n > 0:
    _x, _y = p.popleft()
    if D[_y] == 0:
        pass
    else:
        D[_y] -= 1
        ans += _x
        _n -= 1

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_ = sorted(p)[-x:]
q_ = sorted(q)[-y:]
s = p_ + q_ + r
s_ = sorted(s)[-(x + y):]

print(sum(s_))

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

d = sorted(p[:x]+q[:y]+r,reverse=True)
print(sum(d[:(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)
ip = 0
iq = 0
ir = 0
ans = 0
while ip+iq+ir<x+y:
    tp = 0 if ip>=x else p[ip]
    tq = 0 if iq>=y else q[iq]
    tr = 0 if ir==c else r[ir]
    if tp >= tq and tp >= tr and ip < x:
        ans += tp
        ip += 1
    elif tq >= tp and tq >= tr and iq < y:
        ans += tq
        iq += 1
    elif ir < c:
        ans += tr
        ir += 1
    elif tp > tq and ip < x:
        ans += tp
        ip += 1
    else:
        ans += tq
        iq += 1
print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	x,y,a,b,c = MI()
	p = LI()
	p.sort(reverse=True)
	q = LI()
	q.sort(reverse=True)
	r = LI()

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

if __name__ == '__main__':
	main()

Solution (Python):
x, y, a, b, c = map(int, input().split())
r = sorted(list(map(int, input().split())), reverse=True)[:x]
g = sorted(list(map(int, input().split())), reverse=True)[:y]
n = sorted(list(map(int, input().split())), reverse=True)
list = sorted(r+g+n, reverse=True)
ans = 0
for _ in range(x+y):
  ans += list[_]
  
print(ans)

Solution (Python):
import itertools
from itertools import zip_longest

x, y, a, b, c = map(int, input().split())
ans_list = list()
p = list()
for i in input().split():
  p.append(int(i))
q = list()
for i in input().split():
  q.append(int(i))
r = list()
for i in input().split():
  r.append(int(i))

sort_p = sorted(p, reverse=True)
sort_q = sorted(q, reverse=True)
sort_r = sorted(r, reverse=True)
sort_r_max = sort_r[:x+y]

ans_list.append(sort_p[:x])
ans_list.append(sort_q[:y])

sort_ans = sorted(list(itertools.chain.from_iterable(ans_list)))
ans = 0
for i, j in zip_longest(sort_ans, sort_r_max, fillvalue=0):
  if i < j:
    ans += j
  else:
    ans += i
print(ans)

Solution (Python):
I = lambda: sorted([int(a) for a in input().split()])[::-1]
X, Y, *_ = map(int, input().split())
print(sum(sorted(I()[:X] + I()[:Y] + I())[::-1][:X+Y]))

Solution (Python):


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

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


if __name__ == '__main__':
    main()

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

p_list = list(reversed(sorted(p_list)))
p_list = p_list[:X]


q_list = list(reversed(sorted(q_list)))
q_list = q_list[:Y]


r_list = list(reversed(sorted(r_list)))



p_i = -1
q_i = -1
r_i = 0

while True:
    if r_i == C:
        break

    if p_i + X >= 0 and q_i + Y >= 0:
        if p_list[p_i] <= q_list[q_i]:
            if p_list[p_i] < r_list[r_i]:
                p_list[p_i] = r_list[r_i]
                p_i -= 1
                r_i += 1
            else:
                break
        elif q_list[q_i] <= p_list[p_i]:
            if q_list[q_i] < r_list[r_i]:
                q_list[q_i] = r_list[r_i]
                q_i -= 1
                r_i += 1
            else:
                break
    elif p_i + X >= 0:
        if p_list[p_i] < r_list[r_i]:
            p_list[p_i] = r_list[r_i]
            p_i -= 1
            r_i += 1
        else:
            break
    elif q_i + Y >= 0:
        if q_list[q_i] < r_list[r_i]:
            q_list[q_i] = r_list[r_i]
            q_i -= 1
            r_i += 1
        else:
            break
    else:
        break

d = 0
d += sum(p_list)
d += sum(q_list)

print(d)

Solution (Python):
def main():
    x,y,a,b,c=map(int,input().split())
    P=list(map(int,input().split()))
    P.sort(reverse=True)
    Q=list(map(int,input().split()))
    Q.sort(reverse=True)
    R=list(map(int,input().split()))
    A=P[:x]+Q[:y]+R
    A.sort(reverse=True)
    print(sum(A[:x+y]))
    
if __name__=='__main__':
    main()

Solution (Python):
X,Y,A,B,C=map(int,input().split())
R=sorted(list(map(int,input().split())),reverse=True)
G=sorted(list(map(int,input().split())),reverse=True)
RG=sorted(list(map(int,input().split())),reverse=True)


d=R[:X]+G[:Y]+RG
d.sort(reverse=True)
 
print(sum(d[:X+Y]))

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





x,y,a,b,c=mii()

p=deque(list(reversed(sorted(limii(),reverse=True)[:x])))
q=deque(list(reversed(sorted(limii(),reverse=True)[:y])))
r=deque(sorted(limii(),reverse=True))
pp=p.popleft()
qq=q.popleft()
rr=r.popleft()
for i in range(c):
    if pp>qq:
        if qq<rr:
            q.append(rr)
            if i!=c-1:
                rr=r.popleft()
            qq=q.popleft()
    else:
        if pp<rr:
            p.append(rr)
            if i!=c-1:
                rr=r.popleft()
            pp=p.popleft()
p.append(pp)
q.append(qq)
print(sum(list(p))+sum(list(q)))

Solution (Python):
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

if __name__ == '__main__':
    x, y, a, b, c = map(int, input().split())
    p = [int(i) for i in input().split()]
    q = [int(i) for i in input().split()]
    r = [int(i) for i in input().split()]
    p.sort(reverse=True)
    q.sort(reverse=True)
    r.sort(reverse=True)
    ansList = []
    ansList.extend(p[:x])
    ansList.extend(q[:y])
    ansList.extend(r)
    ansList.sort(reverse=True)
    ansList = ansList[:x+y]
    sum = 0
    for i in ansList:
        sum +=i
    print(sum)

Solution (Python):




import sys
input = sys.stdin.readline



def main():
    X,Y,A,B,C = map(int,input().split())
    p = list(map(int,input().split()))
    q = list(map(int,input().split()))
    r = list(map(int,input().split()))

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

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

    all = p + q + r

    all.sort(reverse=True)
    all = all[:X+Y]

    res = sum(all)

    print(res)



main()

Solution (Python):
import sys
x, y, a, b, c = map(int, sys.stdin.readline().split())
p = map(int, sys.stdin.readline().split())
q = map(int, sys.stdin.readline().split())
r = map(int, sys.stdin.readline().split())

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

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

s = []
p.sort(reverse=True)
p = p[:x]

q.sort(reverse=True)
q = q[:y]

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

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())))
print(sum(sorted(P[-X:]+Q[-Y:]+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()
p.reverse()
q.sort()
q.reverse()
r.sort()
r.reverse()

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

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

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

Solution (Python):
x, y, r, g, c = map(int, input().split())
r_d = list(map(int, input().split()))
g_d = list(map(int, input().split()))
c_d = list(map(int, input().split()))
r_d.sort(reverse=True)
g_d.sort(reverse=True)
c_d.sort(reverse=True)
a = r_d[:x]+g_d[:y]+c_d
a.sort(reverse=True)
print(sum(a[: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 = p[:x]
q = q[:y]
apple = sorted(p + q + r, reverse=True)
print(sum(apple[:x+y]))

Solution (Python):
import sys



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

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

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



    print(sum(all))


if __name__ == '__main__':
    main()

Solution (Python):
X,Y,A,B,C = [int(x) for x in input().split()]
R = sorted([int(x) for x in input().split()],reverse = True)[:X]
G = sorted([int(x) for x in input().split()],reverse = True)[:Y]
CL = sorted([int(x) for x in input().split()],reverse = True)[:X+Y]
total = sorted(R+G+CL, reverse=True)[:X+Y]
print(sum(total))

Solution (Python):
X,Y,A,B,C = map(int, input().split())
ps = sorted(map(int,input().split()),reverse=True)[:X]
qs = sorted(map(int,input().split()),reverse=True)[:Y]
rs = list(map(int,input().split()))
print(sum(sorted(ps+qs+rs, reverse=True)[:X+Y]))

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

def resolve():
    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 = sorted(p, reverse=True)[0:X]
    qq = sorted(q, reverse=True)[0:Y]
    ppqqr = list(sorted(pp+qq+r, reverse=True))

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

if __name__ == '__main__':
    resolve()

Solution (Python):
from collections import deque
x,y,a,b,c=map(int, input().split())
pi=list(map(int,input().split()))
qi=list(map(int,input().split()))
ri=list(map(int,input().split()))
pi.sort(reverse=True)
qi.sort(reverse=True)

apple=pi[:x]+qi[:y]+ri
apple.sort(reverse=True)

print(sum(apple[: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)
box=[]
ans=0
for i in range(x):
    heapq.heappush(box,p[i]*(-1))
for i in range(y):
    heapq.heappush(box,q[i]*(-1))
for i in range(c):
    heapq.heappush(box,r[i]*(-1))
for _ in range(x+y):
    ans+=heapq.heappop(box)
print(-1*ans)

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

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

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

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

r.extend(p[:x])
r.extend(q[:y])

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

Solution (Python):
def e_red_and_green_apples():
    from bisect import bisect_right
    X, Y, A, B, C = [int(i) for i in 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)

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

print(e_red_and_green_apples())

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

red.sort(reverse = True)
red = red[:x]
green.sort(reverse = True)
green = green[:y]

apples = red + green + clear
apples.sort(reverse = True)
apples = apples[:x+y]

print(sum(apples))

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()))
    s = []
    for v in p:
        s.append([v, "p"])
    for v in q:
        s.append([v, "q"])
    for v in r:
        s.append([v, "r"])
    s.sort(reverse=True)
    ans = 0
    cnt = [0]*3
    for v, c in s:
        if c == "p":
            if cnt[0] < x:
                ans += v
                cnt[0] += 1
        elif c == "q":
            if cnt[1] < y:
                ans += v
                cnt[1] += 1
        else:
            ans += v
            cnt[2] += 1
        if sum(cnt) == x+y:
            break
    print(ans)

if __name__ == "__main__":
    main()

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

l = X+Y
lst = []
for i in range(X):
  lst.append(p[i])

for i in range(Y):
  lst.append(q[i])

for i in r:
  lst.append(i)

lst.sort()
lst.reverse()

ans = 0
for i in range(l):
  ans += lst[i]

print(ans)

Solution (Python):
X, Y, A, B, C, *PQR = map(int, open(0).read().split())

P = sorted(PQR[:A], reverse=True)
Q = sorted(PQR[A:A + B], reverse=True)
R = sorted(PQR[A + B:], reverse=True)

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

Solution (Python):



def main():
    x, y, a, b, c = map(int, input().split())
    red_delis = list(map(int, input().split()))
    green_delis = list(map(int, input().split()))
    musyoku_delis = list(map(int, input().split()))

    red_delis.sort(reverse=True)
    green_delis.sort(reverse=True)
    musyoku_delis.sort(reverse=True)

    new_red_delis = red_delis[:x]
    new_green_delis = green_delis[:y]

    return sum(sorted(new_red_delis + new_green_delis + musyoku_delis, reverse=True)[:x + y])


if __name__ == "__main__":
    print(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()
q.sort()
r.sort()
r.reverse()
pp = p[a-x:]
qq = q[b-y:]
ll = pp+qq
ll.sort()
ans = sum(ll)
subll = ll[:c]
rr = r+subll
rr.sort()
subrr = rr[c:]
ans += sum(subrr)-sum(subll)
print(ans)

Solution (Python):
f,g=lambda:map(int,input().split()),sorted;x,y,*_=f();print(sum(g(g(f())[-x:]+g(f())[-y:]+g(f()))[-x-y:]))

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

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

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)

a = a[:x]
b = b[:y]

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

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

Solution (Python):
import heapq
X, Y, A, B, C = map(int, input().split())
red = sorted(list(map(int, input().split())), reverse=True)
green = sorted(list(map(int, input().split())), reverse=True)
mu = list(map(int, input().split()))
eat_red = [0]*X
eat_green = [0]*Y
for i in range(X):
    eat_red[i] = red[i]
for i in range(Y):
    eat_green[i] = green[i]
heapq.heapify(eat_red)
heapq.heapify(eat_green)
for i in range(C):
    tmp = mu[i]
    r = heapq.heappop(eat_red)
    g = heapq.heappop(eat_green)
    if r <= g:
        heapq.heappush(eat_green,g)
        heapq.heappush(eat_red,max(tmp,r))
    else:
        heapq.heappush(eat_red,r)
        heapq.heappush(eat_green,max(tmp,g))
print(sum(eat_red)+sum(eat_green))

Solution (Python):
def merge(l):
    t = [-1]*len(l)
    if(len(l) == 2):
        if(l[0]<l[1]):
            t[1] = l[0]
            t[0] = l[1]
        else:
            t=l
    elif(len(l) > 2):
        x = merge(l[:len(l)//2])
        y = merge(l[len(l)//2:])
        p,q = 0,0
        for i in range(len(l)):
            if(p<len(x) and q<len(y)):
                if(x[p] > y[q]):
                    t[i] = x[p]
                    p += 1
                else:
                    t[i] = y[q]
                    q += 1
            elif(p == len(x)):
                t[i] = y[q]
                q += 1
            else:
                t[i] = x[p]
                p += 1
    else:
        t = l
    return t
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()))
a = [x,y,0]
P = merge(p)
Q = merge(q)
R = merge(r)
X = P[:x]
Y = Q[:y]
for i in range(x+y):
    if(a[2] == c):
        break
    elif(a[0] == 0):
        if(Y[a[1]-1] < R[a[2]]):
                a[1] -= 1
                a[2] += 1
        else:
            break
    elif(a[1] == 0):
        if(X[a[0]-1] < R[a[2]]):
                a[0] -= 1
                a[2] += 1
        else:
            break
    else:
        if(X[a[0]-1] > Y[a[1]-1]):
            if(Y[a[1]-1] < R[a[2]]):
                a[1] -= 1
                a[2] += 1
            else:
                break
        else:
            if(X[a[0]-1] < R[a[2]]):
                a[0] -= 1
                a[2] += 1
            else:
                break
m = 0
for i in range(a[0]):
    m += P[i]
for i in range(a[1]):
    m += Q[i]
for i in range(a[2]):
    m += R[i]
print(m)

Solution (Python):
X, Y, A, B, C = map(int, input().split())
AA = list(map(int, input().split()))
BB = list(map(int, input().split()))
CC = list(map(int, input().split()))
a = sorted(AA, reverse=True)
b = sorted(BB, reverse=True)
c = sorted(CC, reverse=True)

if X < A:
  del a[X:]

if Y < B:
  del b[Y:]

NEW = a + b + c
NEWnew = sorted(NEW, reverse=True)
del NEWnew[X+Y:]
K = sum(NEWnew)
print(K)

Solution (Python):
val = input().split(' ')
x = int(val[0])
y = int(val[1])
a = int(val[2])
b = int(val[3])
c = int(val[4])
 
p_list = sorted([int(a) for a in input().split(' ')])
q_list = sorted([int(a) for a in input().split(' ')])
r_list = sorted([int(a) for a in input().split(' ')])
p_list.reverse()
q_list.reverse()
r_list.reverse()
 
xapples = p_list[0:x]
yapples = q_list[0:y]
zapples = r_list[0:x+y]
 
xapples.extend(yapples)
xapples.extend(zapples)
tmp_apples = sorted(xapples)
tmp_apples.reverse()
apples = tmp_apples[0:x+y]
print(sum(apples))

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)

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

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

p_i = 0
q_i = 0

for ri in R:
    if p_i >= len(P) and q_i >= len(Q):
        break
    if p_i >= len(P):
        if ri >= Q[q_i]:
            Q[q_i] = ri
            q_i += 1
    elif q_i >= len(Q):
        if ri >= P[p_i]:
            P[p_i] = ri
            p_i += 1
    elif ri < P[p_i] and ri < Q[q_i]:
        break
    elif ri > P[p_i] and ri > Q[q_i]:
        d1 = ri - P[p_i]
        d2 = ri - Q[q_i]
        if d1 > d2:
            P[p_i] = ri
            p_i += 1
        else:
            Q[q_i] = ri
            q_i += 1
    elif ri > P[p_i] and ri < Q[q_i]:
        P[p_i] = ri
        p_i += 1
    else:
        Q[q_i] = ri
        q_i += 1



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

Solution (Python):
def main():
    X,Y,A,B,C = map(int,input().split())
    R = [int(i) for i in input().split()]
    G =  [int(i) for i in input().split()]
    N =  [int(i) for i in input().split()]
    R.sort(reverse=True)
    G.sort(reverse=True)
    N.sort(reverse=True)
    E = R[:X] + G[:Y] + N
    E.sort(reverse=True)
    print(sum(E[:(X+Y)]))

if __name__ == '__main__':
    main()

Solution (Python):
f=lambda:map(int,input().split());x,y,*_=f();g=sorted;print(sum(g(g(f())[-x:]+g(f())[-y:]+list(f()))[-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_use = p[:X]
q_use = q[:Y]
r_use = r[:]
p_use.extend(q_use)
p_use.extend(r_use)
total = p_use[:]
total.sort(reverse=True)
total_use = total[:X+Y]
sum = 0
for i in range(len(total_use)):
    sum += total_use[i]
print(sum)

Solution (Python):
from collections import deque

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 = deque(p[0:x])
q = deque(q[0:y])
r = deque(r)


while len(r) != 0 and min(p[-1],q[-1]) < r[0]:
  if p[-1] < q[-1]:
    p.appendleft(r.popleft())
    p.pop()
  else:
    q.appendleft(r.popleft())
    q.pop()
    
print(sum(p)+sum(q))

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

X, Y, A, B, C = i_l()
p = i_l()
q = i_l()
r = i_l()

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

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

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

Solution (Python):
from collections import deque

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 = deque(p[0:x])
q = deque(q[0:y])
r = deque(r)


while len(r) != 0 and min(p[-1],q[-1]) < r[0]:
  if p[-1] < q[-1]:
    p.appendleft(r.popleft())
    p.pop()
  else:
    q.appendleft(r.popleft())
    q.pop()
    
print(sum(p)+sum(q))

Solution (Python):
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    X,Y,A,B,C = map(int, readline().split())
    p = [int(i) for i in readline().split()]
    q = [int(i) for i in readline().split()]
    r = [int(i) for i in readline().split()]

    p.sort()
    q.sort()
    r.sort()
    
    Q = p[A-X:] + q[B-Y:] + r
    Q.sort(reverse=True)
    ans = sum(Q[:X+Y])

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
x,y,a,b,c=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort(reverse=True)
A.sort()
B.sort()
A=A[a-x:]
B=B[b-y:]
D=A+B+C
D.sort(reverse=True)
sum=0
for i in range(x+y):
    sum+=D[i]
print(sum)