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

umami = [[0]*2 for i in range(a+b+c)];
um = [0]*(x+y+c);

for i in range(a) :
    umami[i][0] = 0;
    umami[i][1] = p[i];

for i in range(b) :
    umami[a+i][0] = 1;
    umami[a+i][1] = q[i];
for i in range(c) :
    umami[a+b+i][0] = 2;
    umami[a+b+i][1] = r[i];

p.sort();
p.reverse();
q.sort();
q.reverse();
r.sort();
r.reverse();
for i in range(x) :
    um[i] = p[i];
for i in range(y) :
    um[i+x] = q[i];
for i in range(c) :
    um[i+x+y] = r[i];

um.sort();
um.reverse();

umami.sort(key=lambda x:x[1]);
umami.reverse();
i = 0;
j = 0;
numr = x;
numg = y;
ans = 0;

while i < x+y :
    if umami[j][0] == 0 and numr == 0 :
        j += 1;
    if umami[j][0] == 1 and numg == 0 :
        j += 1;
    else :
        if umami[j][0] == 0 :
            numr -= 1;
        if umami[j][0] == 1 :
            numg -= 1;
        ans += umami[j][1];
        i += 1;
        j += 1;

ans = 0;
for i in range(x+y) :
    ans += um[i];

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)
q = sorted(q)
r = sorted(r)
p = p[-x:]
q = q[-y:]
q.extend(r)
p.extend(q)
al = sorted(p)

ans = 0
for i in range(x+y):
    ans += al[-(i+1)]

print(ans)

Solution (Python):
import sys


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


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

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


main()

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()
q.sort()
p0 = p[-x:]
q0 = q[-y:]

all1 = p0 + q0 + r
all1.sort()

print(sum(all1[-(x+y):]))

Solution (Python):
import heapq

x,y,a,b,c=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
arr3=list(map(int,input().split()))
q=[]
for val in arr1:
  heapq.heappush(q,(-val,1))
for val in arr2:
  heapq.heappush(q,(-val,2))
for val in arr3:
  heapq.heappush(q,(-val,3))
ans=0
cnt1=0
cnt2=0
cnt3=0
while cnt1+cnt2+cnt3<x+y:
  tmp,flag=heapq.heappop(q)
  tmp*=-1
  if flag==1:
    if cnt1<x:
      ans+=tmp
      cnt1+=1
  elif flag==2:
    if cnt2<y:
      ans+=tmp
      cnt2+=1
  elif flag==3:
    ans+=tmp
    cnt3+=1
print(ans)

Solution (Python):
from sys import stdin


X, Y, A, B, C = map(int, stdin.readline().rstrip().split())

ps = list(map(int, stdin.readline().rstrip().split()))
qs = list(map(int, stdin.readline().rstrip().split()))
rs = list(map(int, stdin.readline().rstrip().split()))

ps.sort()
qs.sort()

del ps[0:A-X]
del qs[0:B-Y]

l = ps + qs + rs

l.sort()
del l[0:len(l)-X-Y]

print(sum(l))

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

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

D = P + Q + R
D = sorted(D, reverse = True)

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

Solution (Python):
X, Y, A, B, C = list(map(lambda x: int(x) ,input().split(" ")))
li = []
p = list(map(lambda x: int(x) ,input().split(" ")))
q = list(map(lambda x: int(x) ,input().split(" ")))
r = list(map(lambda x: int(x) ,input().split(" ")))

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

Solution (Python):


import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def PL(L) : print(*L, sep="\n")

X, Y, A, B, C = LI()
P = LI()
Q = LI()
R = LI()

P.sort(reverse=True)
Q.sort(reverse=True)
P = P[0 : X]
Q = Q[0 : Y]

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

