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

import heapq
from collections import deque

heapq.heapify(p)
heapq.heapify(q)
r=deque(r)

for i in range(c):
    v_p=heapq.heappop(p)
    v_q=heapq.heappop(q)

    v_r=r.pop()
    if v_p<=v_q:
        heapq.heappush(q,v_q)
        if v_p<v_r:
            heapq.heappush(p,v_r)
        else:
            heapq.heappush(p,v_p)
    else:
        heapq.heappush(p,v_p)
        if v_q<v_r:
            heapq.heappush(q,v_r)
        else:
            heapq.heappush(q,v_q)

ans=sum(p)+sum(q)

print(ans)

Solution (Python):
from heapq import*


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

heapify(P); heapify(Q)
while R:
    p, q, r = heappop(P), heappop(Q), R.pop()
    if p < q:
        heappush(Q, q)
        if p < r:
            heappush(P, r)
        else:
            heappush(P, p)
            break
    else:
        heappush(P, p)
        if q < r:
            heappush(Q, r)
        else:
            heappush(Q, q)
            break

print(sum(P) + sum(Q))

Solution (Python):

import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

p = LIST()
q = LIST()
r = LIST()

p = sorted(p)[::-1]
q = sorted(q)[::-1]
r = sorted(r)[::-1]

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

new = p+q+r

new = sorted(new)[::-1]

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

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

