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

Submission status: Accepted

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

A_list.sort(reverse=True)
B_list.sort(reverse=True)
C_list.sort(reverse=True)

A_list = A_list[:X]
B_list = B_list[:Y]

all_list = []
all_list.extend(A_list)
all_list.extend(B_list)
all_list.extend(C_list)

all_list.sort(reverse=True)

res = 0
for i in range(X+Y):
    res += all_list[i]

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)

L = P[0: X] + Q[0 : Y]
L.sort(reverse = True)

# replace するリンゴの数に関する二分探索
# リンゴを n 個 replace するとすると，
# (L の下から数えて n 番目の値) < (R の上から数えて n 番目の値)
# が成り立つ最大の n を求めたい

def f(n):
    if n == 0: return True
    return L[-n] < R[n - 1]

ok = 0
ng = min(X + Y, C) + 1
mid = (ok + ng) // 2

while ng - ok > 1:
    mid = (ok + ng) // 2
    # print("ok, ng, mid", end = "")
    # print(ok, ng, mid)
    if f(mid):
        ok = mid
    else:
        ng = mid

n = ok
# print(n)
# print(*L)

ans = sum(L[0 : X + Y - n])
if n > 0:
    ans += sum(R[0 : n])

print(ans)

Submission status: Accepted

Solution code:
i=lambda:list(map(int,input().split()));s=lambda k,l:sorted(k)[-l:];x,y,*a=i();print(sum(s(s(i(),x)+s(i(),y)+i(),x+y)))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import heapq
n = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

a=0
m=0
s=0
ans = 0
A = heapq.nlargest(n[0] , A)
B = heapq.nlargest(n[1] , B)
len = len(C)
if len <(n[0]+n[1]):
    C = heapq.nlargest(len,C)
else:
    C = heapq.nlargest(n[0]+n[1] , C)
for i in range(n[0]+n[1]):
    if s == len:
        if a==n[0] and m<n[1]:
            saidai = B[m]
            m +=1
        else:
            saidai = max([ A[a],B[m] ])
            if A[a] >=B[m]:
                a +=1
            else:
                m +=1

    else:
        if a==n[0] and m<n[1]:
            saidai = max([ B[m],C[s] ])

            if C[s] >= B[m]:
                s +=1
            else:
                m +=1
        elif a<n[0] and m == n[1]:
            saidai = max([ A[a],C[s] ])

            if C[s] >= A[a]:
                s +=1
            else:
                a +=1

        else:
            saidai=max([ A[a],B[m],C[s] ])

            if A[a] >= B[m] and A[a] > C[s]:
                a +=1
            elif A[a] < B[m] and B[m] > C[s]:
                m +=1
            elif C[s] >= B[m] and A[a] <= C[s]:
                s +=1
    
    ans = ans + saidai

print(ans)

Submission status: Accepted

Solution code:
lst = input().split()
X = int(lst[0])
Y = int(lst[1])
A = int(lst[2])
B = int(lst[3])
C = int(lst[4])

p_list = [int(num) for num in input().split(" ")]
q_list = [int(num) for num in input().split(" ")]
r_list = [int(num) for num in input().split(" ")]

sort_p = sorted(p_list,reverse = True)[:X]
sort_q = sorted(q_list,reverse = True)[:Y]
sort_r = sorted(r_list,reverse = True)[:X+Y]

max_score = 0
sort_p.extend(sort_q)
sort_p.extend(sort_r)
sort_p.sort(reverse = True)
for i in range(X+Y):
    max_score += sort_p[i]

print(max_score)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
x, y, a, b, c = map(int, input().split())
P = [0]*x + [int(p) for p in input().split()]
Q = [0]*y + [int(q) for q in input().split()]
R = [int(r) for r in input().split()]

