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):
import sys
class Heap:
    def __init__(self):
        self.heap = [None]*1000000
        self.root = 0
        self.size = 0
    
    def push(self, a:int):
        self.heap[self.size] = a
        b = self.size
        while b != 0 and self.heap[(b - 1) //2] < self.heap[b]:
            c = self.heap[(b - 1) //2]
            self.heap[(b - 1) //2] = self.heap[b]
            self.heap[b] = c
            b = (b - 1) //2
        self.size += 1
    
    def pop(self):
        a = self.heap[0]
        b = 0
        self.heap[b] = self.heap[self.size - 1]
        self.heap[self.size] = None
        self.size -= 1
        while (self.heap[b*2 + 1] is not None and self.heap[b] < self.heap[b*2 + 1]) or (self.heap[b*2 + 2] is not None and self.heap[b] < self.heap[b*2 + 2]):
            if self.heap[b*2 + 2] > self.heap[b*2 + 1]:
                c = self.heap[b]
                self.heap[b] = self.heap[b*2 + 2]
                self.heap[b*2 + 2] = c
                b = b*2 + 2
            else:
                c = self.heap[b]
                self.heap[b] = self.heap[b*2 + 1]
                self.heap[b*2 + 1] = c
                b = b*2 + 1
        return a
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()))
    pq = Heap()
    p.sort()
    q.sort()
    for i in range(x):
        pq.push(p[len(p) - 1 - i])
    for i in range(y):
        pq.push(q[len(q) - 1 - i])
    for i in range(len(r)):
        pq.push(r[i])
    ans = 0
    for i in range(x + y):
        ans += pq.pop()
    print(ans)

main()

Solution (Python):
import sys
import heapq
def main(): 
    x, y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    pq = []
    heapq.heapify(pq)
    p.sort()
    q.sort()
    for i in range(x):
        heapq.heappush(pq,-1*p[len(p) - 1 - i])
    for i in range(y):
        heapq.heappush(pq, -1*q[len(q) - 1 - i])
    for i in range(len(r)):
        heapq.heappush(pq, -1*r[i])
    ans = 0
    for i in range(x + y):
        ans += -1*heapq.heappop(pq)
    print(ans)

main()

Solution (Python):
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
sys.setrecursionlimit(10**6)

x,y,a,b,c = na()
p = na()
q = na()
r = na()
p = sorted(p, reverse=True)[:x]
q = sorted(q, reverse=True)[:y]
z = sorted(p+q+r, reverse=True)[:x+y]

print(sum(z))

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

Solution (Python):
import sys
input = sys.stdin.readline
'''
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
for test in range(int(input())):
'''
inf = 100000000000000000  

x, y, a, b, c = map(int, input().split())
array_a = list(map(int, input().split()))
array_b = list(map(int, input().split()))
array_c = list(map(int, input().split()))
array_a = sorted(array_a, reverse=True)[:x]
array_b = sorted(array_b, reverse=True)[:y]
ans = sum(sorted(array_a + array_b + array_c, reverse=True)[:x + y])
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
'''
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
for test in range(int(input())):
'''
inf = 100000000000000000  

x, y, a, b, c = map(int, input().split())
array_a = list(map(int, input().split()))
array_b = list(map(int, input().split()))
array_c = list(map(int, input().split()))
array_a = sorted(array_a, reverse=True)[:x]
array_b = sorted(array_b, reverse=True)[:y]
ans = sum(sorted(array_a + array_b + array_c, reverse=True)[:x + y])
print(ans)

Solution (Python):
def solve(X, Y, p, q, r):
    red_apples = sorted(p, reverse=True)[: X]
    green_apples = sorted(q, reverse=True)[: Y]
    return sum(sorted(red_apples + green_apples + r, reverse=True)[: X + Y])

if __name__ == '__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()))
    print(solve(X, Y, p, q, r))

Solution (Python):
def solve(X, Y, p, q, r):
    red_apples = sorted(p, reverse=True)[: X]
    green_apples = sorted(q, reverse=True)[: Y]
    white_apples = sorted(r)

    ret = 0
    while red_apples and green_apples:
        if not white_apples or (white_apples[-1] < red_apples[-1] and white_apples[-1] < green_apples[-1]):
            return ret + sum(red_apples) + sum(green_apples)

        ret += white_apples.pop(-1)
        if red_apples[-1] < green_apples[-1]:
            red_apples.pop(-1)
        else:
            green_apples.pop(-1)


    if not red_apples:
        while green_apples and white_apples and (green_apples[-1] < white_apples[-1]):
            ret += white_apples.pop(-1)
            green_apples.pop(-1)
        return ret + sum(green_apples)

    else:
        while red_apples and white_apples and (red_apples[-1] < white_apples[-1]):
            ret += white_apples.pop(-1)
            red_apples.pop(-1)
        return ret + sum(red_apples)

if __name__ == '__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()))
    print(solve(X, Y, p, q, r))

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):
import numpy as np
x, y, a, b, c = map(int,input().split())
p = np.array(input().split(),dtype=int)
q = np.array(input().split(),dtype=int)
r = np.array(input().split(),dtype=int)
p = np.sort(p)[::-1]
q = np.sort(q)[::-1]
ans = 0
kouho = []