print(sum(a[: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 = (list(map(int,input().split())))

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

Solution (Python):
X, Y, A, B, C = 2, 2, 2, 2, 2
prr = [8, 6]
qrr = [9, 1]
krr = [2, 1]


X, Y, A, B, C = 2, 2, 4, 4, 4
prr = [11, 12, 13, 14]
qrr = [21, 22, 23, 24]
krr = [1, 2, 3, 4]


X, Y, A, B, C = 1, 2, 2, 2, 1
prr = [2, 4]
qrr = [5, 1]
krr = [3]


X, Y, A, B, C = map(int,input().split())
prr = list(map(int,input().split()))
qrr = list(map(int,input().split()))
krr = list(map(int,input().split()))

def calculate(x, y, a, b, c, prr, qrr, krr):
    prr = sorted(prr,key=lambda x:-x)
    qrr = sorted(qrr, key=lambda x: -x)

    prr = prr[:x]
    qrr = qrr[:y]

    result = []
    result.extend(prr)
    result.extend(qrr)
    result.extend(krr)

    result = sorted(result,key=lambda x:-x)

    result = result[:(x+y)]

    print(sum(result))

calculate(X, Y, A, B, C, prr, qrr, krr)

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

Solution (Python):

from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

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

    now = sum(p[:X]) + sum(q[:Y])
    ans = now
    i = X-1
    j = Y-1

    for k in range(min(C,X+Y)):
        if i < 0:
            now += r[k]-q[j]
            j -= 1
        elif j < 0:
            now += r[k]-p[i]
            i -= 1
        elif p[i] < q[j]:
            now += r[k]-p[i]
            i -= 1
        else:
            now += r[k]-q[j]
            j -= 1
        ans = max(ans,now)
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
X,Y,A,B,C=list(map(int,input().split()))
A_l=list(map(int,input().split()))
B_l=list(map(int,input().split()))
C_l=list(map(int,input().split()))
A_l.sort(reverse=True)
B_l.sort(reverse=True)
C_l.sort()
A_after_l=A_l[:X]
B_after_l=B_l[:Y]
ans=[A_after_l,B_after_l]
ans=sum(ans,[])
ans.sort()
import heapq
heapq.heapify(ans)
for i in C_l:
   N=heapq.heappop(ans)
   if N < i:
      heapq.heappush(ans,i)
   else:
      heapq.heappush(ans,N)
print(sum(ans))

Solution (Python):
X,Y,A,B,C=list(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)

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

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

Solution (Python):
X,Y,A,B,C=list(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)

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

ans=sum(p[:X])+sum(q[:Y])

while k<len(r):
    if i>-1 and j>-1:
        if p[i]<q[j]:
            cmin=p[i]
            i-=1
        else:
            cmin=q[j]
            j-=1
        
        if r[k]<=cmin:
            break
        ans+=r[k]-cmin
        k+=1
    elif i>-1:
        cmin=p[i]
        i-=1

        if r[k]<=cmin:
            break

        ans+=r[k]-cmin
        k+=1
    elif j>-1:
        cmin=q[j]
        j-=1

        if r[k]<=cmin:
            break

        ans+=r[k]-cmin
        k+=1
    else:
        break

print(ans)

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)


def main():
    X, Y, A, B, C = LI()
    p, q, r = sorted(LI(), reverse=True)[:X], sorted(
        LI(), reverse=True)[:Y], LI()
    print(sum(sorted(p + q + r, reverse=True)[:X+Y]))


main()

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)


def main():
    X, Y, A, B, C = LI()
    p = LI()
    q = LI()
    r = LI()
    p = sorted(p, reverse=True)[:X]
    q = sorted(q, reverse=True)[:Y]
    heapify(p), heapify(q)

    for ri in r:
        if len(p) < X:
            heappush(p, ri)
        elif len(q) < Y:
            heappush(q, ri)
        else:
            ptop = p[0]
            qtop = q[0]
            if min(ptop, qtop, ri) == ri:
                continue
            if ptop <= qtop:
                heappop(p)
                heappush(p, ri)
            else:
                heappop(q)
                heappush(q, ri)

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


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

Solution (Python):
import heapq

X, Y, A, B, C = map(int, input().split())
apples = []
for x in input().split():
    apples.append((int(x), 'r'))
for x in input().split():
    apples.append((int(x), 'g'))
for x in input().split():
    apples.append((int(x), 'n'))
apples.sort()
apples.reverse()

r_count = 0
g_count = 0
n_count = 0
yummy = 0
for _ in range(A+B+C):
    apple = apples[_]
    if apple[1] == 'g' and not g_count == Y:
        g_count += 1
        yummy += apple[0]
    elif apple[1] == 'r' and not r_count == X:
        r_count += 1
        yummy += apple[0]
    elif apple[1] == 'n':
        n_count += 1
        yummy += apple[0]
    if g_count + r_count + n_count == X+Y:
        break
print(yummy)

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

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

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

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

p=p[(a-x):]
q=q[(b-y):]
p.extend(q)
p.sort()

idx=0
for i in range(len(p)):
    if p[i]>r[idx]:
        break
    else:
        p[i]=r[idx]
        idx+=1
        if c==idx:
            break

print(sum(p))

Solution (Python):


import sys
input=sys.stdin.readline

def main():
    X,Y,A,B,C=map(int,input().split())
    P=list(map(int,input().split()))
    Q=list(map(int,input().split()))
    R=list(map(int,input().split()))
    lis=[]
    for i in range(A):
        lis.append((P[i],0))
    for i in range(B):
        lis.append((Q[i],1))
    for i in range(C):
        lis.append((R[i],2))
        
    lis.sort(reverse=True)
    white=[]
    sumc=0
    xy=[X,Y]
    for i in range(len(lis)):
        if lis[i][1]==2:
            white.append(lis[i])
        elif xy[lis[i][1]]:
            xy[lis[i][1]]-=1
            sumc+=lis[i][0]
        if (sum(xy)<=len(white)):
            break
    for i in range(len(white)):
        sumc+=white[i][0]
    print(sumc)
            
    
if __name__=="__main__":
    main()

Solution (Python):
from collections import deque

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

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

Solution (Python):
from collections import deque

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

p = deque(p)
q = deque(q)
r = deque(r)

ans = 0
MIN = -1
N = X + Y
for _ in range(N):
    tmp_p, tmp_q, tmp_r = MIN, MIN, MIN
    if len(p) > 0 and X > 0:
        tmp_p = p.popleft()
    if len(q) > 0 and Y > 0:
        tmp_q = q.popleft()
    if len(r) > 0:
        tmp_r = r.popleft()
    
    if tmp_p >= tmp_q and tmp_p >= tmp_r:
        ans += tmp_p
        X -= 1
        if tmp_q != -1:
            q.appendleft(tmp_q)
        if tmp_r != -1:
            r.appendleft(tmp_r)

    elif tmp_q >= tmp_p and tmp_q >= tmp_r:
        ans += tmp_q
        Y -= 1
        if tmp_p != -1:
            p.appendleft(tmp_p)
        if tmp_r != -1:
            r.appendleft(tmp_r)

    else:
        ans += tmp_r
        if tmp_q != -1:
            q.appendleft(tmp_q)
        if tmp_p != -1:
            p.appendleft(tmp_p)

print(ans)

Solution (Python):
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
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 = sorted(P,reverse=True)
Q = sorted(Q,reverse=True)
R = sorted(R,reverse=True)
P = P[:X]
Q = Q[:Y]
PQR = sorted(P+Q+R,reverse = True)
ans = sum(PQR[:X+Y])
print(ans)

Solution (Python):
import itertools
import functools
import math
from collections import Counter

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

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

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

CHK()

Solution (Python):
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(lambda x:int(x)*-1,input().split())))
q=sorted(list(map(lambda x:int(x)*-1,input().split())))
r=sorted(list(map(lambda x:int(x)*-1,input().split())))
import heapq
v=p[:x]+q[:y]+r
heapq.heapify(v)
ans=0
for i in range(x+y):
  ans+=heapq.heappop(v)
