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

Submission status: Accepted

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

Submission status: Accepted

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

r = sorted(list(map(int, input().split())), reverse = True)
g = sorted(list(map(int, input().split())), reverse = True)
a = sorted(list(map(int, input().split())), reverse = True)

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

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

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

Submission status: Accepted

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

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

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_ind = X-1
q_ind = Y-1
r_ind = 0

while 1:

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

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

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

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


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

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

Submission status: Accepted

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

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

flag=True
while flag and c_list:
    x=heapq.heappop(c_list)
    x=x*(-1)
    #ｃ_listの中でのもっとも大きい値
    min_a=heapq.heappop(a_list)
    min_b=heapq.heappop(b_list)
    if min(min_a,min_b)>=x:
        flag=False
        heapq.heappush(a_list,min_a)
        heapq.heappush(b_list,min_b)
    else:
        if min_a>=min_b:
            heapq.heappush(a_list,min_a)
            heapq.heappush(b_list,x)
            
        elif min_a<min_b:
            heapq.heappush(b_list,min_b)
            heapq.heappush(a_list,x)

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

print(sum_a+sum_b)

Submission status: Accepted

Solution code:
from sys import stdin


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


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

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)


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

Submission status: Accepted

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

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_x = sorted(p, reverse=True)[:X]
q_y = sorted(q, reverse=True)[:Y]
r_xy = sorted(r, reverse=True)[:X+Y]

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import deque

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

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

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

print(sum(PQ))

Submission status: Accepted

Solution code:
from sys import stdin, stdout  

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

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

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

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

i=j=0

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

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)
ip = 0
iq = 0
ir = 0
ans = 0
while ip+iq+ir<x+y:
    tp = 0 if ip>=x else p[ip]
    tq = 0 if iq>=y else q[iq]
    tr = 0 if ir==c else r[ir]
    if tp >= tq and tp >= tr:
        ans += tp
        ip += 1
    elif tq >= tp and tq >= tr:
        ans += tq
        iq += 1
    else:
        ans += tr
        ir += 1
print(ans)

Submission status: Accepted

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import deque

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

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

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

while True:
    if not R or R[0] <= PQ[0]:
        break
    if R[0] > PQ[0]:
        PQ.append(R.popleft())
        PQ.popleft()

print(sum(PQ))

Submission status: Accepted

Solution code:
import heapq

X, Y, A, B, C = [int(s) for s in input().split()]
p = [(-int(s), 'r') for s in input().split()]
q = [(-int(s), 'g') for s in input().split()]
r = [(-int(s), 'n') for s in input().split()]
h = p + q + r
heapq.heapify(h)
x, y, z = 0, 0, 0
s = 0
while x + y + z < X + Y:
    d, c = heapq.heappop(h)
    if c == 'r':
        if x < X:
            x += 1
            s += -d
    if c == 'g':
        if y < Y:
            y += 1
            s += -d
    if c == 'n':
        z += 1
        s += -d
print(s)

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)

P = P[:X]
Q = Q[:Y]

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

S = []
S = P + Q + R
S.sort(reverse=True)
# print(S)
S2 = S[:X+Y]
ans = sum(S2)
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 = sorted(p)[-X:]
q = sorted(q)[-Y:]
r = sorted(r)
a = p+q+r
a.sort(reverse=1)
ans = a[:X+Y]
print(sum(ans))

Submission status: Accepted

Solution code:
# Author: cr4zjh0bp
# Created: Sat Mar 28 15:38:17 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

x, y, a, b, c = na()
p = na()
q = na()
r = na()
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

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

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

ps = sorted(p,reverse=True)
qs = sorted(q,reverse=True)
rs = sorted(r,reverse=True)

psc = ps[:x]
qsc = qs[:y]

d = []

d.extend(psc)
d.extend(qsc)
d.extend(rs)

ds = sorted(d,reverse=True)

dsc = ds[:(x+y)]

print(sum(dsc))

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

Submission status: Accepted

