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

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

total = C
A.sort()
A.reverse()
B.sort()
B.reverse()

for i in range(X) :
  total.append(A[i])
  
for j in range(Y) :
  total.append(B[j])

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

Submission status: Accepted

Solution code:
x,y,a,b,c = (int(x) for x in input().split())
p = sorted((int(x) for x in input().split()), reverse=True)
q = sorted((int(x) for x in input().split()), reverse=True)
r = sorted((int(x) for x in input().split()), reverse=True)
ans = sum(p[:x]) + sum(q[:y])
cnt = 0
cnt_a = 0
cnt_b = 0
for cnt in range(c):
    if (x-1-cnt_a) < 0 and  y-1-cnt_b < 0:
        break
    pa = max(0, x-1-cnt_a)
    pb = max(0, y-1-cnt_b)
    if r[cnt] < p[pa] and r[cnt] < q[pb]:
        break
    if p[pa] > q[pb]:
        ans  = ans - q[pb] + r[cnt]
        cnt_b += 1
        q[pb] = r[cnt]
    elif p[pa] < q[pb]:
        ans = ans - p[pa] + r[cnt]
        cnt_a += 1
        p[pa] = r[cnt]
    else:
        j = 0
        while p[pa-j] == q[pb-j] and pa - j > -1 and pb - j > -1:
            j += 1
        if p[pa-j] > q[pb-j]:
            ans  = ans - q[pb] + r[cnt]
            cnt_b += 1
            q[pb] = r[cnt]
        elif p[pa-j] < q[pb-j]:
            ans = ans - p[pa] + r[cnt]
            cnt_a += 1
            p[pa] = r[cnt]
        elif x > y and x-1-cnt_a >= 0:
            ans = ans - p[pa] + r[cnt]
            cnt_a += 1
            p[pa] = r[cnt]
        elif y-1-cnt_b >= 0:
            ans  = ans - q[pb] + r[cnt]
            cnt_b += 1
            q[pb] = r[cnt]
        elif x-1-cnt_a >= 0:
            ans = ans - p[pa] + r[cnt]
            cnt_a += 1
            p[pa] = r[cnt]
        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(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

pi = 0
qi = 0
ri = 0
ans = 0

for _ in range(X + Y):
    p = P[pi] if pi < X else 0
    q = Q[qi] if qi < Y else 0
    r = R[ri] if ri < C else 0

    if p > q:
        if p >= r:
            ans += p
            pi += 1
        else:
            ans += r
            ri += 1
    else:
        if q >= r:
            ans += q
            qi += 1
        else:
            ans += r
            ri += 1

print(ans)

Submission status: Accepted

Solution code:
x,y,a,b,c=map(int,input().split()) #x,yだけ見る。
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]
print(sum(sorted(p+q+r, reverse=True)[:x+y]))

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

Solution code:
X, Y, A, B, C = map(int, input().split())
Red = sorted(list(map(int, input().split())), reverse=True)
Grn = sorted(list(map(int, input().split())), reverse=True)
Wht = sorted(list(map(int, input().split())), reverse=True)

Mix = Red[:X] + Grn[:Y] + Wht
Mix = sorted(Mix, reverse=True)
ans = sum(Mix[:X+Y])
print(ans)

Submission status: Accepted

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

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

aps = sorted(px + qx + r, reverse=True)

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

Submission status: Accepted

Solution code:
import numpy as np
X, Y, A, B, C = map(int,input().split())
Reds = list(map(int, input().split()))
Greens = list(map(int, input().split()))
Ns = list(map(int, input().split()))

Reds = np.array(Reds)
Greens = np.array(Greens)
Ns = np.array(Ns)

Reds = np.sort(Reds)[::-1]
Greens = np.sort(Greens)[::-1]
Ns = np.sort(Ns)[::-1]

Full = np.append(Reds[:X], Greens[:Y])
Full = np.append(Full, Ns)
Full = np.sort(Full)[::-1]

sum = 0

for i in range(X+Y):
    sum += Full[i]

print(sum)

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

