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
import heapq


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


MOD = 10 ** 9 + 7
sys.setrecursionlimit(20000000)


def main():
    X, Y, A, B, C = map(int, input().split())
    red = list(map(int, input().split()))
    green = list(map(int, input().split()))
    nocolor = list(map(int, input().split()))

    red.sort()
    green.sort()
    nocolor.sort()
    answer = sum(red[A - X :]) + sum(green[B - Y :])
    heap = red[A - X :] + green[B - Y :]
    heapq.heapify(heap)
    flag = 0
    while heap and flag < C:
        m = heapq.heappop(heap)
        if nocolor[flag] > m:
            answer -= m
            answer += nocolor[flag]
            heapq.heappush(heap, nocolor[flag])
            flag += 1
        else:
            heapq.heappush(heap, m)
            flag += 1

    print(answer)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
import heapq
def main():
    x,y,a,b,c=map(int,input().split())
    P=list(map(int,input().split()))
    Q=list(map(int,input().split()))
    R=list(map(int,input().split()))
    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)
    Z=P[:x]+Q[:y]
    heapq.heapify(Z)
    for r in R:
        if Z[0]>=r:
            break
        heapq.heapreplace(Z,r)
    print(sum(Z))

    

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
apple = list(map(int, input().split()))
x = apple[0]
y = apple[1]        #to eat
a = apple[2]
b = apple[3]        #i have
c = apple[4]

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)

XredApl = []
for i in range(x):
    XredApl.append(p[i])

YgrnApl = []
for i in range(y):
    YgrnApl.append(q[i])
    
fnlst = XredApl + YgrnApl + r 
fnlst.sort(reverse=True)
s = 0
for i in range(x+y):
    s += fnlst[i]
    
print(s)

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

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

red = [[i, "r"] for i in p]
green = [[i, "g"] for i in q]
white = [[i, "w"] for i in r]

total = sorted(red + green + white)[::-1]

ans = 0
cnt = 0
r_cnt = 0
g_cnt = 0
for t in total:
    if t[1] == "r" and r_cnt == X:
        continue
    if t[1] == "g" and g_cnt == Y:
        continue
    ans += t[0]
    if t[1] == "r":
        r_cnt += 1
    elif t[1] == "g":
        g_cnt += 1
    cnt += 1
    if cnt == X + Y:
        break

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

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

print(sum(C[: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()
r.sort(reverse=True)

ppick = p[-x:]
qpick = q[-y:]
pi = 0
qi = 0

for i in range(len(r)):
    if pi >= x:
        while True:
            if qi < y and i < c and r[i] > qpick[qi]:
                qpick[qi] = r[i]
                qi += 1
                i += 1
            else:
                break
    elif qi >= y:
        while True:
            if pi < x and i < c and r[i] > ppick[pi]:
                ppick[pi] = r[i]
                pi += 1
                i += 1
            else:
                break
    elif ppick[pi] >= qpick[qi] and qpick[qi] < r[i]:
        qpick[qi] = r[i]
        qi += 1
        continue
    elif ppick[pi] < qpick[qi] and ppick[pi] < r[i]:
        ppick[pi] = r[i]
        pi += 1
        continue
    break

print(sum(ppick) + sum(qpick))

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

r.sort(reverse=True)

ans = []

for i in range(x):
    ans.append(p[i])

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

ans = ans + 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()))
ans=[]
s=x+y
for i in p:
    ans.append((i,0))
for i in q:
    ans.append((i,1))
for i in r:
    ans.append((i,2))
ans.sort(reverse=True)
res=0
cnt=0
for i , j in ans:
    if j==0:
        if x>0:
            x-=1
            cnt+=1
            res+=i
    elif j==1:
        if y>0:
            y-=1
            cnt+=1
            res+=i
    else:
        cnt+=1
        res+=i
    if cnt>=s:
        break

print(res)

Submission status: Accepted

Solution code:


def main():
    X,Y,A,B,C  = map(int, input().split()) 
    sum = 0
    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)
    strr = len(r)
    pq = []


    rindex = 0

    for index in range(X):
        sum += p[index]
        pq.append(p[index])

    for index in range(Y):
        sum += q[index]
        pq.append(q[index])

    list.sort(pq,reverse=True)
    strpq = len(pq)

    for index in range(strr):
        if strpq > index and r[index] > pq[X+Y-1-index]:
            sum += r[index] - pq[X+Y-1-index]

    print (sum)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