Solution code:
from collections import deque
def main():
    X, Y, A, B, C = map(int, input().split())
    
    apple = []
    red = sorted(map(int, input().split()), reverse=True)[:X]
    green = sorted(map(int, input().split()), reverse=True)[:Y]
    nocolor = list(map(int, input().split()))
    apple.extend(red)
    apple.extend(green)
    apple.extend(nocolor)
    
    print(sum(sorted(apple, reverse=True)[:X+Y]))      
        

if __name__ == "__main__":
    main()

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)
pq=p[:x]+q[:y]
heapq.heapify(pq)

for i in range(c):
    a=heapq.heappop(pq)
    if a<r[i]:
        heapq.heappush(pq,r[i])
    else:
        heapq.heappush(pq,a)
        break

print(sum(pq))

Submission status: Accepted

Solution code:
x,y,a,b,c = map (int ,input().split())
al = [int(x) for x in(input().split())]
bl = [int(x) for x in(input().split())]
cl = [int(x) for x in(input().split())]


al.sort()
bl.sort()

d = al[-x:]+bl[-y:]+cl
d.sort(reverse = True)
ans = 0
for i in range(x + y):
  ans += d[i]
print(ans)

Submission status: Accepted

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

p = list(map(lambda x: (int(x), 0), input().split()))
p += list(map(lambda x: (int(x), 1), input().split()))
p += list(map(lambda x: (int(x), 2), input().split()))
p = sorted(p, reverse=True)

from collections import deque
p = deque(p)
_n = x+y
ans = 0

D = [x, y ,x+y]
while _n > 0:
    _x, _y = p.popleft()
    if D[_y] == 0:
        pass
    else:
        D[_y] -= 1
        ans += _x
        _n -= 1

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_ = sorted(p)[-x:]
q_ = sorted(q)[-y:]
s = p_ + q_ + r
s_ = sorted(s)[-(x + y):]

print(sum(s_))

Submission status: Accepted

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

r = list(map(int, input().split()))
for i in range(X):
    r.append(p[A-i-1])
for i in range(Y):
    r.append(q[B-i-1])
r.sort()

print(sum(r[len(r) - X - Y:]))

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)

d = sorted(p[:x]+q[:y]+r,reverse=True)
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)
ip = 0
iq = 0
ir = 0
ans = 0
while ip+iq+ir<x+y:
    tp = 0 if ip>=x else p[ip]
    tq = 0 if iq>=y else q[iq]
    tr = 0 if ir==c else r[ir]
    if tp >= tq and tp >= tr and ip < x:
        ans += tp
        ip += 1
    elif tq >= tp and tq >= tr and iq < y:
        ans += tq
        iq += 1
    elif ir < c:
        ans += tr
        ir += 1
    elif tp > tq and ip < x:
        ans += tp
        ip += 1
    else:
        ans += tq
        iq += 1
print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	x,y,a,b,c = MI()
	p = LI()
	p.sort(reverse=True)
	q = LI()
	q.sort(reverse=True)
	r = LI()

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

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
x, y, a, b, c = map(int, input().split())
r = sorted(list(map(int, input().split())), reverse=True)[:x]
g = sorted(list(map(int, input().split())), reverse=True)[:y]
n = sorted(list(map(int, input().split())), reverse=True)
list = sorted(r+g+n, reverse=True)
ans = 0
for _ in range(x+y):
  ans += list[_]
  
print(ans)

Submission status: Accepted

Solution code:
import itertools
from itertools import zip_longest

x, y, a, b, c = map(int, input().split())
ans_list = list()
p = list()
for i in input().split():
  p.append(int(i))
q = list()
for i in input().split():
  q.append(int(i))
r = list()
for i in input().split():
  r.append(int(i))

sort_p = sorted(p, reverse=True)
sort_q = sorted(q, reverse=True)
sort_r = sorted(r, reverse=True)
sort_r_max = sort_r[:x+y]

ans_list.append(sort_p[:x])
ans_list.append(sort_q[:y])

sort_ans = sorted(list(itertools.chain.from_iterable(ans_list)))
ans = 0
for i, j in zip_longest(sort_ans, sort_r_max, fillvalue=0):
  if i < j:
    ans += j
  else:
    ans += i
print(ans)

Submission status: Accepted

Solution code:
I = lambda: sorted([int(a) for a in input().split()])[::-1]
X, Y, *_ = map(int, input().split())
print(sum(sorted(I()[:X] + I()[:Y] + I())[::-1][:X+Y]))

