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



Sample input:
1 2 2 2 1
2 4
5 1
3


Sample output:
12

Submission status: Accepted

Solution code:
import sys
from heapq import heapify, heappushpop

read = sys.stdin.read
readline = sys.stdin.readline

X, Y, A, B, C = map(int, readline().split())
p = list(map(int, readline().split()))
q = list(map(int, readline().split()))
r = [0] + list(map(int, readline().split()))
p.sort()
q.sort()
r.sort()
heap_p = p[-X:]
heap_q = q[-Y:]
'''
heapify(heap_q)
heapify(heap_p)
while r[-1] > heap_p[0] or r[-1] > heap_q[0]:
    if heap_q[0] < heap_p[0]:
        heappushpop(heap_q, r.pop())
    else:
        heappushpop(heap_p, r.pop())

print(sum(heap_p) + sum(heap_q))
'''
a = heap_p + heap_q + r
a.sort()
print(sum(a[-(X + Y):]))

Submission status: Accepted

Solution code:
import sys
from heapq import heapify, heappushpop

read = sys.stdin.read
readline = sys.stdin.readline

X, Y, A, B, C = map(int, readline().split())
p = list(map(int, readline().split()))
q = list(map(int, readline().split()))
r = [0] + list(map(int, readline().split()))
p.sort()
q.sort()
r.sort()
heap_p = p[-X:]
heap_q = q[-Y:]
heapify(heap_q)
heapify(heap_p)
while r[-1] > heap_p[0] or r[-1] > heap_q[0]:
    if heap_q[0] < heap_p[0]:
        heappushpop(heap_q, r.pop())
    else:
        heappushpop(heap_p, r.pop())

print(sum(heap_p) + sum(heap_q))

Submission status: Accepted

Solution code:
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()))

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

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

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

Submission status: Accepted

Solution code:
X,Y,A,B,C=map(int, input().split())
AA=list(map(int, input().split()))
BB=list(map(int, input().split()))
CC=list(map(int, input().split()))
AA=sorted(AA,reverse=True)
BB=sorted(BB,reverse=True)
CC=sorted(CC,reverse=True)
XX=sorted(AA[0:X]+BB[0:Y]+CC,reverse=True)
XX=XX[0:X+Y]
print(sum(XX))

Submission status: Accepted

Solution code:
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 = sorted(p, reverse=True)
q_sort = sorted(q, reverse=True)
r_sort = sorted(r, reverse=True)

del p_sort[X:]
del q_sort[Y:]

total_list = p_sort + q_sort + r_sort
total_list_sort = sorted(total_list, reverse=True)
del total_list_sort[(X+Y):]
print(sum(total_list_sort))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
x,y,a,b,c=map(int,input().split())
red=sorted(list(map(int,input().split())),reverse=True)
green=sorted(list(map(int,input().split())),reverse=True)
white=sorted(list(map(int,input().split())),reverse=True)
eat_list=sorted(red[:x]+green[:y])
for i in range(min(len(eat_list),len(white))):
  if eat_list[i]<white[i]:
    eat_list[i]=white[i]
  else:
    break
print(sum(eat_list))

Submission status: Accepted

Solution code:
x,y,a,b,c=(int(i) for i in input().split())
p=sorted([int(i) for i in input().split()])
q=sorted([int(i) for i in input().split()])
r=sorted([int(i) for i in input().split()])
l=sorted(p[a-x:]+q[b-y:]+r)
n=len(l)
print(sum(l[n-x-y:]))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
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[0:X]
q = q[0:Y]

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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=[]
for i in range(a):
    apples.append([p[i],0])
for i in range(b):
    apples.append([q[i],1])
for i in range(c):
    apples.append([r[i],2])

apples.sort(reverse=True)

mx_cnt=[x,y,float('inf')]
cnt=[0,0,0]
ans=0
for app in apples:
    deli=app[0]
    clr = app[1]

    if cnt[clr] < mx_cnt[clr]:
        ans+=deli
        cnt[clr]+=1

    if sum(cnt)>=x+y:
        break
print(ans)

Submission status: Accepted

Solution code:
L=lambda:map(int,input().split())
x,y,a,b,c=L()
*p,=L()
*q,=L()
*r,=L()
print(sum(sorted(sorted(p,reverse=1)[:x]+sorted(q,reverse=1)[:y]+r,reverse=1)[:x+y]))

Submission status: Accepted

Solution code:
import heapq
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 = sorted(list(map(lambda x:int(x),input().split())),reverse=True)

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