P.sort()
Q.sort()
R.sort(reverse=True)
Px = P[a:]
Qy = Q[b:]
R = R[:x+y]
pc, qc = 0, 0
pqpq = [Px, Qy]
pqc = [pc, qc]
pqctop=[x, y]
for r in R:
    if pqc[0] == x:
        pq = 1
    elif pqc[1] == y:
        pq = 0
    else:
        if Px[pqc[0]]<Qy[pqc[1]]:
            pq = 0
        else:
            pq = 1
    if pqpq[pq][pqc[pq]] < r:
        pqpq[pq][pqc[pq]] = r
        pqc[pq]+= 1
    else:
        break

print(sum(Px)+sum(Qy))

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()
ans = sum(p[:X]) + sum(q[:Y])
flg = 1
lp, lq, lr = X - 1, Y - 1, C - 1
while flg == 1:
    if lr < 0 or (lp < 0 and lq < 0):
        break
    elif lq < 0 or p[lp] < q[lq]:
        if r[lr] > p[lp]:
            ans += r[lr] - p[lp]
            lr -= 1
            lp -= 1
        else: flg = 0
    elif lp < 0 or p[lp] >= q[lq]:
        if r[lr] > q[lq]:
            ans += r[lr] - q[lq]
            lr -= 1
            lq -= 1
        else: flg = 0
    else:
        flg = 0
print(ans)

Submission status: Accepted

Solution code:
xyabc = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

max_p = sorted(p, reverse=True)[:xyabc[0]]
max_q = sorted(q, reverse=True)[:xyabc[1]]
if len(r) > xyabc[0] + xyabc[1]:
    max_r = sorted(r, reverse=True)[:xyabc[0] + xyabc[1]]
else: 
    max_r = sorted(r, reverse=True)
apple_list = sorted(max_p + max_q + max_r, reverse=True)[:xyabc[0] + xyabc[1]]
print(sum(apple_list))

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)

eat_p = p[:X]
eat_q = q[:Y]
eat = sorted(eat_p + eat_q)

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

print(sum(eat))

Submission status: Accepted

Solution code:
x, y, a, b, c = map(int, 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)

p_count = 0
q_count = 0
r_count = 0
total = 0
for i in range(0, x + y):
  score_max = 0
  flag = 0
  if p_count < x:
    score = p_list[p_count]
    if score_max < score:
      score_max = score
      flag = 1
  if q_count < y:
    score = q_list[q_count]
    if score_max < score:
      score_max = score
      flag = 2
  if r_count < c:
    score = r_list[r_count]
    if score_max < score:
      score_max = score
      flag = 3
  if flag == 1:
    p_count += 1
  elif flag == 2:
    q_count += 1
  else:
    r_count += 1
  total += score_max
  
print(total)

Submission status: Accepted

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

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

R2 = R[:X]
G2 = G[:Y]

W = sorted(R2 + G2 + N, reverse=True)