Submission status: Accepted

Solution code:


def main():
    X,Y,A,B,C = [int(x) for x in input().split()]
    P = sorted([int(x) for x in input().split()])[-X:]
    Q = sorted([int(x) for x in input().split()])[-Y:]
    R = sorted([int(x) for x in input().split()])

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X, Y, A, B, C = [int(s) for s in input().split()]
p_list = [int(s) for s in input().split()]
q_list = [int(s) for s in input().split()]
r_list = [int(s) for s in input().split()]

p_list = list(reversed(sorted(p_list)))
p_list = p_list[:X]
# print(X, p_list)

q_list = list(reversed(sorted(q_list)))
q_list = q_list[:Y]
# print(Y, q_list)

r_list = list(reversed(sorted(r_list)))
# print(r_list)


p_i = -1
q_i = -1
r_i = 0

while True:
    if r_i == C:
        break

    if p_i + X >= 0 and q_i + Y >= 0:
        if p_list[p_i] <= q_list[q_i]:
            if p_list[p_i] < r_list[r_i]:
                p_list[p_i] = r_list[r_i]
                p_i -= 1
                r_i += 1
            else:
                break
        elif q_list[q_i] <= p_list[p_i]:
            if q_list[q_i] < r_list[r_i]:
                q_list[q_i] = r_list[r_i]
                q_i -= 1
                r_i += 1
            else:
                break
    elif p_i + X >= 0:
        if p_list[p_i] < r_list[r_i]:
            p_list[p_i] = r_list[r_i]
            p_i -= 1
            r_i += 1
        else:
            break
    elif q_i + Y >= 0:
        if q_list[q_i] < r_list[r_i]:
            q_list[q_i] = r_list[r_i]
            q_i -= 1
            r_i += 1
        else:
            break
    else:
        break

d = 0
d += sum(p_list)
d += sum(q_list)

print(d)

Submission status: Accepted

Solution code:
def main():
    x,y,a,b,c=map(int,input().split())
    P=list(map(int,input().split()))
    P.sort(reverse=True)
    Q=list(map(int,input().split()))
    Q.sort(reverse=True)
    R=list(map(int,input().split()))
    A=P[:x]+Q[:y]+R
    A.sort(reverse=True)
    print(sum(A[:x+y]))
    
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
X,Y,A,B,C=map(int,input().split())
R=sorted(list(map(int,input().split())),reverse=True)
G=sorted(list(map(int,input().split())),reverse=True)
RG=sorted(list(map(int,input().split())),reverse=True)


d=R[:X]+G[:Y]+RG
d.sort(reverse=True)
 
print(sum(d[:X+Y]))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

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

p=deque(list(reversed(sorted(limii(),reverse=True)[:x])))
q=deque(list(reversed(sorted(limii(),reverse=True)[:y])))
r=deque(sorted(limii(),reverse=True))
pp=p.popleft()
qq=q.popleft()
rr=r.popleft()
for i in range(c):
    if pp>qq:
        if qq<rr:
            q.append(rr)
            if i!=c-1:
                rr=r.popleft()
            qq=q.popleft()
    else:
        if pp<rr:
            p.append(rr)
            if i!=c-1:
                rr=r.popleft()
            pp=p.popleft()
p.append(pp)
q.append(qq)
print(sum(list(p))+sum(list(q)))

Submission status: Accepted

Solution code:
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

if __name__ == '__main__':
    x, y, a, b, c = map(int, input().split())
    p = [int(i) for i in input().split()]
    q = [int(i) for i in input().split()]
    r = [int(i) for i in input().split()]
    p.sort(reverse=True)
    q.sort(reverse=True)
    r.sort(reverse=True)
    ansList = []
    ansList.extend(p[:x])
    ansList.extend(q[:y])
    ansList.extend(r)
    ansList.sort(reverse=True)
    ansList = ansList[:x+y]
    sum = 0
    for i in ansList:
        sum +=i
    print(sum)

Submission status: Accepted

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


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)

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

    all = p + q + r

    all.sort(reverse=True)
    all = all[:X+Y]

    res = sum(all)

    print(res)