print(-ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    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)
    Apples = sorted(P[:x] + Q[:y] + R, reverse=True)
    print(sum(Apples[: x + y]))


if __name__ == '__main__':
    resolve()

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

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

ans_p = deque(p[:X])
ans_q = deque(q[:Y])
ans_r = deque(r)

while (ans_p[-1]<ans_r[0]) or (ans_q[-1]<ans_r[0]):
  if ans_p[-1] <= ans_q[-1]:
    ans_p.pop()
    ans_p.appendleft(ans_r[0])
    ans_r.popleft()
  else:
    ans_q.pop()
    ans_q.appendleft(ans_r[0])
    ans_r.popleft()
  if not ans_r:
    break;
    
ans = sum(ans_p) + sum(ans_q)
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())
from heapq import *
p=[-i for i in p]
q=[-i for i in q]
r=[-i for i in r]
heapify(p)
heapify(q)
heapify(r)
ans=0
cnt=0
pt=heappop(p)
qt=heappop(q)
rt=heappop(r)
n=x+y
while (x>=0 or y>=0) and cnt<n:
  if rt==0:
    if pt<=qt:
      ans-=pt
      x-=1
      cnt+=1
      if p and x>0: pt=heappop(p)
      else: pt=0
    else:
      ans-=qt
      y-=1
      cnt+=1
      if q and y>0: qt=heappop(q)
      else: qt=0
  elif pt<=rt:
    ans-=pt
    x-=1
    cnt+=1
    if p and x>0: pt=heappop(p)
    else: pt=0
  elif qt<=rt:
    ans-=qt
    y-=1
    cnt+=1
    if q and y>0: qt=heappop(q)
    else: qt=0
  else:
    ans-=rt
    cnt+=1
    if r: rt=heappop(r)
    else: rt=0
print(ans)

Solution (Python):

def resolve():
    X, Y, A, B, C = map(int, input().split())
    apple_A = sorted(map(int, input().split()), reverse=True)[:X]
    apple_B = sorted(map(int, input().split()), reverse=True)[:Y]
    apple_C = sorted(map(int, input().split()), reverse=True)

    ans = apple_A + apple_B + apple_C
    ans.sort(reverse=True)
    
    print(sum(ans[:X+Y]))

if __name__ == "__main__":
    resolve()

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)