print(sum(sorted(sorted(p)[-x:] + sorted(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()))

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

Submission status: Accepted

Solution code:
x,y,a,b,c = (int(x) for x in input().split())
list_p = list(map(int,input().split()))
list_q = list(map(int,input().split()))
list_r = list(map(int,input().split()))
list_p.sort()
list_q.sort()
list_p.reverse()
list_q.reverse()
for i in range(x):
    list_r.append(list_p[i])
for i in range(y):
    list_r.append(list_q[i])
list_r.sort()
list_r.reverse()
sum=0
for i in range(x+y):
    sum+=list_r[i]
print(sum)

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_right, bisect_left

def to_cumsum(arr, pad=True):
    """
    1次元配列を累積和の1次元配列に変換する
    pad: 先頭に0の項を作る場合はTrue
    """
    cumsum = 0
    padding = 1 if pad else 0
    new = [0] * (len(arr) + padding)
    for i, e in enumerate(arr):
        cumsum += e
        new[i + padding] = cumsum
    return new

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


X, Y, A, B, C = MI()
P = LMI()
Q = LMI()
R = LMI()

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


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

ans = 0
cnt_r, cnt_g, cnt_nc = 0, 0, 0


while cnt_r + cnt_g + cnt_nc < X + Y:

    if cnt_r == X:
        while rg[-1][1] == "r":
            rg.pop()

    if cnt_g == Y:
        while rg[-1][1] == "g":
            rg.pop()


    if len(nc) > 0 and nc[-1] > rg [-1][0]:
        tmp = nc.pop()
        cnt_nc += 1
    else:
        tmp, c = rg.pop()
        if c == "r":
            cnt_r += 1

        else:
            cnt_g += 1


    ans += tmp

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=1)
Q.sort(reverse=1)
R.sort(reverse=1)

R0=P[:X]
R0.extend(Q[:Y])
R0.sort()
for i in range(C):
    if R0[i]<R[i]:
        R0[i]=R[i]
    else:
        break
print(sum(R0))

Submission status: Accepted

Solution code:
def resolve():
    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)
    pre = sorted(p[:X] + q[:Y])
    for i in range(min(X + Y, C)):
        if pre[i] < r[i]:
            pre[i] = r[i]
        else:
            break
    print(sum(pre))

resolve()

Submission status: Accepted

Solution code:
if __name__ == "__main__":

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

    Red = list(map(int, input().split()))
    Red.sort()
    Red = Red[::-1]
    Red = Red[:X]
    Green = list(map(int, input().split()))
    Green.sort()
    Green = Green[::-1]
    Green = Green[:Y]
    NoColor = list(map(int, input().split()))

    A = Red + Green + NoColor
    # print(A)
    A.sort(reverse=True)

    eaten = A[:X+Y]

    print(sum(eaten))

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()
l = p[-X:] + q[-Y:]
l.sort()

for i in range(min(X+Y,C)):
  if l[i] < r[-1]:
    l[i] = r.pop()


ans = sum(l)
print(ans)

Submission status: Accepted

Solution code:
from heapq import heapify, heappop
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    X,Y,A,B,C = map(int, readline().split())
    p = [-int(i) for i in readline().split()]
    q = [-int(i) for i in readline().split()]
    r = [-int(i) for i in readline().split()]

    p = sorted(p)[:X]
    q = sorted(q)[:Y]
    r.sort()
    
    Q = p + q + r
    heapify(Q)

    ans = 0
    for i in range(X+Y):
        ans -= heappop(Q)
        
    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)[-X:]
q = sorted(q)[-Y:]
pq = p + q
pq.sort()
r.sort()
N = X + Y
cnt = 0

from collections import deque
pq = deque(pq)
r = deque(r)

pq_max = pq.pop()
r_max = r.pop()
emp = deque()

for _ in range(N):
    if pq_max >= r_max:
        cnt += pq_max
        if pq == emp:
            pq_max = 0
        else:
            pq_max = pq.pop()
    else:
        cnt += r_max
        if r == emp:
            r_max = 0
        else:
            r_max = r.pop()

print(cnt)

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)
p=p[:x]
q=q[:y]
r=r+p+q
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 = (int(i) for i in input().split())
p = [[int(x), "A"] for x in input().split()]
q = [[int(x), "B"] for x in input().split()]
r = [[int(x), "C"] for x in input().split()]
#A = [[int(i) for i in input().split()] for i in range(N)]
apples = p+q+r


#apples.sort(reverse=True)
apples = sorted(apples, reverse=True)
#print(apples)
ans = 0
pend = 0


for hapi, col in apples:
    if col == "C":
        pend += 1
        ans += hapi
    elif col == "A":
        if X > 0:
            ans += hapi
            X -= 1

    elif col == "B":
        if Y>0:
            ans += hapi
            Y -= 1

    if (X < 1 and Y < 1) or X+Y == pend:
        break
    #print(ans)
    #print("XY", X, Y, pend)
#print("XY", X, Y, pend)
print(ans)

Submission status: Accepted

Solution code:
x,y,a,b,c=map(int,input().split())
p0=list(map(int,input().split()))
q0=list(map(int,input().split()))
r0=list(map(int,input().split()))
p1=sorted(p0)
q1=sorted(q0)
p2=[]
q2=[]
for i in range(x):
    p2.append(p1[-i-1])
for i in range(y):
    q2.append(q1[-i-1])
ringo0=p2+q2+r0
ringo1=sorted(ringo0,reverse=True)
s=0
for i in range(x+y):
    s=s+ringo1[i]
print(s)

Submission status: Accepted