p.sort(key=lambda x: -x)
q.sort(key=lambda x: -x)
p = p[:X]
q = q[:Y]

pqr = p+q+r
pqr.sort(key=lambda x: -x)
print(sum(pqr[:X+Y]))

Submission status: Accepted

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

p.sort(key=lambda x: -x)
q.sort(key=lambda x: -x)
r.sort(key=lambda x: -x)

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

psum = sum(p)
qsum = sum(q)
pi, qi, ri = 0, 0, 0
while ri < len(r):
    found = ""
    if pi < X and qi < Y:
        if p[pi] <= q[qi]:
            if p[pi] < r[ri]:
                found = "p"
        else:
            if q[qi] < r[ri]:
                found = "q"
    elif pi < X:
        if p[pi] < r[ri]:
            found = "p"
    elif qi < Y:
        if q[qi] < r[ri]:
            found = "q"

    if found == "p":
        psum -= p[pi]
        psum += r[ri]
        pi += 1
        ri += 1
    elif found == "q":
        qsum -= q[qi]
        qsum += r[ri]
        qi += 1
        ri += 1
    else:
        break

print(psum+qsum)

Submission status: Accepted

Solution code:
x,y,a,b,c = map(int, input().split(" "))
plist= sorted(list(map(int, input().split(" "))),reverse=True)[0:x]
qlist= sorted(list(map(int, input().split(" "))),reverse=True)[0:y]
rlist= sorted(list(map(int, input().split(" "))),reverse=True)

plist.extend(qlist)
plist.sort()
n = min(x+y,len(rlist))
i = 0

while i < n and rlist[i]>plist[i]:
  i += 1
if i == 0:
  print(sum(plist))
else:
  print(sum(plist[i:x+y])+sum(rlist[0:i]))

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
from collections import defaultdict
#d = defaultdict(int)
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import numpy as np
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
s = p[:X]+q[:Y]+r
n = len(s)
for i in range(n):
    s[i] *= -1
heapify(s)
ans = 0
for i in range(X+Y):
    ans -= heappop(s)
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[:x]
q = q[:y]
r = r[:x+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())
L = []
P = list(map(int, input().split()))
P.sort(reverse=True)
L += P[:X]
Q = list(map(int, input().split()))
Q.sort(reverse=True)
L += Q[:Y]
L += list(map(int, input().split()))
L.sort(reverse=True)
print(sum(L[:X + Y]))

Submission status: Accepted

Solution code:
(x, y, A, B, C) = map(int, raw_input().split())

ps = sorted(map(int, raw_input().split()), reverse=True)[:x]
qs = sorted(map(int, raw_input().split()), reverse=True)[:y]
cs = sorted(map(int, raw_input().split()))

res = sorted(ps + qs, reverse=True)
tot = sum(res)

while cs and res and cs[-1] >= res[-1]:
    tot -= res.pop()
    tot += cs.pop()

print tot

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)

ret = red[:x] + green[:y]
ret.sort()

for i in range(len(colorless)):
    if ret[i] < colorless[i]:
        ret[i] = colorless[i]
    else:
        break

print(sum(ret))

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

Submission status: Accepted

