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

list_of_green.sort(reverse=True)
list_of_red.sort(reverse=True)
list_of_colorless.sort(reverse=True)

max_of_red = list_of_red[:x]
max_of_green = list_of_green[:y]

temp = (max_of_red+max_of_green+list_of_colorless)
temp.sort(reverse=True)
ans = sum(temp[:x+y])
print(ans)

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, Q = sorted(P, reverse=True), sorted(Q, reverse=True)
P, Q = P[:X], Q[:Y]
ans = sum(sorted(P + Q + R, reverse=True)[:X + Y])
print(ans)

Solution (Python):
import bisect

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

for i in range(min(x+y,c)):
    if l[i]<r[-1]:
        l[i]=r.pop()
    else:
        break
print(sum(l))

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)
i=0
j=0
k=0
c1=(x+y)-min(c,x+y)
count=0
res=[]
s=0
while(i<x and j<y):
    if(p[i]>q[j]):
        ans=p[i]
        i+=1
    else:
        ans=q[j]
        j+=1
    if(count>=c1):
        res.append(ans)
    else:
        s+=ans
    count+=1
while(i<x):
    ans=p[i]
    i+=1
    if(count>=c1):
        res.append(ans)
    else:
        s+=ans
    count+=1

while(j<y):
    ans=q[j]
    j+=1
    if(count>=c1):
        res.append(ans)
    else:
        s+=ans
    count+=1
c1=min(c,x+y)
count=0
i=0
j=0
while(i<c1 and j<c1):
    if(count>=c1):
        break
    if(res[i]>r[j]):
        s+=res[i]
        i+=1
    else:
        s+=r[j]
        j+=1
    count+=1
print(s)

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

apples = []
for i in p:
    apples.append(i)
for j in q:
    apples.append(j)
for h in r:
    apples.append(h)

apples.sort(reverse=True)
apples = apples[:A+B]
print(sum(apples[:X+Y]))
"""
red = 0
green = 0
trans = 0
ans = 0
for i in range(A+B):
    num = apples[i][1]
    if num == 0 and red <= A:
        ans += apples[i][0]
        red += 1
    elif num == 1 and green <= B:
        ans += apples[i][0]
        green += 1
    elif num == 2 and trans <= C:
        ans += apples[i][0]
        if red < green:
            red += 1
        else:
            green += 1

print(ans)
"""