Solution code:
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
input = sys.stdin.readline
#文字列のときはうまく行かないのでコメントアウトすること
sys.setrecursionlimit(2147483647)

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

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import sys
from collections import Counter
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()))

ans = []

ans.extend(sorted(p, reverse=True)[:X])
ans.extend(sorted(q, reverse=True)[:Y])
ans.extend(r)
ans.sort(reverse=True)

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
X, Y, A, B, C = (int(i) for i in input().split())
p = [[int(x), "A"] for x in input().split()]
q = [[int(x), "B"] for x in input().split()]
r = [[int(x), "C"] for x in input().split()]
#A = [[int(i) for i in input().split()] for i in range(N)]
apples = p+q+r


apples.sort(reverse=True)
#print(apples)
ans = 0
pend = 0


for hapi, col in apples:
    if col == "C":
        pend += 1
        ans += hapi
    elif col == "A":
        if X > 0:
            ans += hapi
            X -= 1

    elif col == "B":
        if Y>0:
            ans += hapi
            Y -= 1

    if (X < 1 and Y < 1) or X+Y == pend:
        break
    #print(ans)
    #print("XY", X, Y, pend)
#print("XY", X, Y, pend)
print(ans)

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()))
cl = list(map(int, input().split()))
r.sort(reverse=True)
g.sort(reverse=True)
ans = r[:x] + g[:y] + cl
print(sum(sorted(ans, reverse=True)[:x+y]))

Submission status: Accepted

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,boundary=1,search=[],replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,boundary=1,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
def show2d(g,h,w):
    for i in range(h):show(g[i*w:i*w+w])

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0
x,y,a,b,c=LI()
p=sorted(LI())[-x:]
q=sorted(LI())[-y:]
r=LI()+p+q

print(sum(sorted(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()))

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

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

Submission status: Accepted

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

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

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


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

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

Submission status: Accepted

Solution code:
def main():
    s = open(0).readlines()

    x, y, a, b, c = map(int, s[0].split())
    f = lambda x: list(map(int, x.split()))

    p, q, r = map(f, s[1:])

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

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

    i = max(r)
    j = sum(x > i for x in p)
    k = sum(x > i for x in q)

    pd = p[j:]
    qd = q[k:]

    m = (x - j) + (y - k)

    rem = sorted(pd + qd + r, reverse=True)
    ans = sum(p[:j] + q[:k]) + sum(rem[:m])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys


def main():
    x, y, a, b, c = [int(s) for s in sys.stdin.readline().strip().split()]
    p = [int(s) for s in sys.stdin.readline().strip().split()]
    q = [int(s) for s in sys.stdin.readline().strip().split()]
    r = [int(s) for s in sys.stdin.readline().strip().split()]

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

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

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

main()

Submission status: Accepted

Solution code:
def resolve():
    import heapq
    from collections import deque
    x, y, a, b, c = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    p = sorted(p, reverse=True)[:x]
    q = sorted(q, reverse=True)[:y]
    heapq.heapify(p)
    heapq.heapify(q)
    r = deque(sorted(r, reverse=True))
    while r:
        testp = heapq.heappop(p)
        testq = heapq.heappop(q)
        testr = r.pop()
        if testp <= testq:
            heapq.heappush(q, testq)
            if testp <= testr:
                heapq.heappush(p, testr)
            else:
                heapq.heappush(p, testp)

        if testp > testq:
            heapq.heappush(p, testp)
            if testq <= testr:
                heapq.heappush(q, testr)
            else:
                heapq.heappush(q, testq)
    print(sum(p+q))
resolve()

Submission status: Accepted

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


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)

x_p = []
y_q = []
xy_r = []
c = 0
for p in P[::-1]:
    if c == X: break
    x_p.append(p)
    c += 1
c = 0
for q in Q[::-1]:
    if c == Y: break
    y_q.append(q)
    c += 1
c = 0
for r in R[::-1]:
    if c == X+Y: break
    xy_r.append(r)
    c += 1



p_i = len(x_p)-1
q_i = len(y_q)-1
xy_i = 0


f = True

while f:
    if xy_i == len(xy_r): break
    p = x_p[p_i]
    q = y_q[q_i]
    s = ''
    if p > q:
        s = 'q'
        mi = q_i
    else:
        s = 'p'
        mi = p_i
    if s == 'p' and p < xy_r[xy_i]:
        x_p[p_i] = xy_r[xy_i]
        p_i -= 1
        xy_i += 1
    elif s == 'q' and q < xy_r[xy_i]:
        y_q[q_i] = xy_r[xy_i]
        q_i -= 1
        xy_i += 1
    else:
        f = False

ans = sum(x_p) + sum(y_q)
print(ans)

Submission status: Accepted

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