print(sum(W[0: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)
if x+y <= c:
    res = sorted(p[:x]+q[:y]+r[:x+y],reverse = True)
else:
    res = sorted(p[:x]+q[:y]+r[:c],reverse = True)
print(sum(res[:x+y]))

Submission status: Accepted

Solution code:
x, y, r, g, n = map(int, input().split())
rt = list(map(int, input().split()))
rt.sort(reverse=True)
rt = rt[:x]
gt = list(map(int, input().split()))
gt.sort(reverse=True)
gt = gt[:y]
nt = list(map(int, input().split()))
nt.sort(reverse=True)
rt.extend(gt)
rt.extend(nt)
rt.sort(reverse=True)
rt = rt[:x+y]
print(sum(rt))

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

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

r = 0
for i in range(x+y):
  r += l[i]
print(r)

Submission status: Accepted

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

red = sorted(list(map(int, input().split())), reverse=True)
gre = sorted(list(map(int, input().split())), reverse=True)
non = sorted(list(map(int, input().split())), reverse=True)

red = red[0:x]
gre = gre[0:y]

eat = red + gre + non

eat.sort(reverse=True)

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

Submission status: Accepted

Solution code:
def Main(X, Y, A, B, C, p, q, r):
    p.sort()
    q.sort()
    r.sort()
    ans = 0
    p = p[-X:]
    q = q[-Y:]
    wa = X+Y
    for i in range(wa):
        if(len(r) and len(p) and len(q)):
            if p[-1] < r[-1] and q[-1] < r[-1]:
                ans += r.pop()
            elif p[-1] < q[-1]:
                ans += q.pop()
            else:
                ans += p.pop()
        elif(len(r) == 0 and len(p) and len(q)):
            if p[-1] < q[-1]:
                ans += q.pop()
            else:
                ans += p.pop()
        elif(len(r) and len(p)==0 and len(q)):
            if q[-1] < r[-1]:
                ans += r.pop()
            else:
                ans += q.pop()
        elif(len(r) and len(p) and len(q)==0):
            if p[-1] < r[-1]:
                ans += r.pop()
            else:
                ans += p.pop()
        elif(len(r)==0 and len(p)==0 and len(q)):
            ans += q.pop()
        elif(len(r)==0 and len(p) and len(q)==0):
            ans += p.pop()
        elif(len(r) and len(p)==0 and len(q)==0):
            ans += r.pop()
    return ans
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()))
    print(Main(X, Y, A, B, C, p, q, r))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(X: int, Y: int, A: int, B: int, C: int, p: "List[int]", q: "List[int]", r: "List[int]"):
    pp = sorted(p, reverse=True)[:X]
    qq = sorted(q, reverse=True)[:Y]
    apples = sorted(pp + qq)
    rr = sorted(r, reverse=True)
    for i, v in enumerate(apples):
        if len(rr) > i and rr[i] > v:
            apples[i] = rr[i]
        else:
            break
    print(sum(apples))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(A)]  # type: "List[int]"
    q = [int(next(tokens)) for _ in range(B)]  # type: "List[int]"
    r = [int(next(tokens)) for _ in range(C)]  # type: "List[int]"
    solve(X, Y, A, B, C, p, q, r)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X, Y, A, B, C=map(int,input().split())
rp=list(map(int,input().split()))
bp=list(map(int,input().split()))
np=list(map(int,input().split()))
rp.sort()
bp.sort()
np.sort()
count=X+Y
red=len(rp)-1
blue=len(bp)-1
non=len(np)-1
lb = blue-Y
lr = red -X
N=0
ans =0

for k in range(count):
    if non > -1:
        nn= np[non]
    else:
        nn =0
    if blue > lb:
        bb= bp[blue]
    else:
        bb =0
    if red > lr:
        rr= rp[red]
    else:
        rr =0
    
    if red == lr:
        if bb >= nn or non ==-1:
            ans+=bb
            blue-=1        
        else:
            ans += nn
            non-=1

    elif blue == lb:
        if rr >= nn or non ==-1:
            ans+=rr
            red-=1        
        else:
            ans += nn
            non-=1
       
    elif non > -1:
        if nn >= rr and nn >= bb:
            ans+=nn
            non-=1
        else:
            if red > lr:
                if blue> lb:
                    if rr >= bb:
                        ans += rr
                        red-=1
                    else:
                        ans+=bb
                        blue-=1
                else:
                    ans += rr
                    red-=1

            else:
                ans += bb
                blue-=1
    elif rr >= bb:
        ans += rr
        red-=1
    else:
        ans+=bb
        blue-=1
            
print(ans)

Submission status: Accepted

Solution code:
xyabc = list(map(int,input().rsplit()))
p = list(map(int,input().rsplit()))
q = list(map(int,input().rsplit()))
r = list(map(int,input().rsplit()))
x = xyabc[0]
y = xyabc[1]
p.sort(reverse=True)
q.sort(reverse=True)

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

Submission status: Accepted

Solution code:
x, y, a, b, c = map(int, input().split())
p = [int(_) for _ in input().split()]
q = [int(_) for _ in input().split()]
r = [int(_) for _ in input().split()]
 
p.sort()
q.sort()
r.sort()
 
x_list = p[-x:]
y_list = q[-y:]
all_apple = x_list + y_list + r
all_apple.sort()
 