for i in range(x):
    kouho.append(p[i])
for i in range(y):
    kouho.append(q[i])
for i in range(c):
    kouho.append(r[i])
kouho = sorted(kouho)[::-1]

for i in range(x+y):
    ans += kouho[i]

print(ans)

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

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

p1 = p[:X]
q1 = q[:Y]

pqr = p1 + q1 + r

pqr.sort(reverse = True)

ans = 0
for i in range(X+Y):
  ans += pqr[i]
  
print(ans)

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

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

Solution (Python):
X, Y, A, B, C = map(int, input().split())
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)


basket = []
for x in range(X) :
  basket.append(p[x])

for y in range(Y) :
  basket.append(q[y])

for c in range(C) :
  basket.append(r[c])


basket.sort(reverse=True)


ans = 0
for eat in range(X+Y) :
  ans += basket[eat]

print(ans)

Solution (Python):
x, y, a, b, c = map(int, input().split())
ps = sorted(list(map(int, input().split())), reverse=True)
qs = sorted(list(map(int, input().split())), reverse=True)
rs = sorted(list(map(int, input().split())), reverse=True)

choice_apples = sorted(ps[:x] + qs[:y])
total = 0
j = 0

for i in choice_apples:
    if rs and i < rs[0]:
        total += rs[0]
        del rs[0]
    else:
        total += i

print(total)

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

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

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

    lst = t_p + t_q + r

    lst = sorted(lst, reverse=True)

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

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007



def main():
	
	x, y, a, b, c = IN()
	al = list(IN())
	al.sort(reverse=True)
	bl = list(IN())
	bl.sort(reverse = True)
	cl = list(IN())
	cl.sort(reverse=True)
	
	tx=x-1
	ty=y-1
	tc=0
	while True:
		if tc == len(cl):
			break
		al_min=al[tx] if tx >= 0 else 10**11
		bl_min=bl[ty] if ty >= 0 else 10**11
		cl_max=cl[tc]
		if al_min >= cl_max and bl_min >= cl_max:
			break
		elif al_min <= bl_min and al_min < cl_max:
			tx -= 1
			tc += 1
		elif bl_min<= al_min and bl_min < cl_max:
			ty -= 1
			tc += 1
		else:
			break
	ret=sum(al[:tx+1])+sum(bl[:ty+1])+sum(cl[:tc])
	print(ret)
			
		
	
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

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

P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))
        
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

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())
a = sorted(list(map(int,input().split())),reverse=True)[:X]
b = sorted(list(map(int,input().split())),reverse=True)[:Y]
c = sorted(list(map(int,input().split())),reverse=True)

data = sorted(a+b+c,reverse=True)

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

Solution (Python):

import math
import operator as op
from functools import reduce
from fractions import Fraction as frac




def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer / denom
    