x,y,a,b,c=MI()
p=sorted(LI())[::-1][:x]
q=sorted(LI())[::-1][:y]
r=sorted(LI())[::-1]

u=sorted(p+q+r)[::-1][:x+y]
print(sum(u))

Submission status: Accepted

Solution code:
import sys

X, Y, A, B, C = map(int, sys.stdin.readline().strip().split())

P = list(map(int, sys.stdin.readline().strip().split()))
Q = list(map(int, sys.stdin.readline().strip().split()))
R = list(map(int, sys.stdin.readline().strip().split()))

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

ans = P[:X] + Q[:Y] + 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 = []

ans.extend(sorted(p,reverse=True)[:x])
ans.extend(sorted(q,reverse=True)[: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 = sorted(p)
q = sorted(q)
r = sorted(r)
P = A - X
Q = B - Y
R = C - 1
found = True
for i in range(C+1):
    if R < 0:
        break
    if P < A:
        if (r[C-i-1] >= p[P]):
            if Q < B:
                if (q[Q] >= p[P]):
                    P += 1
                    R -= 1
                elif r[C-i-1] > q[Q]:
                    Q += 1
                    R -= 1
                else:
                    break
            else:
                P += 1
                R -= 1
        elif Q < B:
            if r[C-i-1] > q[Q]:
                Q += 1
                R -= 1
            else:
                break
        else:
            break
    elif Q < B:
        if r[C-i-1] > q[Q]:
            Q += 1
            R -= 1
        else:
            break    
    else:
        break
print(sum(p[P:])+sum(q[Q:])+sum(r[R+1:]))

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x,y,a,b,c = map(int,input().split())
lst_r = list(map(int,input().split()))
lst_g = list(map(int,input().split()))
lst_n = list(map(int,input().split()))
lst_r = sorted(lst_r, reverse=True)[:x]
lst_g = sorted(lst_g, reverse=True)[:y]
lst_all = sorted(lst_r + lst_g + lst_n, reverse=True)[:x+y]
print(sum(lst_all))

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=0
P=[]
for i in range(X):
    P.append(p[i])
    #ans+=p[i]
for i in range(Y):
    P.append(q[i])
    #ans+=q[i]
P.sort()
tmp=0
Q=[]
count=0
for i in range(C):
    if count>=(X+Y):
        break
    if r[i]>P[count]:
        Q.append(r[i])
        count+=1
    else:
        break
R=[]
ans=0
for i in range(len(Q)):
    ans+=Q[i]
for i in range(len(Q),X+Y):
    ans+=P[i]
#print(P)
#print(Q)
print(ans)

Submission status: Accepted

Solution code:
f=lambda:list(map(int,input().split()))
X,Y,*e=f()
P=f()
Q=f()
R=f()
P.sort()
Q.sort()
R.sort()
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=sorted(list(map(int,input().split())))[-x:]
q=sorted(list(map(int,input().split())))[-y:]
r=sorted(list(map(int,input().split())))
s=sorted(p+q+r)[-x-y:]
print(sum(s))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.q = l
        heapq.heapify(self.q)
        return

    def push(self, n):
        heapq.heappush(self.q, n)
        return

    def pop(self):
        return heapq.heappop(self.q)


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    X, Y, A, B, C = Scanner.map_int()
    P = Scanner.map_int()
    Q = Scanner.map_int()
    R = Scanner.map_int()
    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)
    P = P[:X]
    Q = Q[:Y]
    A = P + Q + 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())
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)

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

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

Submission status: Accepted

Solution code:
x, y, a, b, c = map(int, input().split())
pp = list(sorted(map(int, input().split()), reverse=True))[:x]
qq = list(sorted(map(int, input().split()), reverse=True))[:y]
rr = list(map(int, input().split()))

xx = list(sorted(pp + qq + rr, reverse=True))[:x+y]
print(sum(xx))

Submission status: Accepted

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

Alist.sort(reverse = True)
Blist.sort(reverse = True)

for i in range(X):
    list.append(Alist[i])
for i in range(Y):
    list.append(Blist[i])
list.sort(reverse = True)

ans =0
for i in range(X + Y):
    ans += list[i]
    
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)

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

value = sum(apples[:X+Y])
print(value)

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)[a-x:]
q=sorted(q)[b-y:]
p.extend(q)
p.extend(r)
p.sort(reverse=True)
print(sum(p[: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)
rr = [0]
for i in r:
    rr.append(rr[-1]+i)
p = p[:x]
q = q[:y]
pq = sorted(p+q)
ppqq = [sum(pq)]
for i in pq:
    ppqq.append(ppqq[-1]-i)
result = []
for i in range(min(x+y, c+1)):
    result.append(ppqq[i]+rr[i])
print(max(result))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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()
z = p[-x:]
z.extend(q[-y:])
z.extend(r)
z.sort()
#print(z)
print(sum(z[-x-y:]))