for i in range(min(len(r),len(p))):
    p[i] = max(p[i],r[i])
print(sum(p))

Submission status: Accepted

Solution code:
def resolve():
    X, Y, A, B, C = map(int,input().split())
    P = sorted(tuple(map(int, input().split())), reverse=True)
    Q = sorted(tuple(map(int, input().split())), reverse=True)
    R = sorted(tuple(map(int, input().split())), reverse=True)

    NP = P[0:X]
    NQ = Q[0:Y]

    NP.extend(NQ)
    NP.extend(R)

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

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    X,Y,A,B,C=MI()
    p=LI()
    q=LI()
    r=LI()
    p.sort(reverse=True)
    q.sort(reverse=True)
    r.sort(reverse=True)
    sp=sum(p[:X])
    sq=sum(q[:Y])
    np=X-1
    nq=Y-1
    nr=0
    p.append(10**10)
    q.append(10**10)
    r.append(-1)
    
    
    while True:
        pp=p[np]
        qq=q[nq]
        rr=r[nr]
        if rr>pp and rr>qq:
            if pp>qq:
                sq=sq-qq+rr
                nr+=1
                nq-=1
            else:
                sp=sp-pp+rr
                nr+=1
                np-=1
        elif rr>pp:
            sp=sp-pp+rr
            nr+=1
            np-=1
        elif rr>qq:
            sq=sq-qq+rr
            nr+=1
            nq-=1
        else:
            break
        
    print(sp+sq)
            
            
    
    
    

main()

Submission status: Accepted

Solution code:
from collections import deque
x,y,a,b,c = map(int,input().split())
red = [int(i) for i in input().split()]
g = [int(i) for i in input().split()]
w = [int(i) for i in input().split()]
red.sort(reverse=True)
g.sort(reverse=True)
g = g[:y]
gw = g+w
gw.sort(reverse=True)
gwrui = []
rui = 0
for i in range(y+c):
    rui += gw[i]
    gwrui.append(rui)
red = red[:x]
rrui = []
rui = 0
for i in range(x):
    rui += red[i]
    rrui.append(rui)
rrui = [0] + rrui
ans = 0
oisr = 0
lgw = len(gw)
#print(red,gw,gwrui)
for i in range(0,x+1):
    temp = rrui[i]
    if x+y-i <= lgw:
        temp += gwrui[x+y-i-1]
        ans = max(ans,temp)
print(ans)

Submission status: Accepted

Solution code:
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 i in range(Y):
    ans.append(q[i])

for i in range(C):
    ans.append(r[i])

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

Submission status: Accepted

Solution code:
x,y,a,b,c=map(int,input().split())
p=[int(i) for i in input().split()]
q=[int(j) for j in input().split()]
r=[int(k) for k in input().split()]
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p=p[:x]
q=q[:y]
s=p+q+r
s.sort(reverse=True)
s=s[:x+y]
print(sum(s))

Submission status: Accepted

Solution code:
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.reverse()
q.reverse()
r.reverse()

ret = 0
z = 0

pidx=0
qidx=0
ridx=0

plen=len(p)
qlen=len(q)
rlen=len(r)
while(x + y > z):
    pattern = 0
    apple = 0
    if x > 0 and pidx < plen:
        apple = p[pidx]
        pattern = 1
    if y > 0 and qidx < qlen:
        if apple < q[qidx]:
            apple = q[qidx]
            pattern = 2
    if ridx < rlen and apple < r[ridx]:
        apple = r[ridx]
        pattern = 3
    ret += apple
    if pattern == 1:
        x -= 1
        pidx += 1
    elif pattern == 2:
        y -= 1
        qidx  += 1
    elif pattern == 3:
        z += 1
        ridx += 1

print(ret)

Submission status: Accepted

Solution code:
x,y,a,b,c=map(int,input().split())
p=[int(i) for i in input().split()]
q=[int(i) for i in input().split()]
r=[int(i) for i in input().split()]
p.sort()
q.sort()
p=p[-x:]
q=q[-y:]
s=p+q+r
s.sort()
print(sum(s[-x-y:]))

Submission status: Accepted

Solution code:
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, Y, A, B, C = 1, 2, 2, 2, 1
# p = [2, 4]
# q = [5, 1]
# r = [3]

p.sort()
q.sort()
r.sort()
p = p[-X:]
q = q[-Y:]

d = []
d += p
d += q
d += r
d.sort()

print(sum(d[-X-Y:]))