Solution (Python):
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p=p[:x]
q=q[:y]
p[len(p):len(p)]=q
p[len(p):len(p)]=r
p.sort(reverse=True)
print(sum(p[: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 = [0]*(A+1)
P[1] = p[0]
for i in range(2,A+1):
    P[i] = P[i-1] + p[i-1]

Q = [0]*(B+1)
Q[1] = q[0]
for i in range(2,B+1):
    Q[i] = Q[i-1] + q[i-1]

R = [0]*(C+1)
R[1] = r[0]
for i in range(2,C+1):
    R[i] = R[i-1] + r[i-1]

z = 0
res = []

x = X
y = Y
p.append(10000000000)
q.append(10000000000)

for i in range(C+1):
    
    hp = P[x] + Q[y] + R[z]
    if p[x-1] <= q[y-1] and x > 0:
        x -= 1
        z += 1
    elif p[x-1] >= q[y-1] and y > 0:
        y -= 1
        z += 1

    res.append(hp)

print(max(res))

Solution (Python):
X,Y,A,B,C = map(int,input().split())
p_s = list(map(int,input().split()))
q_s = list(map(int,input().split()))
r_s = list(map(int,input().split()))
p_s.sort()
q_s.sort()
r_s.sort()
p = p_s[A-X:]
q = q_s[B-Y:]
r = r_s[max(C-(X+Y),0):]
p.reverse()
q.reverse()
r.reverse()
p.append(0)
q.append(0)
r.append(0)
i=0
j=0
k = 0
SUM = 0
cnt = 0
while cnt < X+Y:
    if i<len(p)-1 and p[i] >= q[j] and p[i] >= r[k]:
        SUM += p[i]
        i+=1
    elif j<len(q)-1 and q[j] >= p[i] and q[j] >= r[k]:
        SUM += q[j]
        j+=1
    elif k<len(r)-1 and r[k] >= q[j] and r[k] >= p[i]:
        SUM += r[k]
        k+=1
    cnt += 1
print(SUM)

Solution (Python):



from math import *
from copy import *
from string import *				
from random import *				
from bisect import *				
from sys import stdin				
from sys import maxsize
from operator import *				
from itertools import *
from collections import Counter		
from collections import defaultdict 

'''
1 2 2 2 1
2 4
5 1
3
'''

def solve(p,q,r,x,y):
	a,b,c = len(p),len(q),len(r)
	p = sorted(p)[::-1][:x]
	q = sorted(q)[::-1][:y]
	r = sorted(r)[::-1]
	t = p + q + r
	t = sorted(t)[::-1][:x+y]
	return sum(t)


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

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

def main():
    X, Y, *_, = map(int, input().split())
    P = sorted(map(int, input().split()), reverse=True)[:X]
    Q = sorted(map(int, input().split()), reverse=True)[:Y]
    R = list(map(int, input().split()))
    PQR = P + Q + R
    PQR.sort(reverse=True)
    ans = sum(PQR[: X + Y])
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    X, Y, A, B, C = map(int, input().split())
    P = sorted(map(int, input().split()), reverse=True)[:X]
    Q = sorted(map(int, input().split()), reverse=True)[:Y]
    R = list(map(int, input().split()))
    PQR = P + Q + R
    PQR.sort(reverse=True)
    ans = sum(PQR[: X + Y])
    print(ans)


if __name__ == "__main__":
    main()

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


X, Y, A, B, C = inpl()
P = inpl()
Q = inpl()
R = inpl()
P.sort()
Q.sort()
R.sort(reverse=True)

ans = sum(P[A - X:]) + sum(Q[B - Y:])
P.append(10**10)
Q.append(10**10)


pi = A - X
qi = B - Y
for ri in range(C):
    if P[pi] >= R[ri] and Q[qi] >= R[ri]:
        break
    elif P[pi] > Q[qi]:
        ans -= Q[qi]
        qi += 1
        ans += R[ri]
    else:
        ans -= P[pi]
        pi += 1
        ans += R[ri]

print(ans)

Solution (Python):
from heapq import heappush, heappop, heapify
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,Q = p[:X],q[:Y]

heapify(P)
heapify(Q)

for i in range(C):
  if min(P[0],Q[0]) > r[i]:
    break
  if P[0] < Q[0]:
    heappop(P)
    heappush(P,r[i])

  else:
    heappop(Q)
    heappush(Q,r[i])
print(sum(P)+sum(Q))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
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 LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]



def main():
    a=LI()
    x=a[0]
    y=a[1]
    b=a[3]
    c=a[4]
    a=a[2]
    pa=LI()
    pb=LI()
    pc=LI()
    pa.sort()
    pb.sort()
    pc.sort()
    pa.reverse()
    pb.reverse()
    pc.reverse()
    pa=pa[0:x]
    pb=pb[0:y]
    pa+=pb
    pa.sort()
    pa.reverse()
    j=len(pa)-1
    summ=0
    for i in range(0, len(pa)):
        summ+=pa[i]
    for i in range(0, len(pc)):
        if j>=0 and pc[i]<=pa[j]:
            break
        else:
            summ-=pa[j]
            summ+=pc[i]
            j-=1
    print(summ)
main()

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

Solution (Python):
from collections import deque
x,y,a,b,c = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
d = deque(r)
aka = x-1
midori = y-1
ps = p[:x]
qs = q[:y]
li = ps + qs
li.sort(reverse=True)
i = 0
z = d.popleft()
while li[x+y-1-i] < z:
  li[x+y-1-i] = z
  i += 1
  if not d:
    break
  z = d.popleft()
ans = 0
for i in range(x+y):
  ans += li[i]
print(ans)

Solution (Python):

import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline




def acinput():
    return list(map(int, input().split(" ")))


def II():
    return int(input())

directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact



def serch(x, count):
    
            

    for d in directions:
        nx = d+x
        
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1 
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)  
                continue
            if field[nx[0]][nx[1]] == "
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)    
                 
    return count

