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

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

P = sum(i for i in p)
Q = sum(j for j in q)
ans = P+Q
apples = p+q
apples.sort()
for i in range(len(r)):
  if apples[i] < r[0]:
    ans = ans-apples[i] + r[0]
    del r[0]
  else:
    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(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

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

print(ans)

Solution (Python):
import heapq
def main():
    X, Y, A, B, C = (int(_) for _ in input().split())
    p = sorted([int(_) for _ in input().split()])[::-1]
    q = sorted([int(_) for _ in input().split()])[::-1]
    r = sorted([int(_) for _ in input().split()])[::-1]
    output = 0
    apple = list()
    heapq.heapify(apple)
    for i in range(X):
        heapq.heappush(apple, p[i])
        output += p[i]
    for i in range(Y):
        heapq.heappush(apple, q[i])
        output += q[i]
    i = 0
    while i < C:
        x = heapq.heappop(apple)
        if x < r[i]:
            heapq.heappush(apple, r[i])
            output = output - x + r[i]
            i += 1
        else: break

    print(output)
    return

if __name__ == '__main__':
    main()

Solution (Python):
from collections import deque
import math
import sys

x,y,a,b,c = list(map(int,sys.stdin.readline().split()))
p = sorted(list(map(int,sys.stdin.readline().split())), reverse=True)
q = sorted(list(map(int,sys.stdin.readline().split())), reverse=True)
r = sorted(list(map(int,sys.stdin.readline().split())), reverse=True)
eat=[]

if x<len(p):
    [eat.append(red) for red in p[:x]]
else:
    [eat.append(red) for red in p]
if y<len(q):
    [eat.append(green) for green in q[:y]]
else:
    [eat.append(green) for green in q]
[eat.append(apple) for apple in r]
eat = sorted(eat, reverse=True)

ans = 0
for taste in eat[:x + y]:
    ans += taste 
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()

all_apples = []
for i in range(max(X,Y,C)):
  if(i<X):
    all_apples.append([P[-(i+1)],'r'])
  if(i<Y):
    all_apples.append([Q[-(i+1)],'g'])
  if(i<C):
    all_apples.append([R[i],'any'])

all_apples.sort()

ans = 0
for i in range(X+Y):
 ans += all_apples[-(i+1)][0]
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,reverse=True)
q = sorted(q,reverse=True)
r = sorted(r,reverse=True)

lis = p[:x]
lis.extend(q[:y])

lis = sorted(lis)


ans = []
lr = len(r)
for i in range(len(lis)):
    if i<lr:
        ans.append(max(lis[i],r[i]))
    else:
        ans.append(lis[i])

print(sum(ans))

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

tmp = sorted(map(int, input().split()), key=lambda x: -x)[:X] \
      + sorted(map(int, input().split()), key=lambda x: -x)[:Y] \
      + sorted(map(int, input().split()), key=lambda x: -x)

print(sum(sorted(tmp, key=lambda x: -x)[:X + Y]))

Solution (Python):
x,y,nr,ng,nm=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)
a=r[:x]+g[:y]+m
a.sort(reverse=True)
print(sum(a[:x+y]))

Solution (Python):
q=list(map(int,input().split()))
X=q[0]
Y=q[1]
A=q[2]
B=q[3]
C=q[4]
r=list(map(int,input().split()))
g=list(map(int,input().split()))
n=list(map(int,input().split()))
r=sorted(r,reverse=True)
g=sorted(g,reverse=True)
n=sorted(n,reverse=True)
A=[]
for i in range(X):
    A.append(r[i])
for i in range(Y):
    A.append(g[i])
A=sorted(A,reverse=True)
s=0
for i in range(min(len(A),len(n))):
    if A[-1]>=n[i]:
        s=i
        break
    A.pop(-1)
    s=i+1
for i in range(s):
    A.append(n[i])
print(sum(A))

Solution (Python):
import sys
import heapq


def input():
    return sys.stdin.readline().strip()


MOD = 10 ** 9 + 7
sys.setrecursionlimit(20000000)


def main():
    X, Y, A, B, C = map(int, input().split())
    red = list(map(int, input().split()))
    green = list(map(int, input().split()))
    nocolor = list(map(int, input().split()))

    red.sort()
    green.sort()
    nocolor.sort()
    answer = sum(red[A - X :]) + sum(green[B - Y :])
    heap = red[A - X :] + green[B - Y :]
    heapq.heapify(heap)
    flag = 0
    while heap and flag < C:
        m = heapq.heappop(heap)
        if nocolor[flag] > m:
            answer -= m
            answer += nocolor[flag]
            heapq.heappush(heap, nocolor[flag])
            flag += 1
        else:
            heapq.heappush(heap, m)
            flag += 1

    print(answer)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
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()))
    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)
    Z=P[:x]+Q[:y]
    heapq.heapify(Z)
    for r in R:
        if Z[0]>=r:
            break
        heapq.heapreplace(Z,r)
    print(sum(Z))

    

