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

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

Solution (Python):
import sys



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


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    x, y, a, b, c = input_int_list()
    P = [-1] + sorted(input_int_list())  
    Q = [-1] + sorted(input_int_list())
    R = [-1] + sorted(input_int_list())
    A = []
    B = []
    C = []
    for i in range(x + y):
        if R[-1] >= P[-1] and R[-1] >= Q[-1]:
            C.append(R.pop())
        elif P[-1] >= Q[-1] and P[-1] >= R[-1]:
            A.append(P.pop())
        else:
            B.append(Q.pop())
    if len(A) <= x and len(B) <= y:
        print(sum(A) + sum(B) + sum(C))
    elif len(A) > x:
        for j in range(len(A) - x):
            if R[-1] >= Q[-1]:
                C.append(R.pop())
            else:
                B.append(Q.pop())
        print(sum(A[:x]) + sum(B) + sum(C))
    elif len(B) > y:
        for j in range(len(B) - y):
            if R[-1] >= P[-1]:
                C.append(R.pop())
            else:
                A.append(P.pop())
        print(sum(A) + sum(B[:y]) + sum(C))

    return


if __name__ == "__main__":
    main()

Solution (Python):
import heapq
X, Y, A, B, C = map(int, input().split())
AL = list(map(int, input().split()))
BL = list(map(int, input().split()))
CL = list(map(int, input().split()))
h = []
for a in AL:
  heapq.heappush(h, (-a, 0))
for b in BL:
  heapq.heappush(h, (-b, 1))
for c in CL:
  heapq.heappush(h, (-c, 2))
answer = 0
x_cnt = 0
y_cnt = 0
eat_cnt = 0
for _ in range(A+B+C):
  if eat_cnt >= X+Y:
    break
  d, t = heapq.heappop(h)
  if t == 0 and x_cnt+1 <= X:
    answer += -d
    x_cnt += 1
    eat_cnt += 1
  elif t == 1 and y_cnt+1 <= Y:
    answer += -d
    y_cnt += 1
    eat_cnt += 1
  elif t == 2:
    answer += -d
    eat_cnt += 1
print(answer)

Solution (Python):
import heapq
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(reverse = True)
Qlist.sort(reverse = True)
Rlist.sort(reverse = True)
i,j,k = 0,0,0
pmax = Plist[i]
qmax = Qlist[i]
rmax = Rlist[i]
Ans = 0
for _ in range(2*10**5):
    Ans += max(pmax,qmax,rmax)
    if pmax == max(pmax,qmax,rmax):
        i += 1
        if i != X:
            pmax = Plist[i]
        else:
            pmax = -1
    elif qmax == max(pmax,qmax,rmax):
        j += 1
        if j != Y:
            qmax = Qlist[j]
        else:
            qmax = -1
    else:
        k += 1
        try:
            rmax = Rlist[k]
        except:
            rmax = -1
    if i+j+k == X+Y:
        break
print(Ans)

Solution (Python):
x,y,a,b,c=map(int,input().split())
p=[0]+sorted(list(map(int,input().split())))[a-x:]
q=[0]+sorted(list(map(int,input().split())))[b-y:]
r=[0]+sorted(list(map(int,input().split())))
pi=-1
qi=-1
ri=-1
gs=0
rs=0
ws=0
s=0              
while gs+rs+ws!=x+y:
    if r[ri]>=q[qi]>=p[pi]:
        s += r[ri]
        ws+=1
        ri-=1

    elif r[ri]>=p[pi]>=q[qi]:
        s += r[ri]
        ws += 1
        ri -= 1

    elif q[qi]>=r[ri]>=p[pi]:
        s += q[qi]
        gs += 1
        qi -= 1

    elif q[qi]>=p[pi]>=r[ri]:
        s += q[qi]
        gs += 1
        qi -= 1

    elif p[pi]>=r[ri]>=q[qi]:
        s += p[pi]
        rs += 1
        pi -= 1

    elif p[pi]>=q[qi]>=r[ri]:
        s += p[pi]
        rs += 1
        pi -= 1

print(s)