def rd(p):
    if(p==0):
        return input()
    if(p==1):
        return int(input())
    if(p==2):
        return map(int,input().split())
    if(p==3):
        return list(map(int,input().split()))



global par
par=[-1 for i in range(100001)]

def find(u):
    if(par[u]<0):
        return u
    else:
        return find(par[u])
def uni(x,y):
    u=find(x)
    v=find(y)
    if u==v:
        return
    if(par[u]<par[v]):
        par[u]+=par[v]
        par[v]=u
    else:    
        par[v]+=par[u]
        par[u]=v

        

t=1
for term in range(1,t+1):
    x,y,a,b,c=rd(2)
    A=rd(3)
    B=rd(3)
    C=rd(3)
    A.sort()
    B.sort()
    C.sort()
    temp=A[-x:]+B[-y:]+C
    temp.sort()
    tot=sum(temp[-x-y:])
    
    print(tot)

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

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

eat = []

for i in range(X):
    eat.append(p[i])
for i in range(Y):
    eat.append(q[i])

eat.sort()

for i in range(min(X+Y,len(r))):
    if eat[i] < r[i]:
        eat[i] = r[i]
    else:
        break

print(sum(eat))

Solution (Python):

import sys
import heapq
sys.setrecursionlimit(10**8)
INF = float("inf")


class MaxHeap(object):
    def __init__(self, x, default=-INF):
        self.heap = [-e for e in x]
        self.default = default
        heapq.heapify(self.heap)

    def push(self, value):
        heapq.heappush(self.heap, -value)

    def pop(self):
        if len(self.heap) == 0:
            return self.default
        else:
            return -heapq.heappop(self.heap)


def solve(X: int, Y: int, A: int, B: int, C: int, p: "List[int]", q: "List[int]", r: "List[int]"):
    p.sort()
    p = p[-X:]
    q.sort()
    q = q[-Y:]

    h = sorted(p+q+r)
    print(sum(h[-X-Y:]))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  
    Y = int(next(tokens))  
    A = int(next(tokens))  
    B = int(next(tokens))  
    C = int(next(tokens))  
    p = [int(next(tokens)) for _ in range(A)]  
    q = [int(next(tokens)) for _ in range(B)]  
    r = [int(next(tokens)) for _ in range(C)]  
    solve(X, Y, A, B, C, p, q, r)


if __name__ == '__main__':
    main()

Solution (Python):

import sys
import heapq
sys.setrecursionlimit(10**8)
INF = float("inf")


class MaxHeap(object):
    def __init__(self, x, default=-INF):
        self.heap = [-e for e in x]
        self.default = default
        heapq.heapify(self.heap)

    def push(self, value):
        heapq.heappush(self.heap, -value)

    def pop(self):
        if len(self.heap) == 0:
            return self.default
        else:
            return -heapq.heappop(self.heap)


def argmax(a):
    value, n = -(1 << 31), -1
    for i, v in enumerate(a):
        if value < v:
            n, value = i, v
    return n, value


def solve(X: int, Y: int, A: int, B: int, C: int, p: "List[int]", q: "List[int]", r: "List[int]"):
    ABC = [MaxHeap(p), MaxHeap(q), MaxHeap(r)]

    upper = [X, Y]

    abc = [k.pop() for k in ABC]
    xyz = [0, 0, 0]
    tot = 0
    for _ in range(X+Y):
        i, m = argmax(abc)
        tot += m
        if (i < 2 and xyz[i] < upper[i]-1) or (i == 2):
            abc[i] = ABC[i].pop()
        else:
            abc[i] = -INF
        xyz[i] += 1
    print(tot)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  
    Y = int(next(tokens))  
    A = int(next(tokens))  
    B = int(next(tokens))  
    C = int(next(tokens))  
    p = [int(next(tokens)) for _ in range(A)]  
    q = [int(next(tokens)) for _ in range(B)]  
    r = [int(next(tokens)) for _ in range(C)]  
    solve(X, Y, A, B, C, p, q, r)


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)

p = p[:X]
q = q[:Y]

SB = p + q + r
SB.sort(reverse=True)
ans = 0
for i in range(X+Y):
    ans += SB[i]