l = p[:X] + q[:Y] + r
print(sum(sorted(l, 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()))
ap = sorted(p)[a-x:]
aq = sorted(q)[b-y:]
r = sorted(r, reverse = True)

i,j,k = 0,0,0
flag = True

while k < c:
    if flag:
        if ap[i] <= aq[j]:
            if ap[i] <= r[k]:
                ap[i] = r[k]
                i += 1
                k += 1
                if i == x:
                    flag = False
                    continue
                continue
            else:
                break
        else:
            if aq[j] <= r[k]:
                aq[j] = r[k]
                j += 1
                k += 1
                if j == y:
                    flag = False
                    continue
                continue
    else:
        if i == x:
            if aq[j] <= r[k]:
                aq[j] = r[k]
                j += 1
                k += 1
                if j == y:
                    break
                continue
        else:
            if ap[i] <= r[k]:
                ap[i] = r[k]
                i += 1
                k += 1
                if i == x:
                    break
                continue
    
    break

ans = sum(ap) + sum(aq)
print(ans)

Solution (Python):
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))
P.sort()
Q.sort()
R.sort()
P = P[::-1]
Q = Q[::-1]
R = R[::-1]
D = P[:X] + Q[:Y] + R
D.sort()
D = D[::-1]
D = D[:X+Y]
ans = sum(D)
print(ans)

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

if __name__ == '__main__':
    main()

Solution (Python):
import sys
import itertools
import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

if __name__ == "__main__":
    main()
    pass

Solution (Python):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

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

ans=0

p=sorted(nl())[::-1][:x]
q=sorted(nl())[::-1][:y]
r=sorted(nl())[::-1]

s=sorted(p+q+r)[::-1]

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

Solution (Python):





import math
import fractions
import sys
import bisect
import heapq  
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n-1
    while(tmp >= l):
        a = a*tmp%mod
        tmp -= 1
    return a

inf = 10**18
mod = 10**9+7

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

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

ans = 0

if len(p) > x:
    p = p[:x]
if len(q) > y:
    q = q[:y]

p.extend(q)
p.extend(r)

p.sort(reverse=True)

p = p[:x+y]

print(sum(p))

Solution (Python):
import sys
import itertools

import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

X, Y, A, B, C = map(int, readline().split())
P = sorted(map(int, readline().split()), reverse=True)
Q = sorted(map(int, readline().split()), reverse=True)
R = sorted(map(int, readline().split()), reverse=True)

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

Solution (Python):
import numpy as np
inp = input



X, Y, A, B, C = map(int, inp().split())




red = list(map(int, inp().split()))
green = list(map(int, inp().split()))
white = list(map(int, inp().split()))
red.sort(reverse=True)
green.sort(reverse=True)
white.sort(reverse=True)






idr = 0
idg = 0
idw = 0

total = 0.0
countr = 0
countg = 0
countw = 0
while X > countr and Y > countg and (X+Y > countr+countg+countw):
    if red[idr] >= green[idg]:
        if idw >= C or red[idr] >= white[idw]:
            
            total += red[idr]
            idr += 1
            countr += 1
        elif idw < C:
            
            total += white[idw]
            idw += 1
            countw += 1
    else:
        if idw >= C or green[idg] >= white[idw]:
        
            total += green[idg]
            idg += 1
            countg += 1
        else:
            
            total += white[idw]
            idw += 1
            countw += 1


if Y <= countg:
    while X > countr+countw:
        
        if idw < C and red[idr] < white[idw]:
            
            total += white[idw]
            idw += 1
        else:
            
            total += red[idr]
            idr += 1
        countr += 1

if X <= countr:
    while Y > countg+countw:
        
        if idw < C and green[idg] < white[idw]:
            
            total += white[idw]
            idw += 1
        else:
            
            total += green[idg]
            idg += 1
        countg += 1

print(int(total))

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

Solution (Python):
def main():
    x, y, a, b, c = map(int, input().split())
    p = sorted([int(v) for v in input().split()])[-x:]
    q = sorted([int(v) for v in input().split()])[-y:]
    r = [int(v) for v in input().split()]
    r.extend(p)
    r.extend(q)
    print(sum(sorted(r)[-(x+y):]))