print(sum(aps[0 : 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)
red = P[:X]
green = Q[:Y]
ALL = red + green
R = list(map(lambda x: x*(-1), R))
ALL = list(map(lambda x: x*(-1), ALL))

heapq.heapify(R)
heapq.heapify(ALL)

ans = 0
loop = len(ALL)

for _ in range(loop):
    if len(R) == 0:
        ans += heapq.heappop(ALL)*(-1)
    elif len(ALL) == 0:
        ans += heapq.heappop(R)*(-1)
    elif R[0]*(-1) < ALL[0]*(-1):
        ans += heapq.heappop(ALL)*(-1)
    else:
        ans += heapq.heappop(R)*(-1)

print(ans)

Solution (Python):

x,y,a,b,c=map(int,raw_input().split())
p=map(int,raw_input().split())
q=map(int,raw_input().split())
r=map(int,raw_input().split())
p.sort(reverse=True)
q.sort(reverse=True)
z=p[:x]+q[:y]+r
z.sort(reverse=True)
print sum(z[:x+y])

Solution (Python):
import heapq

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

for _ in range(X):
    a = heapq.heappop(P)
    heapq.heappush(R,a)

for _ in range(Y):
    a = heapq.heappop(Q)
    heapq.heappush(R,a)

s = 0
for _ in range(X+Y):
    s += heapq.heappop(R)

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


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



L = P + Q + R
L = sorted(L)[::-1]

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

Solution (Python):


from decimal import *
from itertools import permutations, combinations,combinations_with_replacement,product

s = input().split()
t = [int(p) for p in s]


sA = input().split()
p = [int(w) for w in sA]
p.sort(reverse=True) 


sB = input().split()
q = [int(p) for p in sB]
q.sort(reverse=True)

sC = input().split()
r = [int(p) for p in sC]
r.sort(reverse=True)

X = t[0]
Y = t[1]
A = t[2]
B = t[3]
C = t[4]
p = p[:X] 
q = q[:Y] 
r = r[:X+Y] 





def delete_min(p, q, r):
    if(len(p) == 0 and len(q) == 0):
        del r[-1]
    elif(len(p) == 0):
        if(q[-1] <= r[-1]):
            del q[-1]
        else:
            del r[-1]
    elif(len(q) == 0):
        if(p[-1] <= r[-1]):
            del p[-1]
        else:
            del r[-1]
    elif(len(r) == 0):
        if(p[-1] <= q[-1]):
            del p[-1]
        else:
            del q[-1]
    else:
        if(p[-1] <= q[-1] and p[-1] <= r[-1]):
            del p[-1]
        elif(q[-1] <= r[-1]):
            del q[-1]
        else:
            del r[-1]
    

while len(p) + len(q) + len(r) > X + Y:
    delete_min(p, q, r)
    

answer = sum(p) + sum(q) + sum(r)
print(answer)

Solution (Python):


import sys
stdin = sys.stdin
import bisect

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    x, y, a, b, c = na()
    p = na()
    q = na()
    r = na()
    p.sort(reverse=True)
    q.sort(reverse=True)
    l = p[:x]
    l += q[:y]
    l += r
    l.sort(reverse=True)
    ans = sum(l[:(x+y)])
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
x, y, a, b, c = [int(i) for i in input().split()]
pa = [int(i) for i in input().split()]
pb = [int(i) for i in input().split()]
pc = [int(i) for i in input().split()]

pa = sorted(pa, reverse=True)
pa = pa[:x]
pb = sorted(pb, reverse=True)
pb = pb[:y]
pc = sorted(pc, reverse=True)

l = pa + pb + pc
l = sorted(l, reverse=True)
l = l[:int(x+y)]
print(sum(l))

Solution (Python):
X,Y,A,B,C = map(int,input().split())
P = [int(x) for x in input().split()]
Q = [int(y) for y in input().split()]
R = [int(z) for z in input().split()]
P.sort(reverse = True)
Q.sort(reverse = True)
P = P[:X]
Q = Q[:Y]
apple = P + Q + R
apple.sort(reverse=True)
print(sum(apple[: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()))

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

P = p[0:X]
Q = q[0:Y]
R = r[0:X+Y]

S = P + Q + R

S.sort(reverse = True)

ans = sum(S[0:X+Y])

print(ans)

Solution (Python):
X, Y, p, q, r = list(map(int, input().split()))
P = list(sorted(list(map(int, input().split())), reverse = True))
Q = list(sorted(list(map(int, input().split())), reverse = True))
R = list(sorted(list(map(int, input().split())), reverse = True))
all_values = P[:X] + Q[:Y] + R[:X+Y]
all_values = list(sorted(all_values, reverse = True))
print(sum(all_values[:X+Y]))

Solution (Python):
X, Y, A, B, C = map(int, input().split())
red_apple = list(map(int, input().split()))
green_apple = list(map(int, input().split()))
transparent_apple = list(map(int, input().split()))
red_apple.sort(reverse=True)
green_apple.sort(reverse=True)
red_apple = red_apple[:X]
green_apple = green_apple[:Y]
transparent_apple.extend(red_apple)
transparent_apple.extend(green_apple)
transparent_apple.sort(reverse=True)
print(sum(transparent_apple[:X+Y]))

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

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

if x < a:
    del p[: a - x]
if y < b:
    del q[: b - y]

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

cnt = 0
for i in range(x + y):
    cnt += delicious[i]
    
print(cnt)

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

r += p[-x:]
r += q[-y:]
print(sum(sorted(r)[-(x+y):]))

Solution (Python):
s=sorted
(x,y,*_),p,q,r=eval('map(int,input().split()),'*4)
print(sum(s(s(p)[-x:]+s(q)[-y:]+s(r))[-x-y:]))

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

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

com = sorted(r + g + n,reverse = True)
print(sum(com[0:x + y]))

Solution (Python):
sel='E'

if sel=='A':
    S=input()
    if S[2]==S[3] and S[4]==S[5]:
        print('Yes')
    else:
        print('No')

if sel=='B':
    X=int(input())
    ans=0
    ans+=(X//500)*1000
    ans+=((X%500)//5)*5
    print(ans)

if sel=='C':
    K,N=map(int,input().split())
    A=[int(i) for i in input().split()]
    d=[A[0]+K-A[-1]]
    for i in range(N-1):
        d.append(A[i+1]-A[i])
    d.sort()
    print(K-d[-1])

if sel=='D':
    N,X,Y=map(int,input().split())
    cnt={}
    for k in range(1,N):
        cnt[k]=0
    for i in range(1,N):
        for j in range(i+1,N+1):
            k=j-i 
            k=min(k,abs(i-X)+1+abs(j-Y)) 
            k=min(k,abs(i-Y)+1+abs(X-j)) 
            cnt[k]+=1

    for k in range(1,N):
        print(cnt[k])

if sel=='E':
    import heapq
    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)
    red=P[:X]
    gre=Q[:Y]
    heapq.heapify(red)
    heapq.heapify(gre)
    for r in R:
        if red[0]<=gre[0]:
            if red[0]<r:
                heapq.heapreplace(red,r)
        else:
            if gre[0]<r:
                heapq.heapreplace(gre,r)
    print(sum(red)+sum(gre))

Solution (Python):
sel='E'

if sel=='A':
    S=input()
    if S[2]==S[3] and S[4]==S[5]:
        print('Yes')
    else:
        print('No')

if sel=='B':
    X=int(input())
    ans=0
    ans+=(X//500)*1000
    ans+=((X%500)//5)*5
    print(ans)

if sel=='C':
    K,N=map(int,input().split())
    A=[int(i) for i in input().split()]
    d=[A[0]+K-A[-1]]
    for i in range(N-1):
        d.append(A[i+1]-A[i])
    d.sort()
    print(K-d[-1])

if sel=='D':
    N,X,Y=map(int,input().split())
    cnt={}
    for k in range(1,N):
        cnt[k]=0
    for i in range(1,N):
        for j in range(i+1,N+1):
            k=j-i 
            k=min(k,abs(i-X)+1+abs(j-Y)) 
            k=min(k,abs(i-Y)+1+abs(X-j)) 
            cnt[k]+=1

    for k in range(1,N):
        print(cnt[k])

if sel=='E':
    import heapq
    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)
    red=P[:X]
    gre=Q[:Y]
    heapq.heapify(red)
    heapq.heapify(gre)
    for r in R:
        if red[0]<=gre[0]:
            if red[0]<r:
                heapq.heapreplace(red,r)
        else:
            if gre[0]<r:
                heapq.heapreplace(gre,r)
    print(sum(red)+sum(gre))

Solution (Python):
na, nb, a, b, c = map(int, input().split())
ab_list = [0 for i in range(na + nb)]
ab_list[:na] = sorted(list(map(int, input().split())), reverse=True)[:na]
ab_list[na:] = sorted(list(map(int, input().split())), reverse=True)[:nb]
ab_list += sorted(list(map(int, input().split())), reverse=True)[:min(na + nb, c)]

ab_list.sort(reverse=True)

print(sum(ab_list[:na + nb]))

Solution (Python):
xyabc=input().split()
x=int(xyabc[0])
y=int(xyabc[1])
a=int(xyabc[2])
b=int(xyabc[3])
c=int(xyabc[4])
list1=input().split()
list2=input().split()
list3=input().split()
d=a-x+b-y
an=[]
bn=[]
cn=[]
for num in list1 :
  an.append(int(num))
for num in list2 :
  bn.append(int(num))
for num in list3 :
  cn.append(int(num))
an.sort(reverse=True)
bn.sort(reverse=True)

an=an[:x]
bn=bn[:y]

for a in an :
  cn.append(a)
for b in bn :
  cn.append(b)
cn.sort(reverse=True)
count=0
for i in range(x+y) :
  count+=cn[i]

print(count)

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)

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

print(sum(ans))

Solution (Python):



import queue 








mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

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)
    e = p[0:x] + q[0:y] + r
    e.sort(reverse=True)
    ans = 0
    for i in range(x+y):
        ans += e[i]
    print(ans)
    return

if __name__=='__main__':
    main()

Solution (Python):
x, y, a, b, c = [int(e) for e in input().split()]
pa = sorted([int(e) for e in input().split()], reverse=True)
pb = sorted([int(e) for e in input().split()], reverse=True)
pr = sorted([int(e) for e in input().split()], reverse=True)

print(sum(sorted(pa[:x] + pb[:y] + pr, reverse=True)[:x+y]))

Solution (Python):
inf = 10 ** 9 + 1
x, y, a, b, c = map(int, input().split())

r = [int(i) for i in input().split()] + [inf]
g = [int(i) for i in input().split()] + [inf]
m = [int(i) for i in input().split()]
r.sort()
g.sort()
m.sort(reverse=True)
i = -x-1
j = -y-1
S = 0

for k in range(c):
    if r[i] <= g[j]:
        if m[k] > r[i]:
            S += m[k]
            i += 1
        else:
            break
    else:
        if m[k] > g[j]:
            S += m[k]
            j += 1
        else:
            break

S += sum(r[i:-1]) + sum(g[j:-1])
print(S)

Solution (Python):
x, y, a, b, c = map(int, input().split())
pa = sorted(list(map(int, input().split())), reverse=True)
pb = sorted(list(map(int, input().split())), reverse=True)
pc = sorted(list(map(int, input().split())), reverse=True)
ans = sorted(pa[:x] + pb[:y])
for i in range(min(len(ans), len(pc))):
    if pc[i] > ans[i]:
        ans[i] = pc[i]
    else:
        break
print(sum(ans))

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

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

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.reverse()
Q.reverse()

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

eatable_apple = P+Q+R
eatable_apple.sort()
eatable_apple.reverse()

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

Solution (Python):
x,y,a,b,c=map(int,input().split())
p=[0]*a
q=[0]*b
r=[0]*c
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
List=[]
newp=sorted(p,reverse=True)
newq=sorted(q,reverse=True)
for i in range(max(x,y,c)):
  if (i<x):
    List.append(newp[i])
  if (i<y):
    List.append(newq[i])
  if (i<c):
    List.append(r[i])


ans=sorted(List,reverse=True)
print(sum(ans[:x+y]))

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

red_apple = list(map(int, input().split()))
green_apple = list(map(int, input().split()))
all_apple = list(map(int, input().split()))

red_apple = sorted(red_apple, reverse=True)
green_apple = sorted(green_apple, reverse=True)

all_apple += red_apple[:X]
all_apple += green_apple[:Y]
ans = sum(sorted(all_apple)[::-1][:X+Y])
print(ans)

Solution (Python):
from heapq import heappop,heappush
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
p.sort(reverse=1)
q=list(map(int,input().split()))
q.sort(reverse=1)
r=list(map(int,input().split()))+[0]
r.sort(reverse=1)
h=[]
m=p[0]
for i in range(x):
  heappush(h,p[i])
  m=min(m,p[i])
for i in range(y):
  heappush(h,q[i])
  m=min(m,q[i])
i=0
while m<r[i]:
  _=heappop(h)
  heappush(h,r[i])
  m=heappop(h)
  heappush(h,m)
  i+=1
print(sum(h))

Solution (Python):
import sys
from heapq import heappop, heapify


def input() -> str:
    return sys.stdin.readline().rstrip("\r\n")


def main():
    x, y, a, b, c = map(int, input().split())
    red = [(-int(s), 'r') for s in input().split()]
    green = [(-int(s), 'g') for s in input().split()]
    colorless = [(-int(s), 'n') for s in input().split()]
    apples = red + green + colorless
    heapify(apples)
    cnt = {'r': x, 'g': y, 'n': -1}
    res = 0
    while sum(cnt.values()) + 1 and apples:
        num, clr = heappop(apples)
        if cnt[clr] == 0:
            continue
        cnt[clr] -= 1
        res -= num
    print(res)


if __name__ == "__main__":

    main()

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

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

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

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

for e in r :
    heapq.heappushpop(pq, e)

print(sum(pq))

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

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 = []
d_append = d.append
for i in range(x):
    d_append(P[i])

for i in range(y):
    d_append(Q[i])

for i in range(c):
    d_append(R[i])

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

Solution (Python):
x,y,a,b,c = map(int,input().split())
n = a+b+c
ar = list(map(int,input().split()))
br = list(map(int,input().split()))
cr = list(map(int,input().split()))
ls = []
for i in ar:
  ls.append([i,1])
for i in br:
  ls.append([i,2])
for i in cr:
  ls.append([i,3])
ls.sort(reverse = True)
nx = 0
ny = 0
cnt = 0
res = 0
for item in ls:
  if item[1]==1:
    if nx==x: continue
    nx+=1
  if item[1]==2:
    if ny==y: continue
    ny+=1
  res+=item[0]
  cnt+=1
  if cnt==x+y:
    break
print(res)

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()]
from collections import deque
P_sort = sorted(P,reverse=True)[0:X]
Q_sort = sorted(Q,reverse=True)[0:Y]
R_sort = deque(sorted(R,reverse=True)[0:X+Y])
PQ = sorted(P_sort + Q_sort)
for i in range(len(PQ)):
    if R_sort[0] > PQ[i]:
        r = R_sort.popleft()
        PQ[i] = r
    if not R_sort:
      break
print(sum(PQ))

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

pp = sorted(pl,reverse=True)[:x]
qq = sorted(ql,reverse=True)[:y]
al = pp + qq + rl

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

Solution (Python):
import sys
import numpy as np

X, Y, A, B, C = map(int, sys.stdin.readline().rstrip().split())
P = list(map(int, sys.stdin.readline().rstrip().split()))
Q = list(map(int, sys.stdin.readline().rstrip().split()))
R = list(map(int, sys.stdin.readline().rstrip().split()))

if A == 1 and B == 1 and C == 1:
    ans = sum(sorted([P[0], Q[0], R[0]], reverse=True)[:2])
    print(ans)
    sys.exit()

Pmin = np.min(P)
Qmin = np.min(Q)
Rmax = np.max(R)


if Pmin > Rmax and Qmin > Rmax:
    sP = np.sort(P)[::-1] if len(set(P)) > 1 else P
    sQ = np.sort(Q)[::-1] if len(set(Q)) > 1 else Q
    ans = np.sum(sP[:X]) + np.sum(sQ[:Y])
    print(ans)
    sys.exit()

gS = P + Q + R
p = A + B
iX = 0
iY = 0
iR = []
aX = [0] * X
aY = [0] * Y
aR = []
for index in np.argsort(gS)[::-1]:
    if iX == X and iY == Y:
        break
    if index < A:
        if iX == X:
            continue
        else:
            aX[iX] = gS[index]
            iX += 1
    elif index < p:
        if iY == Y:
            continue
        else:
            aY[iY] = gS[index]
            iY += 1
    else:
        iR.append((iX, iY))
        aR.append(gS[index])

sumX = sum(aX)
sumY = sum(aY)
for (iX, iY), s in zip(iR, aR):
    if len(aX) == 0 and len(aY) == 0:
        break
    if len(aX) == 0:
        if s <= aY[-1]:
            break
        sumY = sumY + s - aY.pop()
        if len(aY) == 0:
            break
    elif len(aY) == 0:
        if s <= aX[-1]:
            break
        sumX = sumX + s - aX.pop()
        if len(aX) == 0:
            break
    else:
        if s <= aX[-1] and s <= aY[-1]:
            break
        if iX == X:
            sumY = sumY + s - aY.pop()
        elif iY == Y:
            sumX = sumX + s - aX.pop()
        else:
            if aX[-1] < aY[-1]:
                sumX = sumX + s - aX.pop()
            else:
                sumY = sumY + s - aY.pop()

print(sumX + sumY)

Solution (Python):
def merge_sort(arr):
 if len(arr) <= 1:
  return arr
 mid = len(arr) // 2

 left = arr[:mid]
 right = arr[mid:]

 left = merge_sort(left)
 right = merge_sort(right)

 return merge(left, right)
def merge(left, right):
 merged = []
 l_i, r_i = 0, 0

 while l_i < len(left) and r_i < len(right):
    
  if left[l_i] <= right[r_i]:
   merged.append(left[l_i])
   l_i += 1
  else:
   merged.append(right[r_i])
   r_i += 1


 if l_i < len(left):
  merged.extend(left[l_i:])
 if r_i < len(right):
  merged.extend(right[r_i:])
 return merged

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=merge_sort(P)
QQ=merge_sort(Q)
S=PP[A-X:A]+QQ[B-Y:B]+R
SS=merge_sort(S)
D=0
for r in range(X+Y):
 D+=SS[C+r]
print(D)

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)

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

print(sum(candidate[: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 = [[value, "r"] for value in p]
q = [[value, "g"] for value in q]
r = [[value, "s"] for value in r]

pqr = p + q + r
pqr = sorted(pqr, key=lambda x: x[0], reverse=True)

n_rgs = {"r": 0, "g": 0, "s": 0}

for val, color in pqr:
    n_rgs[color] += 1

    if min(n_rgs["r"], X) + min(n_rgs["g"], Y) + n_rgs["s"] == X+Y:
        break

ans = 0
for val, _ in p[:min(n_rgs["r"], X)]:
    ans += val
for val, _ in q[:min(n_rgs["g"], Y)]:
    ans += val
for val, _ in r[:n_rgs["s"]]:
    ans += val

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)

ans = 0
l = []

for i in range(X):
    l.append(P[i])
for j in range(Y):
    l.append(Q[j])
    
l = sorted(l)


for k in range(C):
    if R[k] > l[k]:
        l[k] = R[k]
    else:
        break

print(sum(l))

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

AList=list(map(int,input().split()))
BList=list(map(int,input().split()))
CList=list(map(int,input().split()))

AList.sort(reverse=True)
BList.sort(reverse=True)
CList.sort(reverse=True)

alist = AList[0:X] + BList[0:Y] + CList
alist.sort(reverse=True)

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

Solution (Python):
import heapq
 
x, y, a, b, c = map(int, input().split())
 
def max_listup(limit):
  l = sorted(list(map(int, input().split())))
  cnt = 1
  res = []
  while l:
    if cnt > limit:
      break
    m = l.pop()
    res.append(m)
    cnt += 1
  return res

all = sorted(max_listup(x) + max_listup(y) + list(map(int, input().split())))
ans = 0
for _ in range(x+y):
  ans += all.pop()

print(ans)

Solution (Python):
import heapq

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

def max_listup(limit):
  l = sorted(list(map(int, input().split())))
  cnt = 1
  res = []
  while l:
    if cnt > limit:
      break
    m = l.pop()
    res.append(m)
    cnt += 1
  return res

if __name__ == "__main__":
  all = sorted(max_listup(x) + max_listup(y) + list(map(int, input().split())))
  ans = 0
  for _ in range(x+y):
    ans += all.pop()

  print(ans)

Solution (Python):
import heapq

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

def max_listup(limit):
  l = list(map(lambda x:int(x)*-1, input().split()))
  heapq.heapify(l)
  cnt = 1
  res = []
  while l:
    if cnt > limit:
      break
    m = heapq.heappop(l)
    res.append(m*-1)
    cnt += 1
  return res

if __name__ == "__main__":
  all = sorted(max_listup(x) + max_listup(y) + list(map(int, input().split())))
  ans = 0
  for _ in range(x+y):
    ans += all.pop()

  print(ans)

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)

p.extend(q)
ans=sorted(p)


for i in range(x+y):
    if len(r)==i or r[i]<ans[i]:
        break
    else:
        ans[i]=r[i]
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(reverse=True)
q.sort(reverse=True)

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

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

d = []
d.extend(sorted(p)[::-1][:x])
d.extend(sorted(q)[::-1][:y])
d.extend(sorted(r)[::-1])
print(sum(sorted(d)[::-1][:x+y]))

Solution (Python):
X,Y,A,B,C=map(int,input().split())
P=sorted([int(x) for x in input().split()])
Q=sorted([int(x) for x in input().split()])
R=sorted([int(x) for x in input().split()])

final=sorted(P[A-X:]+Q[B-Y:]+R,reverse=True)

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

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