print(ans)

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)

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

print(sum(a))

Solution (Python):
from collections import deque
X,Y,A,B,C = (int(x) for x in input().split())
p = [[int(x), 'r'] for x in input().split()]
q = [[int(x), 'g'] for x in input().split()]
r = [[int(x), 'c'] for x in input().split()]
pqr = p + q + r
pqr.sort(reverse=True)
d = deque(pqr)
rem = X + Y
pickedr = 0
pickedg = 0
pickedc = 0
ans = 0
if len(d) <= rem:
    print(sum([apple[0] for apple in pqr]))
else:
    while pickedr + pickedg + pickedc < rem:
        pop = d.popleft()
        if pop[1] == 'r':
            if pickedr < X:
                ans += pop[0]
                pickedr += 1
        elif pop[1] == 'g':
            if pickedg < Y:
                ans += pop[0]
                pickedg += 1
        else:
            ans += pop[0]
            pickedc += 1
    print(ans)

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

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

p.extend(q)
p.extend(r)
p.sort()
print(sum(p[len(p)-x-y:]))

Solution (Python):
x, y, a, b, c = map(int, input().split())
pa = list(map(int, input().split()))
pb = list(map(int, input().split()))
pc = list(map(int, input().split()))
pa.sort(reverse=True)
pb.sort(reverse=True)
pc.sort(reverse=True)
N = x+y
i = ia = ib = ic = 0
psum = 0
while i < N:
    xa = pa[ia] if ia < len(pa) and ia < x else -1
    xb = pb[ib] if ib < len(pb) and ib < y else -1
    xc = pc[ic] if ic < len(pc) else -1
    if xa >= xb and xa >= xc:
        ia += 1
        psum += xa
    elif xb >= xc:
        ib += 1
        psum += xb
    else:
        ic += 1
        psum += xc
    i += 1

print(psum)

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

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
lst=[]
p_=[[p[i],1] for i in range (a)]
q_=[[q[i],2] for i in range (b)]
r_=[[r[i],3] for i in range (c)]
lst = sorted(p_+q_+r_,reverse=True)

ans = 0
count =0
for i in range (len(lst)):
    if lst[i][1]==1 and x>0:
        x = x -1
        ans = ans + lst[i][0]
    if lst[i][1]==2 and y>0:
        y = y -1
        ans = ans + lst[i][0]
    if lst[i][1]==3 and x+y>0:
        count =count+1
        ans = ans + lst[i][0]
    if count == x+y:
        break

print(ans)

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

print(ans)

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 = sorted(p)
q = sorted(q)

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

print(ans)

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

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

p.sort()
p.reverse()
q.sort()
q.reverse()

d = []

for i in range(X):
    d.append(p[i])
for i in range(Y):
    d.append(q[i])
for i in range(len(r)):
    d.append(r[i])

d.sort()
d.reverse()
result = 0
for i in range(X + Y):
    result += d[i]

print(result)

Solution (Python):
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort()
q.sort()
r.sort(reverse=True)
p = p[a-x:]
q = q[b-y:]
pi = 0
qi = 0
ri = 0
while ri < c:
    if pi == x:
        if qi == y:
            break
        else:
            if q[qi] >= r[ri]:
                break
            else:
                q[qi] = r[ri]
                qi += 1
                ri += 1
                continue
    elif qi == y:
        if p[pi] >= r[ri]:
            break
        else:
            p[pi] = r[ri]
            pi += 1
            ri += 1
            continue
    else:
        if p[pi] >= r[ri] and q[qi] >= r[ri]:
            break
        else:
            if p[pi] <= q[qi]:
                p[pi] = r[ri]
                pi += 1
                ri += 1
                continue
            else:
                q[qi] = r[ri]
                qi += 1
                ri += 1
                continue

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()
r.sort(reverse=True)
p = p[A-X:]
q = q[B-Y:]
min_p = 0
min_q = 0
j = 0