if __name__=='__main__':
    main()

Solution (Python):
apple = list(map(int, input().split()))
x = apple[0]
y = apple[1]        
a = apple[2]
b = apple[3]        
c = apple[4]

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)

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

YgrnApl = []
for i in range(y):
    YgrnApl.append(q[i])
    
fnlst = XredApl + YgrnApl + r 
fnlst.sort(reverse=True)
s = 0
for i in range(x+y):
    s += fnlst[i]
    
print(s)

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

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

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

red = [[i, "r"] for i in p]
green = [[i, "g"] for i in q]
white = [[i, "w"] for i in r]

total = sorted(red + green + white)[::-1]

ans = 0
cnt = 0
r_cnt = 0
g_cnt = 0
for t in total:
    if t[1] == "r" and r_cnt == X:
        continue
    if t[1] == "g" and g_cnt == Y:
        continue
    ans += t[0]
    if t[1] == "r":
        r_cnt += 1
    elif t[1] == "g":
        g_cnt += 1
    cnt += 1
    if cnt == X + Y:
        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()))

red = [[i, "r"] for i in p]
green = [[i, "g"] for i in q]
white = [[i, "w"] for i in r]

total = sorted(red + green + white)[::-1]

ans = 0
cnt = 0
r_cnt = 0
g_cnt = 0
for t in total:
    if t[1] == "r" and r_cnt == X:
        continue
    if t[1] == "g" and g_cnt == Y:
        continue
    ans += t[0]
    if t[1] == "r":
        r_cnt += 1
    elif t[1] == "g":
        g_cnt += 1
    cnt += 1
    if cnt == X + Y:
        break

print(ans)

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

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

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

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

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