Submission status: Accepted

Solution code:
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)
ALL = P[0:X]+Q[0:Y]+R
ALL.sort(reverse=True)
print(sum(ALL[0:X+Y]))

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.buffer.readline
    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(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()

Submission status: Accepted

Solution code:
x,y,a,b,c=map(int,input().split())
p=sorted([int(i) for i in input().split()],reverse=True)[:x]
q=sorted([int(i) for i in input().split()],reverse=True)[:y]
r=sorted([int(i) for i in input().split()],reverse=True)
pq=sorted(p+q)
for i in range(min(x+y,a+b,c)):
    if pq[i]<r[i]:
        pq[i]=r[i]
print(sum(pq))

Submission status: Accepted

Solution code:
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()))

pX = sorted(p, reverse=True)[:X]
qY = sorted(q, reverse=True)[:Y]

D = pX + qY + r

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X,Y,A,B,C = map(int,input().split())
r_l = list(map(int,input().split()))
b_l = list(map(int,input().split()))
n_l = list(map(int,input().split()))

r_l.sort(reverse=True)
b_l.sort(reverse=True)

a_l = r_l[:X] + b_l[:Y] + n_l
a_l.sort(reverse=True)
print(sum(a_l[:X+Y]))

Submission status: Accepted

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


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

print(sum(taberu[0:X+Y]))

Submission status: Accepted

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

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

print(sum(taberu[0:X+Y]))

Submission status: Accepted

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

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

print (sum(z))

Submission status: Accepted

Solution code:
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)
colorless.sort(reverse=True)

red = red[:x]
green = green[:y]

l = red + green + colorless
l.sort(reverse=True)
ans = sum(l[:x + y])
print(ans)

Submission status: Accepted

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


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

print(sum(taberu[0:X+Y]))

Submission status: Accepted

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

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