Solution code:
from sys import stdin


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

    pqr = []

    for pi in p:
        pqr.append([pi, 0])
    for qi in q:
        pqr.append([qi, 1])
    for ri in r:
        pqr.append([ri, 2])

    pqr.sort(reverse=True)

    ans = 0
    c_a = 0
    c_b = 0
    c_c = 0

    for pqri in pqr:
        if pqri[1] == 0 and c_a < x:
            ans += pqri[0]
            c_a += 1
        elif pqri[1] == 1 and c_b < y:
            ans += pqri[0]
            c_b += 1
        elif pqri[1] == 2 and (c_a < x or c_b < y) and c_a + c_b + c_c < x + y:
            ans += pqri[0]
            c_c += 1
        if c_a + c_b + c_c == x + y:
            print(ans)
            exit()


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
(x, y, A, B, C) = map(int, raw_input().split())

ps = sorted(map(int, raw_input().split()), reverse=True)[:x]
qs = sorted(map(int, raw_input().split()), reverse=True)[:y]
cs = sorted(map(int, raw_input().split()))

tot = sum(ps) + sum(qs)

while cs and ((ps and cs[-1] > ps[-1]) or (qs and cs[-1] > qs[-1])):
    if ps and qs:
        if ps[-1] < qs[-1]:
            tot -= ps.pop()
            tot += cs.pop()
        else:
            tot -= qs.pop()
            tot += cs.pop()
    elif ps:
        tot -= ps.pop()
        tot += cs.pop()
    elif qs:
        tot -= qs.pop()
        tot += cs.pop()
    else:
        break
# print ps, qs

print tot

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

Submission status: Accepted

Solution code:
def function(arg):
    xyabc, pa, qb, rc = arg.split('¥n')
    X,Y,A,B,C = map(int, xyabc.split())
    oishisa_A = list(map(int, pa.split()))
    oishisa_B = list(map(int, qb.split()))
    oishisa_C = list(map(int, rc.split()))
    
    oishisa_A.sort(reverse=True)
    oishisa_A = oishisa_A[:X] # at most X
    oishisa_B.sort(reverse=True)
    oishisa_B = oishisa_B[:Y] # at most Y
    oishisa_C.sort(reverse=True)
    
    oishisa = oishisa_A + oishisa_B + oishisa_C
    oishisa.sort(reverse=True)

    results = 0
    for i in range(X+Y):
        results += oishisa[i]

    return results

if __name__ == '__main__':
    xyabc = input()
    pa = input()
    qb = input()
    rc = input()
    print(function(xyabc+'¥n'+pa+'¥n'+qb+'¥n'+rc))

Submission status: Accepted

Solution code:
from collections import deque

x, y, a, b, c = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P = sorted(P, reverse=True)[:x]

Q = sorted(Q, reverse=True)[:y]

P.extend(Q)
R.extend(P)

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

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_sum = [0]*(a+1)
q_sum = [0]*(b+1)
for i in range(a):
    p_sum[i+1] = p_sum[i] + p[i]
for i in range(b):
    q_sum[i+1] = q_sum[i] + q[i]
#print(p_sum)
#print(q_sum)
ans = [0]*(c+1)
ans[0] = p_sum[X] + q_sum[Y]
x, y = X, Y
flag = True
for i in range(c):
    if x > 0 and y > 0:
        ans[i+1] = max(ans[i]-p[x-1]+r[i], ans[i]-q[y-1]+r[i], ans[i])
        if ans[i+1] == ans[i]-p[x-1]+r[i]:
            x -= 1
        elif ans[i+1] == ans[i]-q[y-1]+r[i]:
            y -= 1
        elif ans[i+1] == ans[i]:
            break
    elif x == 0:
        ans[i+1] = max(ans[i]-q[y-1]+r[i], ans[i])
        if ans[i+1] == ans[i]:
            break
        else:
            y -= 1
    elif y == 0:
        ans[i+1] = max(ans[i]-p[x-1]+r[i], ans[i])
        if ans[i+1] == ans[i]:
            break
        else:
            x -= 1
    elif x == 0 and y == 0:
        flag = False