print(sum(C[: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(reverse=True)

ppick = p[-x:]
qpick = q[-y:]
pi = 0
qi = 0

for i in range(len(r)):
    if pi >= x:
        while True:
            if qi < y and i < c and r[i] > qpick[qi]:
                qpick[qi] = r[i]
                qi += 1
                i += 1
            else:
                break
    elif qi >= y:
        while True:
            if pi < x and i < c and r[i] > ppick[pi]:
                ppick[pi] = r[i]
                pi += 1
                i += 1
            else:
                break
    elif ppick[pi] >= qpick[qi] and qpick[qi] < r[i]:
        qpick[qi] = r[i]
        qi += 1
        continue
    elif ppick[pi] < qpick[qi] and ppick[pi] < r[i]:
        ppick[pi] = r[i]
        pi += 1
        continue
    break

print(sum(ppick) + sum(qpick))

Solution (Python):
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 = list(reversed(sorted(p)))
q = list(reversed(sorted(q)))
r = list(reversed(sorted(r)))
apple = p[:x] + q[:y] + r
apple = list(reversed(sorted(apple)))
print(sum(apple[:x+y]))

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

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

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

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

p.sort(reverse=True)

q.sort(reverse=True)

r.sort(reverse=True)

ans = []

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

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

ans = ans + 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()))
ans=[]
s=x+y
for i in p:
    ans.append((i,0))
for i in q:
    ans.append((i,1))
for i in r:
    ans.append((i,2))
ans.sort(reverse=True)
res=0
cnt=0
for i , j in ans:
    if j==0:
        if x>0:
            x-=1
            cnt+=1
            res+=i
    elif j==1:
        if y>0:
            y-=1
            cnt+=1
            res+=i
    else:
        cnt+=1
        res+=i
    if cnt>=s:
        break

print(res)

Solution (Python):


def main():
    X,Y,A,B,C  = map(int, input().split()) 
    sum = 0
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    list.sort(p,reverse=True)
    list.sort(q,reverse=True)
    list.sort(r,reverse=True)
    strr = len(r)
    pq = []


    rindex = 0

    for index in range(X):
        sum += p[index]
        pq.append(p[index])

    for index in range(Y):
        sum += q[index]
        pq.append(q[index])

    list.sort(pq,reverse=True)
    strpq = len(pq)

    for index in range(strr):
        if strpq > index and r[index] > pq[X+Y-1-index]:
            sum += r[index] - pq[X+Y-1-index]

    print (sum)


if __name__ == '__main__':
    main()

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(key=lambda x: -x)
q.sort(key=lambda x: -x)
p = p[:X]
q = q[:Y]

pqr = p+q+r
pqr.sort(key=lambda x: -x)
print(sum(pqr[: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(key=lambda x: -x)
q.sort(key=lambda x: -x)
r.sort(key=lambda x: -x)

p = p[:X]
q = q[:Y]
p.sort()
q.sort()

psum = sum(p)
qsum = sum(q)
pi, qi, ri = 0, 0, 0
while ri < len(r):
    found = ""
    if pi < X and qi < Y:
        if p[pi] <= q[qi]:
            if p[pi] < r[ri]:
                found = "p"
        else:
            if q[qi] < r[ri]:
                found = "q"
    elif pi < X:
        if p[pi] < r[ri]:
            found = "p"
    elif qi < Y:
        if q[qi] < r[ri]:
            found = "q"

    if found == "p":
        psum -= p[pi]
        psum += r[ri]
        pi += 1
        ri += 1
    elif found == "q":
        qsum -= q[qi]
        qsum += r[ri]
        qi += 1
        ri += 1
    else:
        break

print(psum+qsum)

Solution (Python):
x,y,a,b,c = map(int, input().split(" "))
plist= sorted(list(map(int, input().split(" "))),reverse=True)[0:x]
qlist= sorted(list(map(int, input().split(" "))),reverse=True)[0:y]
rlist= sorted(list(map(int, input().split(" "))),reverse=True)

plist.extend(qlist)
plist.sort()
n = min(x+y,len(rlist))
i = 0

while i < n and rlist[i]>plist[i]:
  i += 1
if i == 0:
  print(sum(plist))
else:
  print(sum(plist[i:x+y])+sum(rlist[0:i]))

Solution (Python):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
from collections import defaultdict

import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left









import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import numpy as np
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
s = p[:X]+q[:Y]+r
n = len(s)
for i in range(n):
    s[i] *= -1
heapify(s)
ans = 0
for i in range(X+Y):
    ans -= heappop(s)
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)
r.sort(reverse = True)

p = p[:x]
q = q[:y]
r = r[:x+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())
L = []
P = list(map(int, input().split()))
P.sort(reverse=True)
L += P[:X]
Q = list(map(int, input().split()))
Q.sort(reverse=True)
L += Q[:Y]
L += list(map(int, input().split()))
L.sort(reverse=True)
print(sum(L[:X + Y]))

Solution (Python):
(x, y, A, B, C) = map(int, raw_input().split())

ps = sorted(map(int, raw_input().split()), reverse=True)[:x]
qs = sorted(map(int, raw_input().split()), reverse=True)[:y]
cs = sorted(map(int, raw_input().split()))

res = sorted(ps + qs, reverse=True)
tot = sum(res)

while cs and res and cs[-1] >= res[-1]:
    tot -= res.pop()
    tot += cs.pop()

print tot

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

red = list(map(int, input().split()))
green = list(map(int, input().split()))
colorless = list(map(int, input().split()))

red.sort(reverse = True)
green.sort(reverse = True)
colorless.sort(reverse = True)

ret = red[:x] + green[:y]
ret.sort()

for i in range(len(colorless)):
    if ret[i] < colorless[i]:
        ret[i] = colorless[i]
    else:
        break

print(sum(ret))

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

Solution (Python):
from sys import stdin


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

    pqr = []

    for pi in p:
        pqr.append([pi, 0])
    for qi in q:
        pqr.append([qi, 1])
    for ri in r:
        pqr.append([ri, 2])

    pqr.sort(reverse=True)

    ans = 0
    c_a = 0
    c_b = 0
    c_c = 0

    for pqri in pqr:
        if pqri[1] == 0 and c_a < x:
            ans += pqri[0]
            c_a += 1
        elif pqri[1] == 1 and c_b < y:
            ans += pqri[0]
            c_b += 1
        elif pqri[1] == 2 and (c_a < x or c_b < y) and c_a + c_b + c_c < x + y:
            ans += pqri[0]
            c_c += 1
        if c_a + c_b + c_c == x + y:
            print(ans)
            exit()


if __name__ == "__main__":
    main()

Solution (Python):
(x, y, A, B, C) = map(int, raw_input().split())

ps = sorted(map(int, raw_input().split()), reverse=True)[:x]
qs = sorted(map(int, raw_input().split()), reverse=True)[:y]
cs = sorted(map(int, raw_input().split()))

tot = sum(ps) + sum(qs)

while cs and ((ps and cs[-1] > ps[-1]) or (qs and cs[-1] > qs[-1])):
    if ps and qs:
        if ps[-1] < qs[-1]:
            tot -= ps.pop()
            tot += cs.pop()
        else:
            tot -= qs.pop()
            tot += cs.pop()
    elif ps:
        tot -= ps.pop()
        tot += cs.pop()
    elif qs:
        tot -= qs.pop()
        tot += cs.pop()
    else:
        break


print tot

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

Solution (Python):
def function(arg):
    xyabc, pa, qb, rc = arg.split('¥n')
    X,Y,A,B,C = map(int, xyabc.split())
    oishisa_A = list(map(int, pa.split()))
    oishisa_B = list(map(int, qb.split()))
    oishisa_C = list(map(int, rc.split()))
    
    oishisa_A.sort(reverse=True)
    oishisa_A = oishisa_A[:X] 
    oishisa_B.sort(reverse=True)
    oishisa_B = oishisa_B[:Y] 
    oishisa_C.sort(reverse=True)
    
    oishisa = oishisa_A + oishisa_B + oishisa_C
    oishisa.sort(reverse=True)

    results = 0
    for i in range(X+Y):
        results += oishisa[i]

    return results

if __name__ == '__main__':
    xyabc = input()
    pa = input()
    qb = input()
    rc = input()
    print(function(xyabc+'¥n'+pa+'¥n'+qb+'¥n'+rc))

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

Q = sorted(Q, reverse=True)[:y]

P.extend(Q)
R.extend(P)

T = sorted(R, reverse=True)[:x+y]
print(sum(T))

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_sum = [0]*(a+1)
q_sum = [0]*(b+1)
for i in range(a):
    p_sum[i+1] = p_sum[i] + p[i]
for i in range(b):
    q_sum[i+1] = q_sum[i] + q[i]


ans = [0]*(c+1)
ans[0] = p_sum[X] + q_sum[Y]
x, y = X, Y
flag = True
for i in range(c):
    if x > 0 and y > 0:
        ans[i+1] = max(ans[i]-p[x-1]+r[i], ans[i]-q[y-1]+r[i], ans[i])
        if ans[i+1] == ans[i]-p[x-1]+r[i]:
            x -= 1
        elif ans[i+1] == ans[i]-q[y-1]+r[i]:
            y -= 1
        elif ans[i+1] == ans[i]:
            break
    elif x == 0:
        ans[i+1] = max(ans[i]-q[y-1]+r[i], ans[i])
        if ans[i+1] == ans[i]:
            break
        else:
            y -= 1
    elif y == 0:
        ans[i+1] = max(ans[i]-p[x-1]+r[i], ans[i])
        if ans[i+1] == ans[i]:
            break
        else:
            x -= 1
    elif x == 0 and y == 0:
        flag = False
if flag:
    print(max(ans))
else:
    print(sum(r[:x+y-1]))

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

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

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

Solution (Python):
import heapq
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)


hq = P[:X]+Q[:Y]
ans = sum(hq)
heapq.heapify(hq)  

i = 0
while hq and i < len(R):
    t = heapq.heappop(hq)  
    if R[i] > t:
        ans = ans - t + R[i]
        i += 1
    else:
        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()
p = p[len(p)-x:]
q.sort()
q = q[len(q)-y:]
r.extend(q)
r.extend(p)
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()))