print(sum(taberu[0:X+Y]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

def mergef(a,b):
    c = []
    h = j = 0
    while j<len(a) and h<len(b):
        if a[j]>b[h]:
            c.append(a[j])
            j+=1
        else:
            c.append(b[h])
            h+=1
    if j==len(a):
        for i in b[h:]:
            c.append(i)
    else:
        for i in a[j:]:
            c.append(i)
    return c

def merge_sortf(lists):
    if len(lists) <= 1:
        return lists
    middle = int(len(lists)/2)
    left = merge_sortf(lists[:middle])
    right = merge_sortf(lists[middle:])
    return mergef(left,right)


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

pm=merge_sortf(p)
qm=merge_sortf(q)
rm=merge_sortf(r)

k=0;i=X-1;j=Y-1
while i>=0 and j>=0 and k<C:
    if min((pm[i]-rm[k]),(qm[j]-rm[k])) < 0 :
        if pm[i]>=qm[j] :
            qm[j]=rm[k]
            if j>0:
                j=j-1
        elif pm[i]<qm[j]:
            pm[i]=rm[k]
            if i>0:
                i=i-1
    elif min((pm[i]-rm[k]),(qm[j]-rm[k])) > 0:
        break
    k=k+1

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

Submission status: Accepted

Solution code:
# coding: utf-8

x, y, a, b, c = map(int,input().split())
L = []
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)

ca = 0
cb = 0
cc = 0
flg1 = True
flg2 = True
flg3 = True
ans = 0
for i in range(x+y):
    if ca == x:
        flg1 = False
        ca = 0
        Pa[ca] = 0
    if cb == y:
        flg2 = False
        cb = 0
        Pb[cb] = 0
    if cc == c:
        flg3 = False
        cc = 0
        Pc[cc] = 0
    if Pa[ca] == max(Pa[ca], Pb[cb], Pc[cc]) and flg1:
        ans += Pa[ca]
        ca += 1
    elif Pb[cb] == max(Pa[ca], Pb[cb], Pc[cc]) and flg2:
        ans += Pb[cb]
        cb += 1
    elif Pc[cc] == max(Pa[ca], Pb[cb], Pc[cc]) and flg3:
        ans += Pc[cc]
        cc += 1
        #print("###")

print(ans)

Submission status: Accepted

Solution code:
x,y,a,b,c = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
ans = []
for i in range(x):
    ans.append(A[i])
for i in range(y):
    ans.append(B[i])
for i in range(c):
    ans.append(C[i])
ans.sort(reverse=True)
anss = 0
for i in range(x+y):
    anss += ans[i]
print(anss)

Submission status: Accepted

Solution code:
# Problem E - Red and Green Apples

from collections import deque

# input
X, Y, A, B, C = map(int, input().split())
red_apples = sorted(list(map(int, input().split())), reverse=True)
green_apples = sorted(list(map(int, input().split())), reverse=True)
mushoku_apples = list(map(int, input().split()))

# initialization
red_apples = red_apples[:X]
green_apples = green_apples[:Y]
ans_list = deque([])

# sort
for r in red_apples:
    ans_list.append(r)
for g in green_apples:
    ans_list.append(g)
for m in mushoku_apples:
    ans_list.append(m)
ans_list = sorted(ans_list, reverse=True)

# output
ans = sum(ans_list[:X+Y])
print(ans)

Submission status: Accepted

Solution code:
import heapq
x,y,a,b,c=map(int,input().split())
def _int(x):
    return -int(x)
p=list(map(_int,input().split()))
q=list(map(_int,input().split()))
r=list(map(_int,input().split()))
heapq.heapify(p)
heapq.heapify(q)
heapq.heapify(r)

ans=[]
heapq.heapify(ans)
for i in range(x):
    _p=heapq.heappop(p)
    heapq.heappush(ans,-_p)
for i in range(y):
    _q=heapq.heappop(q)
    heapq.heappush(ans,-_q)
#ansは小さい順、rは大きい順
for i in range(x+y):
    if len(r)==0:break
    _ans=heapq.heappop(ans)
    _r=-heapq.heappop(r)
    if _r>=_ans:
        heapq.heappush(ans,_r)
    else:
        heapq.heappush(ans,_ans)
        break
print(sum(ans))

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


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


x, y, a, b, c = map(int, input().split())
P = sorted(list(map(int, input().split())), reverse=True)[:x]
Q = sorted(list(map(int, input().split())), reverse=True)[:y]
R = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
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[:X]+Q[:Y]+R
s.sort(reverse=True)
        
print(sum(s[:X+Y]))

Submission status: Accepted

Solution code:
import sys
import numpy as np

from collections import deque 
from functools import reduce

# input = sys.stdin.readline

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

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

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

p_np = np.zeros(999999)
q_np = np.zeros(999999)

if len(p) > x:
    p_np[:x] = p[:x]
else:
    l_p = len(p)
    p_np[:l_p] = p[:]

if len(q) > y:
    q_np[:y] = q[:y]
else:
    l_q = len(q)
    q_np[:l_q] = q[:]
ap_np = np.hstack((p_np[:x], q_np[:y]))
ap_np.sort()
ap_cnt = 0

for i, ri in enumerate(r):
    if i >= x + y:
        break
    if (r[i] > ap_np[i]):
        ap_np[i] = r[i]
print(int(ap_np.sum()))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import heapq
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 = sorted(list(map(lambda x:int(x),input().split())),reverse=True)

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

for i in range(min(len(r),len(p))):
    p[i] = max(p[i],r[i])
print(sum(p))

Submission status: Accepted

Solution code:
x, y, a, b, c = map(int, input().split())
red = [int(x) for x in input().split()]
green = [int(x) for x in input().split()]
red.sort()
green.sort()
candidates = [int(x) for x in input().split()] + red[-x:] + green[-y:]
candidates.sort()
print(sum(candidates[-x-y:]))

Submission status: Accepted

Solution code:
x, y, a, b, c = map(int, input().split())
red = sorted(int(x) for x in input().split())[-x:]
green = sorted(int(x) for x in input().split())[-y:]
print(sum(sorted([int(x) for x in input().split()] + red + green)[-(x+y):]))

Submission status: Accepted

Solution code:
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)
c_apple = p[0:x] + q[0:y]
c_apple.sort()
for i in range(len(r)):
    if c_apple[i] < r[i]:
        c_apple[i] = r[i]
    else:
        break
print(sum(c_apple))

Submission status: Accepted

Solution code:
X,Y,A,B,C = map(int,input().split())
p = input().split()
q = input().split()
r = input().split()
p = [int(val) for val in p]
q = [int(val) for val in q]
r = [int(val) for val in r]
p.sort()
q.sort()
p_candidate = p[len(p)-X::]
q_candidate = q[len(q)-Y::]
candidate = []
candidate.extend(p_candidate)
candidate.extend(q_candidate)
candidate.extend(r)
candidate.sort()
print(sum(candidate[len(candidate)-X-Y::]))

Submission status: Accepted

Solution code:
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
setrecursionlimit(1000000)

# INF = float('inf')
INF = int(1e10)