if flag:
    print(max(ans))
else:
    print(sum(r[:x+y-1]))

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

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

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

Submission status: Accepted

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


hq = P[:X]+Q[:Y]
ans = sum(hq)
heapq.heapify(hq)  # リストhqのheap化

i = 0
while hq and i < len(R):
    t = heapq.heappop(hq)  # heap化されたリストhqから最小値を削除＆その最小値を出力
    if R[i] > t:
        ans = ans - t + R[i]
        i += 1
    else:
        break
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()
p = p[len(p)-x:]
q.sort()
q = q[len(q)-y:]
r.extend(q)
r.extend(p)
r.sort()

print(sum(r[len(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()))

red_green = [(p, "r") for p in P] + [(q, "g") for q in Q]
red_green.sort()
nc = R
nc.sort()

cnt_r , cnt_g , cnt_n = 0,0,0

ans = 0
while cnt_r + cnt_g + cnt_n < X + Y:

    # 指定の個数食べきっている色は除外
    if cnt_r == X:
        while red_green[-1][1] == "r":
            red_green.pop()
    if cnt_g == Y:
        while red_green[-1][1] == "g":
            red_green.pop()

    # 無色と色付きの得点の高いほうを食べる
    if len(nc) > 0 and nc[-1] > red_green[-1][0]:
        point = nc.pop()
        ans += point
        cnt_n += 1
    else:
        point, color = red_green.pop()
        ans += point
        if color == "r":
            cnt_r += 1
        else:
            cnt_g += 1


print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    x,y,a,b,c = LI()
    p = sorted(LI()) + [inf]
    q = sorted(LI()) + [inf]
    r = [-1] + sorted(LI())
    pi = a - x
    qi = b - y
    ri = c
    while True:
        if p[pi] < q[qi]:
            if p[pi] >= r[ri]:
                break
            pi += 1
            ri -= 1
        else:
            if q[qi] >= r[ri]:
                break
            qi += 1
            ri -= 1

    return sum(p[pi:-1] + q[qi:-1] + r[ri+1:])

print(main())

Submission status: Accepted

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

plist.sort()
qlist.sort()
rlist.sort(reverse=True)


pgensen=plist[a-x:]
qgensen=qlist[b-y:]

tmplist=pgensen+qgensen
tmplist.sort()

replacesum=0
for i in range(min(x+y,len(rlist))):
    if tmplist[i] >= rlist[i]:
        break
    else:
        replacesum+=rlist[i]-tmplist[i]

print(sum(tmplist)+replacesum)

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)


i, j, k = x, y, 0

def check(z , l):
    return z > l[-1]

while i**2 + j**2 > 0 and k < len(r):
    if i*j != 0:
        if r[k] > p[i-1] or r[k] > q[j-1]:
            if p[i-1] > q[j-1]:
                j -= 1
            else:
                i -= 1
        else:
            break
    elif i > 0:
        if r[k] > p[i-1]:
            i -= 1
        else:
            break

    elif j > 0:
        if r[k] > q[j-1]:
            j -= 1
        else:
            break


    k += 1

print(sum(p[:i])+sum(q[:j])+sum(r[:k]))

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

X, Y, A, B, C = LI()
p = LI()
q = LI()
r = LI()

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

def solve():
    ans = 0
    p_selected = p[:X]
    q_selected = q[:Y]
    p_selected.sort()
    q_selected.sort()
    p_cnt = 0
    q_cnt = 0
    r_selected = r[:min((X + Y), len(r))]
    # print(p_selected, q_selected)

    ans += sum(p_selected) + sum(q_selected)
    for r_i in r_selected:
    
        if q_cnt < Y and p_cnt < X:
            if p_selected[p_cnt] >= q_selected[q_cnt]:
                if q_selected[q_cnt] < r_i:
                    ans += r_i - q_selected[q_cnt]
                    q_cnt += 1
                else:
                    return ans
            elif p_selected[p_cnt] < q_selected[q_cnt]:
                if p_selected[p_cnt] < r_i:
                    ans += r_i - p_selected[p_cnt]
                    p_cnt += 1
                else:
                    return ans
        elif q_cnt < Y and p_cnt >= X:
            if q_selected[q_cnt] < r_i:
                ans += r_i - q_selected[q_cnt]
                q_cnt += 1
            else:
                return ans
        elif p_cnt < X and q_cnt >= Y:
            if p_selected[p_cnt] < r_i:
                ans += r_i - p_selected[p_cnt]
                p_cnt += 1
            else:
                return ans

    return ans

ans = solve()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,y,a,b,c=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())))
for i in range(len(p)):
  r.append(p[i])