Solution (Python):
x,y,a,b,c=map(int,input().split())
p=[0]+sorted(list(map(int,input().split())))[a-x:]
q=[0]+sorted(list(map(int,input().split())))[b-y:]
r=[0]+sorted(list(map(int,input().split())))
pi=-1
qi=-1
ri=-1
gs=0
rs=0
ws=0
s=0              
while gs+rs+ws!=x+y:
    if r[ri]>=q[qi]>=p[pi]:
        s += r[ri]
        ws+=1
        ri-=1

    elif r[ri]>=p[pi]>=q[qi]:
        s += r[ri]
        ws += 1
        ri -= 1

    elif q[qi]>=r[ri]>=p[pi]:
        s += q[qi]
        gs += 1
        qi -= 1

    elif q[qi]>=p[pi]>=r[ri]:
        s += q[qi]
        gs += 1
        qi -= 1

    elif p[pi]>=r[ri]>=q[qi]:
        s += p[pi]
        rs += 1
        pi -= 1

    elif p[pi]>=q[qi]>=r[ri]:
        s += p[pi]
        rs += 1
        pi -= 1

print(s)

Solution (Python):
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())
import sys
sys.setrecursionlimit(10**6)

x,y,a,b,c=sep()
red=lis()
green=lis()
colorless=lis()
red.sort(reverse=True)
green.sort(reverse=True)
colorless.sort()
red=red[:x][::-1]
green=green[:y][::-1]
i=0
j=0
while(colorless):
    if j>=y and i>=x:
        break
    elif j<y and i>=x:
        if colorless[-1]>green[j]:
            green[j]=colorless[-1]
            colorless.pop()
            j+=1
        else:
            break
    elif i<x and j>=y:
        if colorless[-1]>red[i]:
            red[i]=colorless[-1]
            colorless.pop()
            i+=1
        else:
            break

    elif red[i]<=green[j]:
        if colorless[-1]>red[i]:
            red[i]=colorless[-1]
            colorless.pop()
            i+=1
        else:
            break
    else:
        if colorless[-1]>green[j]:
            green[j]=colorless[-1]
            colorless.pop()
            j+=1
        else:
            break

print(sum(red) + sum(green))

Solution (Python):
import heapq
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(lambda x:-int(x),input().split()))
heapq.heapify(r)
for i in range(x):
    heapq.heappush(r,-p[i])
for i in range(y):
    heapq.heappush(r,-q[i])
ans=0
for i in range(x+y):
    ans-=heapq.heappop(r)
print(ans)

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

pA = list(map(lambda x: (int(x), "a"), input().split()))
pB = list(map(lambda x: (int(x), "b"), input().split()))
pC = list(map(lambda x: (int(x), "c"), input().split()))

apples = sorted(pA + pB + pC)

cntA = 0
cntB = 0
cntC = 0
cnt = 0

while cntA + cntB + cntC < x+y:
    val, col = apples.pop()

    if col == "a" and cntA < x:
        cntA += 1
        cnt += val
    elif col == "b" and cntB < y:
        cntB += 1
        cnt += val
    elif col == "c":
        cntC += 1
        cnt += val

print(cnt)

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

p_array_sort = sorted(p_array, reverse=True)
q_array_sort = sorted(q_array, reverse=True)
r_array_sort = sorted(r_array, reverse=True)

p_i = x - 1
q_i = y - 1

for r in r_array_sort:
    p = p_array_sort[p_i]
    q = q_array_sort[q_i]
    if r <= p and r <= q:
        break
    elif q <= p:
        q_array_sort[q_i] = r
        q_i = max(q_i - 1, 0)
    else:
        p_array_sort[p_i] = r
        p_i = max(p_i - 1, 0)

ans = sum(p_array_sort[:x]) + sum(q_array_sort[:y])
print(ans)

Solution (Python):
def main():
    X, Y, A, B, C = map(int, input().split())
    *P, = map(int, input().split())
    *Q, = map(int, input().split())
    *R, = map(int, input().split())

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

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    X, Y, A, B, C = map(int, readline().split())
    P = list(map(int, readline().split()))
    Q = list(map(int, readline().split()))
    R = list(map(int, readline().split()))

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

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

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

    return


if __name__ == '__main__':
    main()

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

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

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

l = p2 + q2 + r
l.sort(reverse=True)

ans = sum(l[:x+y])
print(ans)