print(sum(all_apple[-(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)[:x]
q = sorted(list(map(int, input().split())), reverse=True)[:y]
r = sorted(list(map(int, input().split())), reverse=True)

p.extend(q)
ans = sorted(p)

for i in range(x + y):
  if (len(r) == i) or (ans[i] > r[i]):
    break
  else:
    ans[i] = r[i]

print(sum(ans))

Submission status: Accepted

Solution code:
[X,Y,A,B,C] = [int(x) for x in input().split()]
R_list = [int(x) for x in input().split()]
G_list = [int(x) for x in input().split()]
T_list = [int(x) for x in input().split()]
R_list.sort()
G_list.sort()
T_list.sort()
ans = 0
r = 0
g = 0
for i in range(X+Y):
    if r == X:
        R_list = [0]
    if g == Y:
        G_list = [0]
    if len(T_list) == 0:
        T_list = [0]
    if max(R_list[-1],G_list[-1],T_list[-1]) == R_list[-1]:
        ans += R_list.pop(-1)
        r += 1
    elif max(R_list[-1],G_list[-1],T_list[-1]) == G_list[-1]:
        ans += G_list.pop(-1)
        g += 1
    elif max(R_list[-1],G_list[-1],T_list[-1]) == T_list[-1]:
        ans += T_list.pop(-1)
print(ans)

Submission status: Accepted

Solution code:
X, Y, A, B, C = tuple(int(v) for v in input().split())
p_list = sorted((int(v) for v in input().split()), reverse=True)
q_list = sorted((int(v) for v in input().split()), reverse=True)
r_list = sorted((int(v) for v in input().split()), reverse=True)

p_list = p_list[:X]
q_list = q_list[:Y]
all_apple = sorted(p_list + q_list + r_list, reverse=True)

yummy = sum(all_apple[:X+Y])
# # 赤リンゴを食べる
# for _ in range(X):
#     if p_list[-1] >= r_list[-1]:
#         yummy += p_list.pop()
#         if len(p_list) == 0:
#             p_list = [0]
#     else:
#         yummy += r_list.pop()
#         if len(r_list) == 0:
#             r_list = [0]
# # 緑リンゴを食べる
# for _ in range(Y):
#     if q_list[-1] >= r_list[-1]:
#         yummy += q_list.pop()
#         if len(q_list) == 0:
#             q_list = [0]
#     else:
#         yummy += r_list.pop()
#         if len(r_list) == 0:
#             r_list = [0]

print(yummy)

Submission status: Accepted

Solution code:
X,Y,A,B,C = map(int,input().split())
R = list(map(int,input().split()))
G = list(map(int,input().split()))
T = list(map(int,input().split()))
R.sort(reverse=True)
G.sort(reverse=True)
R = R[:X]
G = G[:Y]
A = T+R+G
A.sort(reverse=True)
print(sum(A[:X+Y]))

Submission status: Accepted

Solution code:
X,Y,A,B,C = (int(x) for x in input().split())
red = list(map(int, input().strip().split()))
green = list(map(int, input().strip().split()))
clear = list(map(int, input().strip().split()))
red.sort(reverse=True)
green.sort(reverse=True)
# clear.sort(reverse=True)
apple = red[0:X] + green[0:Y] + clear
apple.sort(reverse=True)
print(sum(apple[0:X+Y]))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
	X, Y, A, B, C = map(int, input().split())
	p = [int(a) for a in input().split()]
	q = [int(a) for a in input().split()]
	r = [int(a) for a in input().split()]

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


	P = p[0:X]
	Q = q[0:Y]

	s = P+Q+r

	s.sort(reverse=True)

	S = s[0:X+Y]

	ans = sum(S)

	print(ans)

Submission status: Accepted

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

A = sorted(list(map(int, input().split())), reverse=True)
A = A[:x]
B = sorted(list(map(int, input().split())), reverse=True)
B = B[:y]

C = sorted(list(map(int, input().split())), reverse=True)

ans = A + B + C
ans = sorted(ans, reverse=True)[:x+y]

print(sum(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)
np = p[:x]
nq = q[:y]
n = np + nq + r
n.sort(reverse=True)
print(sum(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()))
a = sorted(p)[A-X:]+sorted(q)[B-Y:]+r
print(sum(sorted(a)[C:]))

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

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

ans = 0

cnt = 0

while x+y-cnt > 0:
    if x > 0:
        p1 = p[-1]
    else:
        p1 = 0
    if y > 0:
        p2 = q[-1]
    else:
        p2 = 0
    if cnt < c:
        p3 = r[-1]
    else:
        p3 = 0
    eat = max(p1,p2,p3)
    ans += eat
    if x > 0 and p[-1] == eat:
        x -= 1
        p.pop()
    elif y > 0 and q[-1] == eat:
        y -= 1
        q.pop()
    else:
        cnt += 1
        r.pop()
print(ans)

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

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

while r != [] and ((p != [] and r[-1] > p[-1]) or (q != [] and r[-1] > q[-1])):
    if p == []:
        q.pop()
        plus_r.append(r.pop())
        continue
    elif q == []:
        p.pop()
        plus_r.append(r.pop())
        continue

    if p[-1] < q[-1]:
        p.pop()
    else:
        q.pop()
    plus_r.append(r.pop())

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

Submission status: Accepted

Solution code:
input1=list(map(int,input().split()))
input2=list(map(int,input().split()))
input3=list(map(int,input().split()))
input4=list(map(int, input().split()))

input2.sort(reverse=True)
input3.sort(reverse = True)

raw_final=input2[:input1[0]]+input3[:input1[1]]+input4

raw_final.sort(reverse=True)

print(sum(raw_final[:input1[0]+input1[1]]))

Submission status: Accepted

Solution code:
x,y,a,b,c = map(int,input().split())
p_list = list(map(int,input().split()))
q_list = list(map(int,input().split()))
r_list = list(map(int,input().split()))
p_list.sort(reverse = True)
q_list.sort(reverse = True)
p_list = p_list[:x]
q_list = q_list[:y]
all_list = p_list + q_list + r_list
all_list.sort(reverse = True)
print(sum(all_list[:x+y]))

Submission status: Accepted

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

def main():
    X, Y, A, B, C = list(map(int, input().split()))
    p = sorted(list(map(int, input().split())), reverse=True)[:X]
    q = sorted(list(map(int, input().split())), reverse=True)[:Y]
    r = sorted(list(map(int, input().split())) + p + q, reverse=True)[:(X+Y)]

    print(sum(r))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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]

P.extend(Q)
P.extend(r)

list = sorted(P, reverse=True)[:x+y]
ans = sum(list)

print(ans)

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

k = p[-X:] + q[-Y:] + r

k.sort()

ans_list = k[-(X + Y):]

print(sum(ans_list))

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(' ')))
 
eat = sorted(p, reverse=True)[:X]
eat[len(eat):] = sorted(q, reverse=True)[:Y]
eat[len(eat):] = R
eat.sort(reverse=True)


print(sum(eat[: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:
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:]

a=-(X+Y)
print(sum(sorted(R)[a:]))

Submission status: Accepted

Solution code:
x,y,a,b,c=map(int,input().split())
arr1=list(map(int,input().split()))
arr1=sorted(arr1,reverse=True)
arr1=arr1[:x]
arr2=list(map(int,input().split()))
arr2=sorted(arr2,reverse=True)
arr2=arr2[:y]
arr3=list(map(int,input().split()))
ans=arr1+arr2+arr3
ans=sorted(ans,reverse=True)
print(sum(ans[:x+y]))

Submission status: Accepted

Solution code:
X,Y,A,B,C=[int(i) for i in input().split(" ")]
red=[int(i) for i in input().split(" ")]
green=[int(i) for i in input().split(" ")]
white=[int(i) for i in input().split(" ")]

red=sorted(red,reverse=True)[:X]
green=sorted(green,reverse=True)[:Y]

color=[(r,'r') for r in red]+[(g,'g') for g in green]
color=sorted(color,key=lambda w:w[0],reverse=False)
white=sorted(white,reverse=True)

delicious=0


for c in color:
    if(c[1]=='r'):
        if X==0:
            continue
        X-=1
        if(len(white)>0 and c[0]<white[0]):
            delicious+=white[0]
            white.pop(0)
        else:
            delicious+=c[0]

    else:
        if Y==0:
            continue
        Y-=1
        if(len(white)>0 and c[0]<white[0]):
            delicious+=white[0]
            white.pop(0)
        else:
            delicious+=c[0]


print(delicious)

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)
A = A[:x]
B.sort(reverse=True)
B = B[:y]

AB = A + B
AB.sort(reverse=True)
total = sum(AB)
C.sort()

while AB and C:
    point = AB.pop()
    candidate = C.pop()
    if candidate > point:
        total += candidate - point
    else:
        break

print(total)

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

Submission status: Accepted

Solution code:
# E - Red and Green Apples

X, Y, A, B, C = map(int, input().split())
P = list(int(x) for x in input().split())
Q = list(int(x) for x in input().split())
R = list(int(x) for x in input().split())

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

ans = []
ans.extend(P[0:X])
ans.extend(Q[0:Y])
ans.extend(R)
ans.sort(reverse=True)

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

Submission status: Accepted

Solution code:
def solve():
  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 = list(sorted(p))
  p = p[-x:]
  q = list(sorted(q))
  q = q[-y:]

  _r = r + p + q
  
  _r = list(sorted(_r))
  
  s = 0
  for _s in _r[-(x + y):]:
    s += _s
  
  print(s)

  return

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)
for i in range(x):
    r.append(p[i])

for i in range(y):
    r.append(q[i])

r.sort(reverse = True)

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

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from heapq import *

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)
pq = []
ans = 0