for i in range(C):
  if min_p < X and min_q < Y:
  
    if p[min_p] > r[i] and q[min_q] > r[i]:
      break
    
    if p[min_p] < q[min_q]:
      if p[min_p] <= r[i]:
        p[min_p] = r[i]
      min_p += 1
    else:
      if q[min_q] <= r[i]:
        q[min_q] = r[i]
      min_q += 1
      
  elif min_p < X:
    if p[min_p] <= r[i]:
      p[min_p] = r[i]
    min_p += 1
  elif min_q < Y:
    if q[min_q] <= r[i]:
      q[min_q] = r[i]
    min_q += 1
  else:
    break
    
print(sum(p)+sum(q))

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

sum=0
l.sort()
l1.sort()
l2.sort()
ct=1



l=l[a-x:]
l1=l1[b-y:]

l=l[:]+l1[:]



if c>=x+y:
  l2=l2[c-(x+y):]


l=l[:]+l2[:]
l.sort()


while ct<=x+y:
  sum+=l[-ct]
  ct+=1
  
print(sum)

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


r.sort(reverse = True)


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


heapq.heapify(p)
heapq.heapify(q)


for i in r:
    if p[0] <= q[0]:
        if i > p[0]:
            heapq.heappop(p)
            heapq.heappush(p,i)
    else:
        if i > q[0]:
            heapq.heappop(q)
            heapq.heappush(q,i)

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

Solution (Python):
def greenandredapples():
    X, Y, A, B, C = list(map(int, input().split()))
    RedD = sorted(list(map(int, input().split())))
    GreenD = sorted(list(map(int, input().split())))
    Colorl = sorted(list(map(int, input().split())))

    considered = RedD[-X:] + GreenD[-Y:]
    Colorl.extend(considered)
    return sum(sorted(Colorl,reverse=True)[:X+Y])

print(greenandredapples())

Solution (Python):
x, y, a,b,c =map(int,input().split())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
c_list = list(map(int,input().split()))
index_list = [0,0,0]
a_list.sort(reverse=True)
b_list.sort(reverse=True)
c_list.sort(reverse=True)

total = 0

for i in range(x+y):
    max_list = []
    try:
        if index_list[0] < x:
            max_list.append(a_list[index_list[0]])
        else:
            max_list.append(-1)
    except:
        max_list.append(-1)
    try:
        if index_list[1] < y:
            max_list.append(b_list[index_list[1]])
        else:
            max_list.append(-1)
    except:
        max_list.append(-1)
    try:
        max_list.append(c_list[index_list[2]])
    except:
        max_list.append(-1)
    max_value = max(max_list)
    max_index = max_list.index(max_value)
    total += max_value
    index_list[max_index] += 1

print(total)

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

Solution (Python):
X, Y, A, B, C = map(int, input().split())
qa = sorted(list(map(int, input().split())), reverse=True)
qb = sorted(list(map(int, input().split())), reverse=True)
qc = sorted(list(map(int, input().split())), reverse=True)
chk = []
chk.extend(qa[:X]+qb[:Y]+qc)
chk.sort(reverse=True)
print(sum(chk[:X+Y]))

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

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
l=p[:x]+q[:y]
l.sort()
ans=sum(l)
for i in l:
    if r!=[]:
        if i<r[0]:
            ans+=r[0]-i
            del r[0]
        else:
            break
    else:
        break
print(ans)

Solution (Python):
import math
import collections
X,Y,A,B,C=  list(map(int,input().split(" ")))
Ps = list(map(int,input().split(" ")))
Qs = list(map(int,input().split(" ")))
Rs = list(map(int,input().split(" ")))
Ps.sort(reverse=True)
Qs.sort(reverse=True)
Ps = Ps[:X]
Qs = Qs[:Y]
ans = sum(Ps) + sum(Qs)
Ps.reverse()
Qs.reverse()
ind_p = 0
ind_q = 0
Rs.sort(reverse=True)
Ps.extend([10 ** 10] * (C -X) )
Qs.extend([10 ** 10] * (C -Y) )