Solution (Python):
x, y, a, b, c = map(int, input().split())
p = [0]+list(map(int, input().split()))
q = [0]+list(map(int, input().split()))
r = [0]+list(map(int, input().split()))
p.sort()
q.sort()
r.sort()
ans = 0
num = x+y
for _ in range(num):
    if x > 0 and y > 0:
      i, j, k = p[-1], q[-1], r[-1]
      if i >= j and i >= k:
          ans += i
          p.pop()
          x -= 1
      elif j >= i and j >= k:
          ans += j
          q.pop()
          y -= 1
      else:
          ans += k
          r.pop()
    elif x > 0:
        i, j = p[-1], r[-1]
        x -= 1
        if i >= j:
            ans += i
            p.pop()
        else:
            ans += j
            r.pop()
    elif y > 0:
        y -= 1
        i, j = q[-1], r[-1]
        if i >= j:
            ans += i
            q.pop()
        else:
            ans += j
            r.pop()
    
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()))
from collections import deque

p.sort()
p=p[len(p)-X:]
q.sort()
q=q[len(q)-Y:]
r.sort(reverse=True)
p=deque(p)
q=deque(q)

for i in r:
  if min(p[0],q[0])>i:break
  if p[0]<q[0]:
    p.popleft()
    p.append(i)
  else:
    q.popleft()
    q.append(i)
print(sum(p)+sum(q))

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


sin=p[a-x:]+q[b-y:]+r

sin.sort()

print(sum(sin[len(sin)-x-y:]))

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

i = X - 1
j = Y - 1
k = 0

p.append(float("INF"))
q.append(float("INF"))
r.append(-1)

while p[i] < r[k] or q[j] < r[k]:
    if p[i] < q[j]:
        i -= 1
        k += 1
    else:
        j -= 1
        k += 1

ans = 0
if i != -1:
    ans += sum(p[:i+1])
if j != -1:
    ans += sum(q[:j+1])
if k != 0:
    ans += sum(r[:k])

print(ans)

Solution (Python):




import sys
from io import StringIO
import unittest
import heapq

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    X,Y,a,b,c=map(int, readline().rstrip().split())

    R=list(map(lambda x: int(x)*(-1), readline().rstrip().split()))
    G=list(map(lambda x: int(x)*(-1), readline().rstrip().split()))
    C=list(map(lambda x: int(x)*(-1), readline().rstrip().split()))

    heapq.heapify(R)
    heapq.heapify(G)
    heapq.heapify(C)
    ans = []
    heapq.heapify(ans)

    for _ in range(X):
        a = heapq.heappop(R)
        heapq.heappush(ans,a)
    for _ in range(Y):
        a = heapq.heappop(G)
        heapq.heappush(ans,a)
    for _ in range(min(X+Y,c)):
        a = heapq.heappop(C)
        heapq.heappush(ans,a)
    a=0
    for _ in range(X+Y):
        a += heapq.heappop(ans) * -1

    print(a)
    
    
    

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

x,y,a,b,c=nii()
p=sorted(lnii(),reverse=True)
q=sorted(lnii(),reverse=True)
r=sorted(lnii(),reverse=True)

l=p[:x]+q[:y]
l.sort()

ans=0
for i in range(x+y):
  if i<c:
    ans+=max(l[i],r[i])
  else:
    ans+=l[i]

print(ans)

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

x,y,a,b,c=nii()
p=lnii()
q=lnii()
r=lnii()

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

l=p[:x]+q[:y]
l.sort()

ans=0
for i in range(x+y):
  if i<c:
    ans+=max(l[i],r[i])
  else:
    ans+=l[i]

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

s = p[:X]+q[:Y]
ans=sum(s)
heapq.heapify(s)

while r and s:
    if s[0]<r[-1]:
        ans += r[-1]
        r.pop()
        ans -= heapq.heappop(s)
    else:
        break
print(ans)

Solution (Python):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  


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

Z = [(P[i],1) for i in range(A)] + [(Q[i],0) for i in range(B)] + [(R[i],-1) for i in range(C)]
Z.sort(reverse=True)
a,b,c = 0,0,0  
n = 0  
ans = 0
for x in Z:
    if n == X+Y:
        break
    s,t = x
    if t == 1 and a == X:
        continue
    elif t == 0 and b == Y:
        continue
    else:
        n += 1
        ans += s
        if t == 1:
            a += 1
        elif t == 0:
            b += 1
        else:
            c += 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=sorted(p,reverse=True)
q=sorted(q,reverse=True)
r=sorted(r,reverse=True)
s=[]
for i in range(x):
    s.append(p[i])