def input():
    return stdin.readline()[:-1]

def main():
    from builtins import int, map
    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 = 0
    v = p[:X] + q[:Y]
    v.sort()
    w = 0
    for i in range(min(X + Y, C)):
        if v[i] < r[w]:
            v[i] = r[w]
            w += 1
    print(sum(v))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# Problem E - Red and Green Apples

from collections import deque

# input
X, Y, A, B, C = map(int, input().split())
red_apples = sorted(list(map(int, input().split())), reverse=True)
green_apples = sorted(list(map(int, input().split())), reverse=True)
mushoku_apples = sorted(list(map(int, input().split())), reverse=True)

# initialization
red_apples = red_apples[:X]
green_apples = green_apples[:Y]
ans_list = deque([])
for r in red_apples:
    ans_list.append(r)
for g in green_apples:
    ans_list.append(g)
for m in mushoku_apples:
    ans_list.append(m)
ans_list = sorted(ans_list, reverse=True)

# output
i = X+Y
ans = sum(ans_list[:i])
print(ans)

Submission status: Accepted

Solution code:
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)
res = P[:x] + Q[:y]
heapq.heapify(res)

for i in range(c):
    tmp_min = heapq.heappop(res)
    tmp_r = R[i]
    if tmp_r > tmp_min:
        heapq.heappush(res, tmp_r)
    else:
        heapq.heappush(res, tmp_min)
print(sum(res))

Submission status: Accepted

Solution code:
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()))
ps = sorted(p,reverse=True)[:X]
qs = sorted(q,reverse=True)[:Y]
r.extend(ps)
r.extend(qs)
rs = sorted(r,reverse=True)
deli = 0
for i in range(0,X+Y):
    deli = deli + rs[i]
print(deli)

Submission status: Accepted

Solution code:
x,y,a,b,c = map(int,input().split())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))

A = A[::-1][:x]
B = B[::-1][:y]
C = C[::-1]
D = A+B+C
D.sort(reverse = True)
print(sum(D[:x+y]))

Submission status: Accepted

Solution code:
import sys
#from collections import deque
input = sys.stdin.buffer.readline

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

Submission status: Accepted

Solution code:
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[:x+y]
ans.sort(reverse=True)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()))
apple = []
p_array.sort()
q_array.sort()
for _ in range(x):
    apple.append((p_array.pop(), 1))
for _ in range(y):
    apple.append((q_array.pop(), 2))
for r in r_array:
    apple.append((r, 0))
apple.sort()
print(sum(map(lambda z: z[0], apple[-(x + y):])))

Submission status: Accepted

Solution code:
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
p = p[A-X:]
q = list(map(int, input().split()))
q.sort()
q = q[B-Y:]
r = list(map(int, input().split()))
apple = p+q+r
apple.sort()
print(sum(apple[len(apple)-X-Y:]))

Submission status: Accepted

Solution code:



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

Submission status: Accepted

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

    red = list(map(int, input().split()))
    red.sort(reverse=True)

    green = list(map(int, input().split()))
    green.sort(reverse=True)

    colorless = list(map(int, input().split()))
    colorless.sort(reverse=True)

    chosen = red[:X] + green[:Y]
    chosen.sort(reverse=True)

    colorless_idx = 0
    for i in range(X+Y-1, -1, -1):
        if chosen[i] < colorless[colorless_idx]:
            chosen[i] = colorless[colorless_idx]
            colorless_idx += 1
        if colorless_idx == C:
            break
        
    print(sum(chosen))



if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys,math,copy,queue,itertools
from fractions import gcd
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
INF = 10**18
MOD = 10**9 + 7
DD = ((1,0),(0,1),(-1,0),(0,-1))
X,Y,A,B,C = LI()
p = sorted(LI(),reverse=True)[:X]
q = sorted(LI(),reverse=True)[:Y]
r = sorted(LI(),reverse=True)[:X+Y]

pq = sorted(p + q)
ans = sum(pq)

for i in range(len(r)):
    if pq[i] < r[i]:
        ans += r[i] - pq[i]
    else:
        break

print (ans)

Submission status: Accepted

Solution code:
X,Y,A,B,C=map(int,input().split())
a=sorted(list(map(int,input().split())),reverse=True)
b=sorted(list(map(int,input().split())),reverse=True)
c=sorted(list(map(int,input().split())))
ans=sum(sorted(a[0:X]+b[0:Y]+c,reverse=True)[0:(X+Y)])
print(ans)