red_green = [(p, "r") for p in P] + [(q, "g") for q in Q]
red_green.sort()
nc = R
nc.sort()

cnt_r , cnt_g , cnt_n = 0,0,0

ans = 0
while cnt_r + cnt_g + cnt_n < X + Y:

    
    if cnt_r == X:
        while red_green[-1][1] == "r":
            red_green.pop()
    if cnt_g == Y:
        while red_green[-1][1] == "g":
            red_green.pop()

    
    if len(nc) > 0 and nc[-1] > red_green[-1][0]:
        point = nc.pop()
        ans += point
        cnt_n += 1
    else:
        point, color = red_green.pop()
        ans += point
        if color == "r":
            cnt_r += 1
        else:
            cnt_g += 1


print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    x,y,a,b,c = LI()
    p = sorted(LI()) + [inf]
    q = sorted(LI()) + [inf]
    r = [-1] + sorted(LI())
    pi = a - x
    qi = b - y
    ri = c
    while True:
        if p[pi] < q[qi]:
            if p[pi] >= r[ri]:
                break
            pi += 1
            ri -= 1
        else:
            if q[qi] >= r[ri]:
                break
            qi += 1
            ri -= 1

    return sum(p[pi:-1] + q[qi:-1] + r[ri+1:])

print(main())

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