X,Y,A,B,C=acinput()

p=acinput()
q=acinput()
r=acinput()



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

tmp=p[:X]
tmp.extend(q[:Y])

tmp.extend(r)

tmp=sorted(tmp,reverse=True)

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

Solution (Python):
x,y,a,b,c=map(int,input().split())
AC=[]
for a in map(int,input().split()):
  AC.append((a,1))
for a in map(int,input().split()):
  AC.append((a,2))
for a in map(int,input().split()):
  AC.append((a,0))
AC.sort(reverse=1)

red=0
green=0
cnt=0
res=0
for a,c in AC:
  if c==0:
    res+=a
    cnt+=1
  elif c==1:
    if red<x:
      res+=a
      red+=1
      cnt+=1
  else:
    if green<y:
      res+=a
      green+=1
      cnt+=1
  if cnt==x+y:
    print(res)
    exit(0)

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
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)
A = p[:x] + q[:y] + r
A.sort(reverse=1)
print(sum(A[: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)






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

merge_list.sort(reverse=True)


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

Solution (Python):
from collections import deque
x,y,r, g, n  = map(int,input().split())

R = list(map(int, input().split()))
G = list(map(int, input().split()))
N = list(map(int, input().split()))

R.sort(reverse = True)
G.sort(reverse = True)
N.sort()
R_dq = deque(R[:x])
G_dq = deque(G[:y])
N_dq = deque(N)

flag =True
while flag:
    r_tail = R_dq[-1]
    g_tail = G_dq[-1]
    if len(N_dq) ==0:
        break
    else:
        n_tail = N_dq[-1]

    if r_tail < g_tail:
        if r_tail < n_tail:
            R_dq.pop()
            R_dq.appendleft(n_tail)
            N_dq.pop()
        else:
            break
    else:
        if g_tail < n_tail:
            G_dq.pop()
            G_dq.appendleft(n_tail)
            N_dq.pop()
        else:
            break
print(sum(R_dq) + sum(G_dq))

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

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

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

Solution (Python):
X, Y, A, B, C = map(int, input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p = p[:X]
q = q[:Y]
l = sorted(p + q + r, reverse=True)
print(sum(l[:X+Y]))

Solution (Python):
from heapq import heappop, heappush

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

for p in map(int, input().split()):
  heappush(apple, (-p, 0))
for q in map(int, input().split()):
  heappush(apple, (-q, 1))
for r in map(int, input().split()):
  heappush(apple, (-r, 2))
delicious = 0
colorless = 0
while x + y > colorless:
  minus_taste, color = heappop(apple)
  if color == 0:
    if x > 0:
      delicious -= minus_taste
      x -= 1
  elif color == 1:
    if y > 0:
      delicious -= minus_taste
      y -= 1
  else:
    delicious -= minus_taste
    colorless += 1
print(delicious)

Solution (Python):
import sys
from math import factorial
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

x, y, a, b, c = MAP()
p = LIST()
q = LIST()
r = LIST()

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

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

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

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

ct1 = x - 1
ct2 = y - 1
ct3 = c - 1
ans = 0

while ct3 >= 0:
    if ct1 >= 0 and ct2 >= 0:
        if p[ct1] > r[ct3] and q[ct2] > r[ct3]:
            break
        elif p[ct1] < q[ct2]:
            p[ct1] = r[ct3]
            ct1 -= 1
            ct3 -= 1
        else:
            q[ct2] = r[ct3]
            ct2 -= 1
            ct3 -= 1
    elif ct1 >= 0:
        if p[ct1] > r[ct3]:
            break
        else:
            p[ct1] = r[ct3]
            ct1 -= 1
            ct3 -= 1
    elif ct2 >= 0:
        if q[ct2] > r[ct3]:
            break
        else:
            q[ct2] = r[ct3]
            ct2 -= 1
            ct3 -= 1
    else:
      break
for i in range(x):
    ans += p[i]
for i in range(y):
    ans += q[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()))
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())
pa = sorted(list(map(int, input().split())), reverse=True) 
qb = sorted(list(map(int, input().split())), reverse=True) 
rc = list(map(int, input().split())) 

ans = []
ans += pa[:x]
ans += qb[:y]
ans += rc

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

Solution (Python):

x, y, a, b, c = map(int, input().split())
red = list(map(int, input().split()))
green = list(map(int, input().split()))
white = list(map(int, input().split()))
red.sort()
green.sort()
white.sort()

apples = []
for i in range(x):
    apples.append(red[(a-1)-i])
for i in range(y):
    apples.append(green[(b-1)-i])
    
add = min(x+y, c)
for i in range(add):
    apples.append(white[(c-1)-i])

apples.sort()
sum = 0
for j in range(x+y):
    sum += apples[(x + y + add -1)-j]
print(sum)

Solution (Python):

import sys

X,Y,A,B,C=map(int, sys.stdin.readline().split())
R=map(int, sys.stdin.readline().split())
G=map(int, sys.stdin.readline().split())
N=map(int, sys.stdin.readline().split())
R.sort(reverse=True)
G.sort(reverse=True)

L=R[:X]+G[:Y]+N
L.sort(reverse=True)
print sum(L[: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()

p = p[:X]
q = q[:Y]
heapq.heapify(p)
heapq.heapify(q)

jdg = True

while r and jdg:
    hp = heapq.heappop(p)
    hq = heapq.heappop(q)
    rr = r.pop()
    if hp > hq:
        heapq.heappush(p, hp)
        if rr > hq:
            heapq.heappush(q, rr)
        else:
            heapq.heappush(q, hq)
            r.append(rr)
            jdg = False            
    else:
        heapq.heappush(q, hq)
        if rr > hp:
            heapq.heappush(p, rr)
        else:
            heapq.heappush(p, hp)
            r.append(rr)
            jdg = False
print(sum(p) + sum(q))

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

from heapq import heappush, heappop

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

hP = []
hQ = []

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

for i in range(min(A, X)):
    heappush(hP, P[i])
for _ in range(X - A):
    heappush(hP, 0)

for i in range(min(B, Y)):
    heappush(hQ, Q[i])
for _ in range(Y - B):
    heappush(hQ, 0)

for r in R:
    hp = heappop(hP)
    hq = heappop(hQ)
    if r <= hp and r <= hq:
        heappush(hP, hp)
        heappush(hQ, hq)
    else:
        if hp <= hq:
            heappush(hP, r)
            heappush(hQ, hq)
        else:
            heappush(hP, hp)
            heappush(hQ, r)
            
print(sum(hP) + sum(hQ))

Solution (Python):
X, Y, A, B, C = map( int, input().split(" "))
scoreA = list( map(int, input().split(" ")))
scoreB = list( map(int, input().split(" ")))
scoreC = list( map(int, input().split(" ")))

scoreA.sort(reverse=True)
scoreB.sort(reverse=True)
scoreC.sort(reverse=True)

scoreAll = scoreA[:X] + scoreB[:Y] + scoreC

scoreAll.sort(reverse=True)

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

Solution (Python):
from sys import stdin
X,Y,A,B,C = [int(x) for x in stdin.readline().rstrip().split()]
P = [int(x) for x in stdin.readline().rstrip().split()]
Q = [int(x) for x in stdin.readline().rstrip().split()]
R = [int(x) for x in stdin.readline().rstrip().split()]

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

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

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

Solution (Python):
import sys
X, Y, A, B, C = sys.stdin.readline().split()
X = int(X)
Y = int(Y)
C = int(C)
scoreA = list(map(int, sys.stdin.readline().split()))
scoreB = list(map(int, sys.stdin.readline().split()))
scoreC = list(map(int, sys.stdin.readline().split()))
scoreA.sort(reverse=True)
scoreB.sort(reverse=True)
scoreC.sort(reverse=True)
scoreA = scoreA[:X]
scoreB = scoreB[:Y]
scoreAll = scoreA + scoreB + scoreC
scoreAll.sort(reverse=True)
print(sum(scoreAll[: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)
ate = p[0:X] +q[0:Y] + r








ate.sort(reverse=True)
ate = ate[0:X+Y]
print(sum(ate))

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

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)

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

heapify(R)
heapify(B)
for i in range(c):
  if min(R[0],B[0]) > r[i]:
    break
  if R[0] < B[0]:
    heappop(R)
    heappush(R,r[i])
  else:
    heappop(B)
    heappush(B,r[i])

print(sum(R) + sum(B))

Solution (Python):
import heapq

def main():
    X, Y, A, B, C, *Z = map(int, open(0).read().split())
    P = sorted(Z[:A], reverse=True)
    Q = sorted(Z[A: A + B], reverse=True)
    R = sorted(Z[A + B:], reverse=True)
    
    q = []
    ans = 0
    for i in range(X):
        v = P[i]
        heapq.heappush(q, v)
        ans += v
    for i in range(Y):
        v = Q[i]
        heapq.heappush(q, v)
        ans += v
    for i in range(C):
        vr = R[i]
        v = heapq.heappop(q)
        if v < vr:
            heapq.heappush(q, vr)
            ans += vr - v
        else:
            break
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
x,y,a,b,c=map(int,input().split())
l_r=sorted(map(int,input().split()),reverse=True)[:x]
l_b=sorted(map(int,input().split()),reverse=True)[:y]
l_w=sorted(map(int,input().split()),reverse=True)

ans=[]
ans+=l_r
ans+=l_b
ans+=l_w

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

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

Solution (Python):
X, Y, A, B, C = 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)
c_list = sorted(list(map(int, input().split(" "))), reverse=True)
p_list = p_list[:X]
q_list = q_list[:Y]
all_list = p_list+q_list+c_list
all_list.sort(reverse=True)
print(sum(all_list[0:X+Y]))

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

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

r = r[0:X]
g = g[0:Y]

ans = r+g+a
ans = sorted(ans, reverse = True)

print(sum(ans[0:(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()
p = p[A-X:]
q.sort()
q = q[B-Y:]
r.sort()
a = p+q+r
a.sort(reverse=True)
print(sum(a[: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_ind = X-1
q_ind = Y-1
r_ind = 0

while 1:

    if p_ind == -1 and q_ind == -1:
        break

    if q_ind == -1 or p[p_ind] < q[q_ind]:
        worst = p[p_ind]
        apple = "p"
    else:
        worst = q[q_ind]
        apple = "q"
    
    if worst <= r[r_ind]:
        r_ind += 1
        if apple == "p":
            p_ind -= 1
        else:
            q_ind -= 1
            
        if r_ind == C:
            break
    else:
        break

eat_p = p[:p_ind+1]
eat_q = q[:q_ind+1]
eat_r = r[:r_ind]

if p_ind == -1:
    eat_p = []
if q_ind == -1:
    eat_q = []


print(sum(eat_p) + sum(eat_q) + sum(eat_r))

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

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

a_list=list(map(int,input().split()))
a_list=sorted(a_list)
b_list=list(map(int,input().split()))
b_list=sorted(b_list)
a_list=a_list[-x:]
b_list=b_list[-y:]
c_list=list(map(int,input().split()))
for i in range(c):
    c_list[i]=-c_list[i]
import heapq
heapq.heapify(a_list)
heapq.heapify(b_list)
heapq.heapify(c_list)

flag=True
while flag and c_list:
    x=heapq.heappop(c_list)
    x=x*(-1)
    
    min_a=heapq.heappop(a_list)
    min_b=heapq.heappop(b_list)
    if min(min_a,min_b)>=x:
        flag=False
        heapq.heappush(a_list,min_a)
        heapq.heappush(b_list,min_b)
    else:
        if min_a>=min_b:
            heapq.heappush(a_list,min_a)
            heapq.heappush(b_list,x)
            
        elif min_a<min_b:
            heapq.heappush(b_list,min_b)
            heapq.heappush(a_list,x)

sum_a=sum(list(a_list))
sum_b=sum(list(b_list))

print(sum_a+sum_b)

Solution (Python):
from sys import stdin


def get_result(data):
    X, Y, A, B, C = data[0]
    p = sorted(data[1], reverse=True)
    q = sorted(data[2], reverse=True)
    r = sorted(data[3], reverse=True)
    tmp = p[0:X] + q[0:Y] + r
    ans = sum(sorted(tmp, reverse=True)[0:(X+Y)])
    return ans


if __name__ == '__main__':
    raw_data = [val.rstrip('\n') for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)

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


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

Solution (Python):
[X,Y,A,B,C] = [int(s) for s in input().rstrip().split(' ')]
L_p  = [int(s) for s in input().rstrip().split(' ')]
L_q  = [int(s) for s in input().rstrip().split(' ')]
L_r  = [int(s) for s in input().rstrip().split(' ')]
L_p.sort(reverse = True)
L_q.sort(reverse = True)
L = L_p[:X] + L_q[:Y] + L_r
L.sort(reverse = True)
print(sum(L[:X+Y]))

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

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

apples = []
for p_ in p_x:
  apples.append(p_)
for q_ in q_y:
  apples.append(q_)
for r_ in r_xy:
  apples.append(r_)

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

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

Solution (Python):
X,Y,A,B,C = list(map(int, input().split()))
As = sorted(list(map(int, input().split())), reverse=True)
Bs = sorted(list(map(int, input().split())), reverse=True)
Cs = list(map(int, input().split()))

As = As[:X]
Bs = Bs[:Y]
ans = 0
Xs = sorted(As+Bs+Cs, reverse=True)
print(sum(Xs[:X+Y]))

Solution (Python):
from collections import deque

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

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

while R and R[0] > PQ[0]:
    PQ.append(R.popleft())
    PQ.popleft()

print(sum(PQ))

Solution (Python):
from sys import stdin, stdout  

X,Y,A,B,C = [int(c) for c in input().split()]

p= [int(c) for c in input().split()]
q= [int(c) for c in input().split()]
r= [int(c) for c in input().split()]

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

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

i=j=0

for k,val in enumerate(r):
    if(i<len(p) and j<len(q)):
        if(val<=p[i] and val <= q[j]):
            break
        elif(val>p[i] and val<q[j]):
            res=res+val-p[i]
            i=i+1
        elif(val<p[i] and val>q[j]):
            res=res+val-q[j]
            j=j+1
        elif(val>p[i] and val>q[j]):
            if(p[i]>q[j]):
                res=res+val-q[j]
                j=j+1
            else:
                res=res+val-p[i]
                i=i+1
    elif(i<len(p) and j==len(q)):
        if(val<=p[i]):
            break
        elif(val>p[i]):
            res=res+val-p[i]
            i=i+1
    elif(i==len(p) and j<len(q)):
        if(val<=q[j]):
            break
        elif(val>q[j]):
            res=res+val-q[j]
            j=j+1
    elif(i==len(p) and j==len(q)):
        break
        
print(res)

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:
        ans += tp
        ip += 1
    elif tq >= tp and tq >= tr:
        ans += tq
        iq += 1
    else:
        ans += tr
        ir += 1
print(ans)

Solution (Python):
def main():
    x, y, a, b, c = map(int, input().split())
    red_apples = sorted(list(map(int, input().split())), reverse=True)[:x]
    green_apples = sorted(list(map(int, input().split())), reverse=True)[:y]
    colorless_apples = sorted(list(map(int, input().split())), reverse=True)[:min(x+y, c)]

    print(sum(sorted(red_apples + green_apples + colorless_apples, reverse=True)[:x+y]))


if __name__ == '__main__':
    main()

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