main()

Submission status: Accepted

Solution code:
import sys
x, y, a, b, c = map(int, sys.stdin.readline().split())
p = map(int, sys.stdin.readline().split())
q = map(int, sys.stdin.readline().split())
r = map(int, sys.stdin.readline().split())

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

Submission status: Accepted

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

s = []
p.sort(reverse=True)
p = p[:x]

q.sort(reverse=True)
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=sorted(list(map(int,input().split())))
Q=sorted(list(map(int,input().split())))
R=sorted(list(map(int,input().split())))
print(sum(sorted(P[-X:]+Q[-Y:]+R)[-X-Y:]))

Submission status: Accepted

Solution code:
#E
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()
r.sort()
r.reverse()
# print(p, q, r)
p = p[:x]
q = q[:y]
# print(p, q)
p.extend(q)
p.extend(r)
p.sort()
p.reverse()
# print(p[:(x + y)])
print(sum(p[:(x + y)]))

Submission status: Accepted

Solution code:
x, y, r, g, c = map(int, input().split())
r_d = list(map(int, input().split()))
g_d = list(map(int, input().split()))
c_d = list(map(int, input().split()))
r_d.sort(reverse=True)
g_d.sort(reverse=True)
c_d.sort(reverse=True)
a = r_d[:x]+g_d[:y]+c_d
a.sort(reverse=True)
print(sum(a[:x+y]))

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)
q = sorted([int(i) for i in input().split()], reverse=True)
r = sorted([int(i) for i in input().split()], reverse=True)
p = p[:x]
q = q[:y]
apple = sorted(p + q + r, reverse=True)
print(sum(apple[:x+y]))

Submission status: Accepted

Solution code:
import sys
#input = sys.stdin.readline
#sys.setrecursionlimit(10**6)

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)

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

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



    print(sum(all))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X,Y,A,B,C = [int(x) for x in input().split()]
R = sorted([int(x) for x in input().split()],reverse = True)[:X]
G = sorted([int(x) for x in input().split()],reverse = True)[:Y]
CL = sorted([int(x) for x in input().split()],reverse = True)[:X+Y]
total = sorted(R+G+CL, reverse=True)[:X+Y]
print(sum(total))

Submission status: Accepted

Solution code:
X,Y,A,B,C = map(int, input().split())
ps = sorted(map(int,input().split()),reverse=True)[:X]
qs = sorted(map(int,input().split()),reverse=True)[:Y]
rs = list(map(int,input().split()))
print(sum(sorted(ps+qs+rs, reverse=True)[:X+Y]))

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    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()))
    pp = sorted(p, reverse=True)[0:X]
    qq = sorted(q, reverse=True)[0:Y]
    ppqqr = list(sorted(pp+qq+r, reverse=True))

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

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
from collections import deque
x,y,a,b,c=map(int, input().split())
pi=list(map(int,input().split()))
qi=list(map(int,input().split()))
ri=list(map(int,input().split()))
pi.sort(reverse=True)
qi.sort(reverse=True)

apple=pi[:x]+qi[:y]+ri
apple.sort(reverse=True)

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

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)
box=[]
ans=0
for i in range(x):
    heapq.heappush(box,p[i]*(-1))
for i in range(y):
    heapq.heappush(box,q[i]*(-1))
for i in range(c):
    heapq.heappush(box,r[i]*(-1))
for _ in range(x+y):
    ans+=heapq.heappop(box)
print(-1*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 = r + p[:x] + q[:y]
r.sort(reverse=True)
#print(r[:x+y])
print(sum(r[:x+y]))

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
def e_red_and_green_apples():
    from bisect import bisect_right
    X, Y, A, B, C = [int(i) for i in input().split()]
    P = sorted([int(i) for i in input().split()], reverse=True)
    Q = sorted([int(i) for i in input().split()], reverse=True)
    R = sorted([int(i) for i in input().split()], reverse=True)

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

print(e_red_and_green_apples())

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

red.sort(reverse = True)
red = red[:x]
green.sort(reverse = True)
green = green[:y]

apples = red + green + clear
apples.sort(reverse = True)
apples = apples[:x+y]

print(sum(apples))