plist.sort()
qlist.sort()
rlist.sort(reverse=True)


pgensen=plist[a-x:]
qgensen=qlist[b-y:]

tmplist=pgensen+qgensen
tmplist.sort()

replacesum=0
for i in range(min(x+y,len(rlist))):
    if tmplist[i] >= rlist[i]:
        break
    else:
        replacesum+=rlist[i]-tmplist[i]

print(sum(tmplist)+replacesum)

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)


i, j, k = x, y, 0

def check(z , l):
    return z > l[-1]

while i**2 + j**2 > 0 and k < len(r):
    if i*j != 0:
        if r[k] > p[i-1] or r[k] > q[j-1]:
            if p[i-1] > q[j-1]:
                j -= 1
            else:
                i -= 1
        else:
            break
    elif i > 0:
        if r[k] > p[i-1]:
            i -= 1
        else:
            break

    elif j > 0:
        if r[k] > q[j-1]:
            j -= 1
        else:
            break


    k += 1

print(sum(p[:i])+sum(q[:j])+sum(r[:k]))

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

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


if __name__ == "__main__":
    main()

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) 

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

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

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

def solve():
    ans = 0
    p_selected = p[:X]
    q_selected = q[:Y]
    p_selected.sort()
    q_selected.sort()
    p_cnt = 0
    q_cnt = 0
    r_selected = r[:min((X + Y), len(r))]
    

    ans += sum(p_selected) + sum(q_selected)
    for r_i in r_selected:
    
        if q_cnt < Y and p_cnt < X:
            if p_selected[p_cnt] >= q_selected[q_cnt]:
                if q_selected[q_cnt] < r_i:
                    ans += r_i - q_selected[q_cnt]
                    q_cnt += 1
                else:
                    return ans
            elif p_selected[p_cnt] < q_selected[q_cnt]:
                if p_selected[p_cnt] < r_i:
                    ans += r_i - p_selected[p_cnt]
                    p_cnt += 1
                else:
                    return ans
        elif q_cnt < Y and p_cnt >= X:
            if q_selected[q_cnt] < r_i:
                ans += r_i - q_selected[q_cnt]
                q_cnt += 1
            else:
                return ans
        elif p_cnt < X and q_cnt >= Y:
            if p_selected[p_cnt] < r_i:
                ans += r_i - p_selected[p_cnt]
                p_cnt += 1
            else:
                return ans

    return ans

ans = solve()

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

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

Solution (Python):
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[-x:]
q=sorted(list(map(int,input().split())))[-y:]
r=sorted(list(map(int,input().split())))
for i in range(len(p)):
  r.append(p[i])
for i in range(len(q)):
  r.append(q[i])
r=sorted(r)[-x-y:]
print(sum(r))

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, reverse = True)
print(sum(s[:x+y]))

'''
pi = x - 1
qi = y - 1
ri = 0

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

print(sum(p[:x]) + sum(q[: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()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
kouho=p[:X]+q[:Y]
kouho.sort()
for i in range(min(C,X+Y)):
    kouho[i]=max(kouho[i],r[i])
print(sum(kouho))

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 j in range(y):
  r.append(q[j])
           
r.sort(reverse = True)  

ans = 0
for i in range(x+y):
  ans += r[i]
print(ans)

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()))
    p.sort(reverse=True)
    q = list(map(int, input().split()))
    q.sort(reverse=True)
    r = list(map(int, input().split()))
    r.sort(reverse=True)
    target = p[:X] + q[:Y] + r
    target.sort(reverse=True)
    ans = sum(target[:X+Y])
    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=sorted(p)
q=sorted(q)
r=sorted(r)
print(sum(sorted(p[-x:]+q[-y:]+r[-x-y:])[-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=p[-x:]
q.sort()
q=q[-y:]
p[len(p):len(p)]=q
p[len(p):len(p)]=r
p.sort()
p=p[-x-y:]
print(sum(p))

Solution (Python):
x,y,a,b,c=map(int,input().split())
p=list(map(lambda x:['red',int(x)],input().split()))
q=list(map(lambda x:['green',int(x)],input().split()))
r=list(map(lambda x:['nan',int(x)],input().split()))
p.sort(key=lambda x:x[1])
p=p[-x:]
q.sort(key=lambda x:x[1])
q=q[-y:]
p[len(p):len(p)]=q
p[len(p):len(p)]=r
p.sort(key=lambda x:x[1])
p=p[-x-y:]
print(sum([pi[1] for pi in p]))