for i in range(y):
    s.append(q[i])
s=sorted(s,reverse=True)
ws=[s[0]]
for i in range(x+y-1):
    ws.append(ws[-1]+s[i+1])
wr=[r[0]]
for i in range(c-1):
    wr.append(wr[-1]+r[i+1])
ans=ws[-1]
for i in range(min(x+y-1,c)):
    ans=max(ans,ws[-2-i]+wr[i])
print(ans)

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

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 = [-x for x in r]

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

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

heapify(p)
heapify(q)
heapify(r)

while r:
    pp = heappop(p)
    qq = heappop(q)
    rr = heappop(r)
    rr *= -1

    if pp >= rr and qq >= rr:
        heappush(p, pp)
        heappush(q, qq)
        break

    elif pp <= qq:
        heappush(q, qq)
        if pp < rr:
            heappush(p, rr)
    else:
        heappush(p, pp)
        if qq < rr:
            heappush(q, rr)

print(sum(p) + sum(q))

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


X, Y, A, B, C = LI()
red = LI()
green = LI()
mu = LI()
red.sort(reverse=True)
green.sort(reverse=True)
ans = red[:X]+green[:Y]+mu
ans.sort(reverse=True)
total = 0
for i in range(X+Y):
    total += ans[i]
print(total)

Solution (Python):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  
def LS2(): return list(sys.stdin.readline().rstrip())  


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

Z = [(P[i],1) for i in range(A)] + [(Q[i],0) for i in range(B)] + [(R[i],-1) for i in range(C)]
Z.sort(reverse=True)
a,b,c = 0,0,0
n = 0
ans = 0
for x in Z:
    if n == X+Y:
        break
    s,t = x
    if t == 1 and a == X:
        continue
    elif t == 0 and b == Y:
        continue
    else:
        n += 1
        ans += s
        if t == 1:
            a += 1
        elif t == 0:
            b += 1
        else:
            c += 1

print(ans)

Solution (Python):
'''
Created on 2020/09/10

@author: harurun
'''
def main():
  import heapq
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  


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

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

  p=p[:X]
  q=q[:Y]
  
  Q=[]
  for i in p:
    Q.append([i,0])
  for j in q:
    Q.append([j,1])

  heapq.heapify(Q)
  cntp=0
  cntq=0
  ans=0
  for k in r:
    t=heapq.heappop(Q)
    if t[1]==0 and t[0]<k and cntp<=X:
      ans+=k 
      cntp+=1

    elif t[1]==1 and t[0]<k and cntq<=Y:
      ans+=k 
      cntq+=1

    else:
      ans+=t[0]
      break
  while True:
    try:
      s=heapq.heappop(Q)
      ans+=s[0] 

    except:
      break
  print(ans)



  
  return 

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

box=[]

ans=0


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

for j in range(y):
    box.append(q[j])

box = box + r

box=sorted(box,reverse=True)

for k in range(x+y):
    ans+=box[k]

print(ans)

Solution (Python):
import heapq

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

qu=[]

for i in range(x):
    heapq.heappush(qu,p[i])

for i in range(y):
    heapq.heappush(qu,q[i])

while r:
    rr=r.pop()

    if rr<qu[0]:
        break

    heapq.heappop(qu)
    heapq.heappush(qu,rr)

print(sum(qu))

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=[]
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[0:x+y]))

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

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

ans = 0
red_cnt = 0
green_cnt = 0
cnt = 0

heap = []
for i in range(len(p)):
    heapq.heappush(heap,(-p[i],0))
for i in range(len(q)):
    heapq.heappush(heap,(-q[i],1))
for i in range(len(r)):
    heapq.heappush(heap,(-r[i],2))

while len(heap):
    _x,_y = heapq.heappop(heap)
    if _y == 0 and red_cnt < x:
        red_cnt += 1
        ans += _x
        cnt += 1
    elif _y == 1 and green_cnt < y:
        green_cnt += 1
        ans += _x
        cnt += 1
    elif _y == 2:
        cnt += 1
        ans += _x

    if cnt == x + y:
        print(-ans)
        exit()

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)

cand = p[0:X] + q[0:Y] + r

cand.sort(reverse=True)

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

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

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

R.sort(reverse=True)
G.sort(reverse=True)

Z = W+R[0:x] + G[0:y]