if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
import math

x, y, a, b, c = map(int, input().split(" "))
qL = sorted(list(map(int, input().split(" "))), reverse=True)[:x]
pL = sorted(list(map(int, input().split(" "))), reverse=True)[:y]
rL = sorted(list(map(int, input().split(" "))), reverse=True)

print(sum(sorted(qL + pL + rL, reverse=True)[:x + y]))

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True

    @staticmethod
    def fact(N):
        res = {}
        tmp = N
        for i in range(2, int(N ** 0.5 + 1) + 1):
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            if cnt > 0:
                res[i] = cnt
        if tmp != 1:
            res[tmp] = 1
        if res == {}:
            res[N] = 1
        return res


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    X, Y, A, B, C = Scanner.map_int()
    P = Scanner.map_int()
    Q = Scanner.map_int()
    R = Scanner.map_int()
    P.sort(reverse=True)
    P = P[:X]
    Q.sort(reverse=True)
    Q = Q[:Y]
    R.sort(reverse=True)
    R = R[:min(X + Y, C)]
    ans = P + Q + R
    ans.sort(reverse=True)
    print(sum(ans[:X + Y]))


def main():
    
    
    
    
    
    solve()


if __name__ == "__main__":
    main()

Solution (Python):
sentinel = 10 ** 9 + 10 ** 8

X, Y, A, B, C = map(int, input().split())
ps = [sentinel] + sorted(map(int, input().split()), reverse = True)
qs = [sentinel] + sorted(map(int, input().split()), reverse = True)
rs = sorted(map(int, input().split()), reverse = True)

X += 1
Y += 1

red_apples = X
green_apples = Y

while X+Y-red_apples-green_apples < C:
    if rs[X+Y-red_apples-green_apples] > qs[green_apples-1]:
        if qs[green_apples-1] > ps[red_apples-1]:
            red_apples -= 1
        else:
            green_apples -= 1
    elif rs[X+Y-red_apples-green_apples] > ps[red_apples-1]:
            red_apples -= 1
    else:
        break

print(sum(ps[1:red_apples]) + sum(qs[1:green_apples]) + sum(rs[:X+Y-red_apples-green_apples]))

Solution (Python):
x,y,A,B,C = map(int, input().split())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = list(map(int, input().split()))
aa = a[len(a)-x:]
bb = b[len(b)-y:]
for i in aa:
  c.append(i)
for i in bb:
  c.append(i)
c = sorted(c)
cc = c[len(c)-x-y:]
print(sum(cc))

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

apples = []
apples.extend([(p, 0) for p in P])
apples.extend([(q, 1) for q in Q])
apples.extend([(r, 2) for r in R])
apples.sort(key=lambda x: x[0], reverse=True)

ans = 0
num = X + Y
thresholds = [X, Y, C]
for v, category in apples:
    
    if not thresholds[category]:
        continue

    num -= 1
    thresholds[category] -= 1
    ans += v

    if num == 0:
        break

print(ans)

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

Solution (Python):
x, y, a, b, c = map(int,input().split())
p_p = list(map(int,input().split()))
q_q = list(map(int,input().split()))
r_r = list(map(int,input().split()))
p_p.sort(reverse=True)
q_q.sort(reverse=True)
r_r.sort(reverse=True)

oisisa = sum(p_p[:x])+sum(q_q[:y])
apple = p_p[:x] + q_q[:y]
apple.sort()
seen = 0
for i in range(min(x+y,c)):
    if r_r[i] > apple[seen]:
        oisisa = oisisa + r_r[i] - apple[seen]
        seen += 1
    else:
        break


print(oisisa)

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)

ans = sorted(P[:X] + Q[:Y])

for i in range(min(C, X+Y)):
    if R[i] > ans[i]:
        ans[i] = R[i]

print(sum(ans))