for r in Rs:
    if r > Ps[ind_p] or  r > Qs[ind_q]:
        if Ps[ind_p]  > Qs[ind_q]:
            ans -= Qs[ind_q]
            ans += r
            ind_q += 1

        else:
            ans -= Ps[ind_p]
            ans += r
            ind_p += 1
print(ans)

Solution (Python):
x,y,a,b,c = map(int,input().split())
red = list(map(int,input().split()))
green = list(map(int,input().split()))
colorless = list(map(int,input().split()))
red.sort(reverse=True)
green.sort(reverse=True)
apple = red[:x] +  green[:y] + colorless
apple.sort(reverse=True)
print(sum(apple[:x+y]))

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

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

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

class Run:
    def build(gv):
        
        gv.X, gv.Y, gv.A, gv.B, gv.C = map(int, input().split())
        gv.p = sorted(map(int, input().split()), reverse=True)
        gv.q = sorted(map(int, input().split()), reverse=True)
        gv.r = sorted(map(int, input().split()), reverse=True)

    def solve(gv):
        
        
        pCnt = 0; qCnt = 0; rCnt = 0
        ans = 0
        cntDown = gv.X + gv.Y
        
        while True:
            if cntDown <= 0: break
            cntDown -= 1
            
            
            pNow = gv.p[pCnt] if pCnt < gv.X else -1
            qNow = gv.q[qCnt] if qCnt < gv.Y else -1
            rNow = gv.r[rCnt] if rCnt < len(gv.r) else -1
            
            if rNow >= pNow and rNow >= qNow:
                ans += rNow
                rCnt += 1
            elif pNow >= qNow:
                ans += pNow
                pCnt += 1
            else:
                ans += qNow
                qCnt +=1
        
        print(ans)
            
        
if __name__ == '__main__':
    run = Run()
    run.build()
    run.solve()

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

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

if __name__ == "__main__":
    main()

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

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

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

if __name__ == "__main__":
    main()

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

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

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

    while R:
        mpq = heappop(PQ)
        mr = R.pop(0)
        if mpq >= mr:
            heappush(PQ, mpq)
            break
        heappush(PQ, mr)
    
    print(sum(PQ))
    

if __name__ == "__main__":
    main()

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

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

    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)
    PQ = P[:X] + Q[:Y]
    heapify(PQ)
    
    while C:
        mpq = heappop(PQ)
        mr = R.pop(0)
        if mpq >= mr:
            heappush(PQ, mpq)
            break
        heappush(PQ, mr)
        C -= 1
    
    print(sum(PQ))
    

if __name__ == "__main__":
    main()

Solution (Python):
def sort_num(x, y):
  list_num = []
  for i in range(y):
    list_num.append(x[i])

  return list_num

def main():
  x,y,a,b,c = (int(i) for i in input().split())
  p_list = sorted(list(map(int, input().split())),reverse=True)
  q_list = sorted(list(map(int, input().split())),reverse=True)
  r_list = sorted(list(map(int, input().split())),reverse=True)
  
  sum_list = sorted(list(sort_num(p_list, x) + sort_num(q_list, y) + r_list), reverse=True)
  sum_num = x + y
  
  print(sum(sum_list[:sum_num]))

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

apple_value = p + q + r
apple_type = [0] * A + [1] * B + [2] * C

tmp = zip(apple_value, apple_type)
tmp = sorted(tmp, reverse=True)
apple_value, apple_type = zip(*tmp)
ans = 0
type_list = [0, 0, 0]
max_list = [X, Y, 0]
green_num = 0

for a_value, a_type in zip(apple_value, apple_type):
    if sum(type_list) >= X + Y:
        break
    if type_list[a_type] < max_list[a_type] or a_type == 2:
        ans += a_value
        type_list[a_type] += 1
print(ans)

Solution (Python):



import sys
input = sys.stdin.readline

def main():
    X, Y, A, B, C = map(int, input().split())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))
    R = list(map(int, input().split()))
    P.sort(reverse = True)
    Q.sort(reverse = True)
    R.extend(P[:X])
    R.extend(Q[:Y])
    R.sort(reverse = True)

    print(sum(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)[:X+Y]

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