Z.sort(reverse=True)

print(sum(Z[0:x+y]))

Solution (Python):






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





p_list = p[:X]
q_list = q[:Y]
mylist = sorted(p_list + q_list + r, reverse=True)
ans = 0
for i in range(X+Y):
    ans += mylist[i]
print(ans)

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()))
v = 0
c = sorted(p[0:x] + q[0:y])
for i in range(x + y):
    if len(r):
        if c[i] < r[-1]:
            c[i] = r.pop()
    else:
        break
print(sum(c))

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

p=p[-x:]
q=q[-y:]
r=sorted(p+q+r)
print(sum(r[-x-y:]))
assert sum(r[-x-y:]) < 2**63

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

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

Solution (Python):
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
ans = sum(p[:X]) + sum(q[:Y])
x = X-1
y = Y-1
m = min(p[x],q[y])
n = 1
while len(r)>0 and r[0] > m:
    if n == 1:
        if p[x] > q[y]:
            ans += r[0] - q[y]
            y -= 1
        else:
            ans += r[0] - p[x]
            x -= 1
    else:
        ans += r[0] - m
        if x<0:
            y -= 1
        else:
            x -= 1
    r.pop(0)
    if y >= 0 and x >= 0:
        m = min(p[x],q[y])
    elif x >= 0 and y<0:
        m = p[x]
        n = 0
    elif y >= 0 and x<0:
        m = q[y]
        n = 0
    else:
        m = 10 ** 9 + 1
        n = 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()))
s=[]
for i in range(a):
    s.append([p[i],1])
for i in range(b):
    s.append([q[i],2])
for i in range(c):
    s.append([r[i],0])
s.sort(reverse=True)
o=0
X,Y,Z=0,0,0
for i in range(a+b+c):
    if s[i][1]==1 and X<x:
        X+=1
        Z+=1
        o+=s[i][0]
    elif s[i][1]==2 and Y<y:
        Y+=1
        Z+=1
        o+=s[i][0]
    elif s[i][1]==0:
        Z+=1
        o+=s[i][0]
    if Z==x+y:
        break
print(o)

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()))
s=[]
for i in range(a):
    s.append([p[i],1])
for i in range(b):
    s.append([q[i],2])
for i in range(c):
    s.append([r[i],0])
s.sort(reverse=True)
o=0
X,Y,Z=0,0,0
for i in range(a+b+c):
    if s[i][1]==1 and X<x:
        X+=1
        Z+=1
        o+=s[i][0]
    elif s[i][1]==2 and Y<y:
        Y+=1
        Z+=1
        o+=s[i][0]
    elif s[i][1]==0:
        Z+=1
        o+=s[i][0]
    if Z==x+y:
        break
print(o)

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

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

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

x=X-1
y=Y-1

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



if p[x]>=q[y]:
  a=q[y]
  f=1
else:
  a=p[x]
  f=2
while len(r)>=1 and a<r[0]:

  if f==1 :

    q[y]=r[0]
    y-=1
    r.pop(0)
  elif f==2 :

    p[x]=r[0]
    x-=1
    r.pop(0)
  else:

    break
    

    
  if (y==-1 and x>=0) or (x>=0 and p[x]<q[y]):

    a=p[x]
    f=2
  elif (x==-1 and y>=0) or (y>=0 and p[x]>=q[y]):

    a=q[y]
    f=1
  else:

    break

ans=0

for i in p[:X]:
  ans+=i
for i in q[:Y]:
  ans+=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()))

from collections import deque

p = sorted(p)[a-x:]
q = sorted(q)[b-y:]
t = deque(sorted(p+q))
r = deque(reversed(sorted(r)))


while r:
    if t[0] < r[0]:
        t.popleft()
        w = r.popleft()
        t.append(w)
    else:
        break

ans = sum(t)
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)

temp = P[:X] + Q[:Y] + R

temp.sort(reverse=True)
ans = sum(temp[:X+Y])

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

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

heapq.heapify(ans)

for j in range(c):
  min_a=heapq.heappop(ans)
  if min_a<=r[j]:
    heapq.heappush(ans,r[j])
  else:
    heapq.heappush(ans,min_a)
    break
    
print(sum(ans))