for i in range(len(q)):
  r.append(q[i])
r=sorted(r)[-x-y:]
print(sum(r))

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)

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

'''
pi = x - 1
qi = y - 1
ri = 0

while ri < c and (p[pi] < r[ri] or q[qi] < r[ri]):
    if p[pi] >= q[qi]:
        q[qi] = r[ri]
        qi -= 1
    else:
        p[pi] = r[ri]
        pi -= 1
    ri += 1

print(sum(p[:x]) + sum(q[: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)
kouho=p[:X]+q[:Y]
kouho.sort()
for i in range(min(C,X+Y)):
    kouho[i]=max(kouho[i],r[i])
print(sum(kouho))

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 j in range(y):
  r.append(q[j])
           
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
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()))
    r.sort(reverse=True)
    target = p[:X] + q[:Y] + r
    target.sort(reverse=True)
    ans = sum(target[:X+Y])
    print(ans)
if __name__ == "__main__":
    main()

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

Submission status: Accepted

Solution code:
x,y,a,b,c=map(int,input().split())
p=list(map(lambda x:['red',int(x)],input().split()))
q=list(map(lambda x:['green',int(x)],input().split()))
r=list(map(lambda x:['nan',int(x)],input().split()))
p.sort(key=lambda x:x[1])
p=p[-x:]
q.sort(key=lambda x:x[1])
q=q[-y:]
p[len(p):len(p)]=q
p[len(p):len(p)]=r
p.sort(key=lambda x:x[1])
p=p[-x-y:]
print(sum([pi[1] for pi in p]))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter

from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
#dequeを使うときはpython3を使う、pypyはダメ
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds

#mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

#N = int(input())
X,Y,A,B,C = map(int, input().split())
#L = [int(input()) for i in range(N)]
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]


ans=0
countp=0
countq=0
countr=0
count=0
r=0
pt=0
qt=0
lR=len(R)
#print(p)
#print(q)
while count<X+Y:
    if countr<lR and r==0:
        r=R[countr]
        countr+=1


    if countp<X and pt==0:
        pt=p[countp]
        countp+=1
    

    if countq<Y and qt==0:
        qt=q[countq]
        countq+=1



    #print(pt,qt,r)
    ans+=max(r,pt,qt)
    if r>=pt and r>=qt:
        r=0
    elif pt>=r and pt>=qt:
        pt=0
    else:
        qt=0
    
    count+=1


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)

l = p[:x] + q[:y]
l.sort()

i = 0
while i < len(l) and i < len(r):
  if l[i] < r[i]:
    l[i] = r[i]
    i += 1
  else:
    break

print(sum(l))

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

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

Submission status: Accepted

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

q = list(map(int, input().split()))
q.sort(reverse=True)
topQ = q[:Y]

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

concat = topP + topQ + r
concat.sort(reverse=True)
top = concat[:X+Y]

print(sum(top))

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(reverse=True)

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

p.extend(q)
p.sort()

ans = sum(p)
count = 0
for i in range(c):
	if p[i] < r[i]:
		ans += r[i] - p[i]
	else:
		break
print(ans)