for i in range(X):
    heappush(pq, p[i])
    ans += p[i]

for i in range(Y):
    heappush(pq, q[i])
    ans += q[i]

r.sort(reverse=True)
now = ans

for i in range(C):
    now -= heappop(pq)
    heappush(pq, r[i])
    now += r[i]
    ans = max(ans, now)

print(ans)

Submission status: Accepted

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


def main():
    import sys
    input = sys.stdin.readline

    from heapq import heappush, heappop

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

    h = list()

    for pi in p:
        heappush(h, pi)

    for qi in q:
        heappush(h, qi)

    for ri in r:
        heappush(h, ri)

    for i in range(c):
        heappop(h)

    print(sum(h))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import heapq as hq

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    X, Y, A, B, C = map(int, rl().split())
    p = list(map(int, rl().split()))
    q = list(map(int, rl().split()))
    r = list(map(int, rl().split()))
    
    p.sort(reverse=True)
    q.sort(reverse=True)
    r.sort(reverse=True)
    heap_p = p[:X]
    heap_q = q[:Y]
    hq.heapify(heap_p)
    hq.heapify(heap_q)
    
    for ri in r:
        if heap_p[0] < ri and heap_p[0] <= heap_q[0]:
            hq.heappushpop(heap_p, ri)
        elif heap_q[0] < ri:
            hq.heappushpop(heap_q, ri)
        else:
            break
    
    ans = sum(heap_p) + sum(heap_q)
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 30 21:20:44 2020

@author: black
"""


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 = [(i, "RED") for i in p]
Q = [(i, "GREEN") for i in q]
R = [(i, "NO COLOR") for i in r]

all = []
all.extend(P)
all.extend(Q)
all.extend(R)
all.sort()

import copy
test = copy.deepcopy(all)

all.sort(reverse=True)

num_red = 0
num_green = 0
num_transparent = 0
total = 0

for i in all:
    if num_red + num_green + num_transparent < X + Y:
        if i[1] == "RED":
            if num_red < X:
                num_red += 1
                total += i[0]
        elif i[1] == "GREEN":
            if num_green < Y:
                num_green += 1
                total += i[0]
        elif i[1] == "NO COLOR":
            num_transparent += 1
            total += i[0]
    else:
        break

print(total)