Solution (Python):
X, Y, A ,B, C = list(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)
ans = 0
for i in range(C):
  if(len(P) == 0):
    if(len(Q) == 0):
      break
    elif(Q[-1] < R[i]):
      Q.pop()
      ans += R[i]
    else:
      break
  elif(len(Q) == 0):
    if(P[-1] < R[i]):
      P.pop()
      ans += R[i]
    else:
      break
  else:
    if(P[-1] < Q[-1] and P[-1] < R[i]):
      P.pop()
      ans += R[i]
    elif(Q[-1] <= P[-1] and Q[-1] < R[i]):
      Q.pop()
      ans += R[i]
    else:
      break
ans += sum(P) + sum(Q)
print(ans)

Solution (Python):
x,y,a,b,c=map(int,input().split())
p=list(reversed(sorted(map(int,input().split()))))
q=list(reversed(sorted(map(int,input().split()))))
r=list(reversed(sorted(map(int,input().split()))))
p.append(2**100)
q.append(2**100)
r.append(-2**100)
s=sum(p[:x])+sum(q[:y])
t=0
while True:
  f=p[x-1]<q[y-1]
  m=p[x-1] if f else q[y-1]
  if m<r[t]:
    if f:
      x-=1
      s+=r[t]-p[x]
      t+=1
    else:
      y-=1
      s+=r[t]-q[y]
      t+=1
  else:
    break
print(s)

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

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

R = sorted(p)
G = sorted(q)
T = sorted(r)

W = 0
GetR = 0
GetG = 0
GetS = 0

while GetS < X + Y:
    a = -1
    b = -1
    c = -1
    if len(R) > 0 and GetR < X:
        a = R[-1]
    if len(G) > 0 and GetG < Y:
        b = G[-1]
    if len(T) > 0:
        c = T[-1]

    t = max([a, b, c])
    index = [a, b, c].index(t)
    W += t
    
    GetS += 1
    if index == 0:
        del(R[-1])
        GetR += 1
    if index == 1:
        del(G[-1])
        GetG += 1
    if index == 2:
        del(T[-1])

print(W)

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)
p2=p[:x]
q2=q[:y]
num=p2+q2
num.sort()
ans=sum(num)
cnt=ans
for i in range(min(x+y,c)):
    cnt+=r[i]-num[i]
    ans=max(ans,cnt)
print(ans)

Solution (Python):
x, y, a, b, c = map(int, input().split())
plst = list(map(int, input().split()))
qlst = list(map(int, input().split()))
rlst = list(map(int, input().split()))
plst.sort()
qlst.sort()
rlst.sort(reverse = True)
inf = 10 ** 20
plst = plst[-x:] + [inf]
qlst = qlst[-y:] + [inf]
r_pos = 0
p_pos = 0
q_pos = 0
while 1:
    if rlst[r_pos] <= plst[p_pos] and rlst[r_pos] <= qlst[q_pos]:
        break
    elif plst[p_pos] < qlst[q_pos]:
        plst[p_pos] = rlst[r_pos]
        p_pos += 1
        r_pos += 1
    else:
        qlst[q_pos] = rlst[r_pos]
        q_pos += 1
        r_pos += 1
    if r_pos == c:
        break
print(sum(plst) + sum(qlst) - inf * 2)

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] + Q[:y] + R
L.sort(reverse=True)
print(sum(L[:x+y]))

Solution (Python):
x_aka,y_mid,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_aka = sorted(p,reverse=True)
q_mid = sorted(q,reverse=True)
r_mu = sorted(r,reverse=True)

tmp = p_aka[:x_aka] + q_mid[:y_mid] + r_mu
sort_tmp = sorted(tmp,reverse=True)

print(sum(sort_tmp[:(x_aka+y_mid)]))

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

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

ans=p+q+r
ans.sort()
ans=ans[-x-y:]
print(sum(ans))

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

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

ans = sum(s[:X + Y])

print(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)[:X+Y]
i,j=X-1,Y-1
for r in R:
    if i==-1 and j==-1:
        break
    elif j==-1:
        if r>P[i]:
            P[i]=r
            i-=1
        else:
            break
    elif i==-1:
        if r>Q[j]:
            Q[j]=r
            j-=1
        else:
            break
    elif P[i]>Q[j]:
        if r>Q[j]:
            Q[j]=r
            j-=1
        else:
            break
    else:
        if r>P[i]:
            P[i]=r
            i-=1
        else:
            break
print(sum(P)+sum(Q))