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:
# 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)
q = sorted(q, reverse=True)
r = sorted(r, reverse=True)

p = [[value, "r"] for value in p]
q = [[value, "g"] for value in q]
r = [[value, "s"] for value in r]

pqr = p + q + r
pqr = sorted(pqr, key=lambda x: x[0], reverse=True)

n_rgs = {"r": 0, "g": 0, "s": 0}

for val, color in pqr:
    n_rgs[color] += 1

    if min(n_rgs["r"], X) + min(n_rgs["g"], Y) + n_rgs["s"] == X+Y:
        break

ans = 0
for val, _ in p[:min(n_rgs["r"], X)]:
    ans += val
for val, _ in q[:min(n_rgs["g"], Y)]:
    ans += val
for val, _ in r[:n_rgs["s"]]:
    ans += val

print(ans)

Submission status: Accepted

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

P = sorted(P,reverse = True)
Q = sorted(Q,reverse = True)
R = sorted(R,reverse = True)

ans = 0
l = []

for i in range(X):
    l.append(P[i])
for j in range(Y):
    l.append(Q[j])
    
l = sorted(l)


for k in range(C):
    if R[k] > l[k]:
        l[k] = R[k]
    else:
        break

print(sum(l))

Submission status: Accepted

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

AList=list(map(int,input().split()))
BList=list(map(int,input().split()))
CList=list(map(int,input().split()))

AList.sort(reverse=True)
BList.sort(reverse=True)
CList.sort(reverse=True)

alist = AList[0:X] + BList[0:Y] + CList
alist.sort(reverse=True)

print(int(sum(alist[:X+Y])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import heapq
 
x, y, a, b, c = map(int, input().split())
 
def max_listup(limit):
  l = sorted(list(map(int, input().split())))
  cnt = 1
  res = []
  while l:
    if cnt > limit:
      break
    m = l.pop()
    res.append(m)
    cnt += 1
  return res

all = sorted(max_listup(x) + max_listup(y) + list(map(int, input().split())))
ans = 0
for _ in range(x+y):
  ans += all.pop()

print(ans)

Submission status: Accepted

Solution code:
import heapq

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

def max_listup(limit):
  l = sorted(list(map(int, input().split())))
  cnt = 1
  res = []
  while l:
    if cnt > limit:
      break
    m = l.pop()
    res.append(m)
    cnt += 1
  return res

if __name__ == "__main__":
  all = sorted(max_listup(x) + max_listup(y) + list(map(int, input().split())))
  ans = 0
  for _ in range(x+y):
    ans += all.pop()

  print(ans)

Submission status: Accepted

Solution code:
import heapq

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

def max_listup(limit):
  l = list(map(lambda x:int(x)*-1, input().split()))
  heapq.heapify(l)
  cnt = 1
  res = []
  while l:
    if cnt > limit:
      break
    m = heapq.heappop(l)
    res.append(m*-1)
    cnt += 1
  return res

if __name__ == "__main__":
  all = sorted(max_listup(x) + max_listup(y) + list(map(int, input().split())))
  ans = 0
  for _ in range(x+y):
    ans += all.pop()

  print(ans)

Submission status: Accepted

Solution code:
#heapqすら使わなくても良い
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)

#ansは小さい順、rは大きい順
for i in range(x+y):
    if len(r)==i or r[i]<ans[i]:
        break
    else:
        ans[i]=r[i]
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)

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
 
i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

x,y,a,b,c = i_l()
p = i_l()
q = i_l()
r = i_l()

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

Submission status: Accepted

Solution code:
X,Y,A,B,C=map(int,input().split())
P=sorted([int(x) for x in input().split()])
Q=sorted([int(x) for x in input().split()])
R=sorted([int(x) for x in input().split()])

final=sorted(P[A-X:]+Q[B-Y:]+R,reverse=True)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

A = A[0:X]
B = B[0:Y]
D = A+B+C

D.sort(reverse=True)

D = D[0:X+Y]
print(sum(D))

Submission status: Accepted

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

p=A-X
q=B-Y

final=sorted(P[p:]+Q[q:])

ans=sum(final)

i=0

for item in R:
	if item > final[i]:
		ans-=final[i]
		ans+=item
		i+=1

print(ans)

Submission status: Accepted

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

Pi.sort()
Qi.sort()
Ri.sort(reverse=True)


#Ri
#for i in range(X,)
r=0
p=A-X
q=B-Y
while(r<C):
  if(p>=A and q>=B):
    break
  elif(p>=A):
    #qi
    if(Qi[q]>=Ri[r]):
      break;
    else:
      Qi[q]=Ri[r]
      q+=1
  elif(q>=B):
    #pi
    if(Pi[p]>=Ri[r]):
      break;
    else:
      Pi[p]=Ri[r]
      p+=1
  elif(Pi[p]>=Qi[q]):
    #qi
    if(Qi[q]>=Ri[r]):
      break;
    else:
      Qi[q]=Ri[r]
      q+=1
  elif(Pi[p]<Qi[q]):
    #pi
    if(Pi[p]>=Ri[r]):
      break;
    else:
      Pi[p]=Ri[r]
      p+=1
  elif(Pi[p]>=Ri[r] and Qi[q]>=Ri[r]):
    break
  
  r+=1

psum=sum(Pi[A-X:A])
qsum=sum(Qi[B-Y:B])


happy = psum + qsum

print(happy)

Submission status: Accepted

Solution code:
X,Y,A,B,C=map(int,input().split())
D=[sorted(int(x) for x in input().split()) for _ in range(3)]

print(sum(sorted(D[0][-X:]+D[1][-Y:]+D[2])[-(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.reverse()
q.sort()
q.reverse()
r.sort()
r.reverse()
total=[]
for i in range(X):
    total.append(p[i])
for i in range(Y):
    total.append(q[i])
for i in range(C):
    total.append(r[i])
total.sort()
total.reverse()
ans=0
for i in range(X+Y):
    ans+=total[i]
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]

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.append(float('inf'))
# q.append(float('inf'))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
ans=0
p=p[:x]
q=q[:y]
anslst=p+q+r
anslst.sort(reverse=True)
print(sum(anslst[:x+y]))

Submission status: Accepted

Solution code:
X,Y,A,B,C=map(int,input().split())
import numpy as np
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
R=list(map(int,input().split()))
Xa=np.array(P+Q+R)
Ya=np.array([i for i,j in enumerate([A,B,C]) for k in range(j)])
x = np.argsort(Xa)
Xa=Xa[x]
Xa=Xa[::-1]
Ya=Ya[x]
Ya=Ya[::-1]
ans=0
N=0
nokori=[X,Y]
for i in range(A+B+C):
  if Ya[i]==2:
    N+=1
    ans+=Xa[i]
  elif nokori[Ya[i]]>0:
    nokori[Ya[i]]-=1
    ans+=Xa[i]
  if sum(nokori)==N:
    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)
P=p[0:X]
Q=q[0:Y]
N=P+Q+r
N.sort(reverse=True)
print(sum(N[0:(X+Y)]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding:utf-8
x, y, a, b, c = map(int, input().split())
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]
p.sort(reverse = True)
q.sort(reverse = True)

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

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

ans = 0

for i in range(x + y):
  ans += p[i]
  
print("{}".format(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)

num = []
n1 = 0
n2 = 0
n3 = 0
flg_0 = False
flg_1 = False
flg_2 = False
for i in range(x+y):
    if flg_0 is False:
        u = p[min(a-1, n1)]
    else:
        u = 0
    if flg_1 is False:
        uu = q[min(b-1, n2)]
    else:
        uu = 0
    if flg_2 is False:
        uuu = r[min(c-1, n3)]
    else:
        uuu = 0
    if max(u, uu, uuu) == u:
        num.append(u)
        n1 += 1
    elif max(u, uu, uuu) == uu:
        num.append(uu)
        n2 += 1
    else:
        num.append(uuu)
        n3 += 1
    if n1 >= x:
        flg_0 = True
    if n2 >= y:
        flg_1 = True
    if n3 >= c:
        flg_2 = True
    if (n1 + n2 + n3) == (x + y):
        break

print(sum(num))

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

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

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify

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

PA = list(map(int, input().split()))
PB = list(map(int, input().split()))
PC = list(map(int, input().split()))

PA.sort(reverse=True)
PB.sort(reverse=True)

heap = []
heapify(heap)

for a in PA[:X]:
    heappush(heap, -a)

for a in PB[:Y]:
    heappush(heap, -a)

for a in PC:
    heappush(heap, -a)

cnt = 0
sum_ = 0
while cnt < X + Y:
    val = heappop(heap)
    sum_ += val * -1

    cnt += 1


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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)

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

pi = [int(i) for i in input().split()]
qi = [int(i) for i in input().split()]
ri = [int(i) for i in input().split()]

pi.sort(reverse=True)
qi.sort(reverse=True)
ri.sort(reverse=True)

import heapq
"""
a = [3,0,2,6]
#listのheap化
#heapはsortではないので順番は割とあべこべになる。最小値は先頭
heapq.heapify(a)
print(a)

#挿入
heapq.heappush(a,3)
print(a)

#最小値を削除&出力
print(heapq.heappop(a))
print(a)
"""
apple = []

for i in range(x):
    heapq.heappush(apple,pi[i])
    
for i in range(y):
    heapq.heappush(apple,qi[i])
    
for i in range(c):
    tmp = heapq.heappop(apple)
    if tmp < ri[i]:
        heapq.heappush(apple,ri[i])
    else:
        heapq.heappush(apple,tmp)
        
print(sum(apple))

Submission status: Accepted

Solution code:
import heapq

def main():
    x, y, a, b, c = map(int, input().split())
    p = sorted(list(map(int, input().split())))
    p = [p[i] for i in range(-x, 0)]
    q = sorted(list(map(int, input().split())))
    q = [q[i] for i in range(-y, 0)]
    r = sorted(list(map(int, input().split())), reverse=True)
    for i in range(c):
        red = heapq.heappop(p)
        green = heapq.heappop(q)
        if r[i] <= red and r[i] <= green:
            heapq.heappush(p, red)
            heapq.heappush(q,green)
            break
        else:
            if r[i] - red >= r[i] - green:
                heapq.heappush(p, r[i])
                heapq.heappush(q,green)
            else:
                heapq.heappush(q, r[i])
                heapq.heappush(p, red)
    print(sum(p)+sum(q))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate
import heapq
x, y, a, b, c = [int(i) for i in sys.stdin.readline().split()]
ps = [int(i) for i in sys.stdin.readline().split()]
qs = [int(i) for i in sys.stdin.readline().split()]
rs = [int(i) for i in sys.stdin.readline().split()]
ls = []
for p in ps:
    heapq.heappush(ls, (-p, 0))
for q in qs:
    heapq.heappush(ls, (-q, 1))
for r in rs:
    heapq.heappush(ls, (-r, 2))
ans = 0
cnt = 0
x_cnt = 0
y_cnt = 0
while cnt < x + y:
    item = heapq.heappop(ls)
    if item[1] == 2:
        ans -= item[0]
        cnt += 1
    elif item[1] == 0:
        if x_cnt >= x:
            continue
        else:
            x_cnt += 1
            cnt += 1
            ans -= item[0]
    else:
        if y_cnt >= y:
            continue
        else:
            y_cnt += 1
            cnt += 1
            ans -= item[0]
print(ans)

Submission status: Accepted

Solution code:
# E - Red and Green Apples
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]+r
l.sort(reverse=True)
print(sum(l[: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)
tmp=[]
for i in range(x):
    tmp.append(p[i])

for j in range(y):
    tmp.append(q[j])

for k in range(len(r)):
    tmp.append(r[k])

tmp.sort(reverse=True)
ans=0
for i in range(x+y):
    ans+=tmp[i]

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

Submission status: Accepted

Solution code:
import sys
import math
import numpy

x , y , a , b , c = map(int,input().split())
pa = list(map(int,input().split()))
pb = list(map(int,input().split()))
pc = list(map(int,input().split()))

pa.sort()
pb.sort()
pc.sort()

if x <= a:
    pa = pa[a-x::]
    a = x
if y <= b:
    pb = pb[b-y::]
    b = y
if x+y <= c:
    # print(c-x+y)
    pc = pc[(c-(x+y))::]
    c = x+y

ain = 0
bin = 0
cin = 0

total = 0
for times in range(x+y):
    if ain < a:
        ta = pa[a-1 - ain ]
    else:
        ta = 0
    
    if bin < b :
        tb = pb[b-1 - bin]
    else:
        tb = 0
    
    if cin < c:
        tc = pc[c-1 - cin]
    else:
        tc = 0
    
    if tb <= ta and tc <= ta:
        total += ta
        ain += 1
    elif ta <= tb and tc <= tb:
        total += tb
        bin += 1
    elif ta <= tc and tb <= tc:
        total += tc
        cin += 1
    else:
        print("error")

print(total)

Submission status: Accepted

Solution code:
from collections import deque

X,Y,A,B,C = map(int,input().split())
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]

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

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

print(sum(s))

Submission status: Accepted

Solution code:
# N = int(input())
# N = map(int,input().split())
# N = list(map(int,input().split()))


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

P = sorted(P,reverse=True)
Q = sorted(Q,reverse=True)
R = sorted(R,reverse=True)
P = P[:X]
Q = Q[:Y]
P.append(-100)
Q.append(-100)
R.append(-100)

ans = sum(P)+sum(Q)

p=0
q=0
r=0

x = 0
y = 0

ans = 0
while(x<=X or y<=Y):
    mm = max(P[p],Q[q],R[r])
    if R[r] == mm:
        ans += R[r]
        r+=1
    elif P[p]==mm:
        ans += P[p]
        p+=1
        x+=1
    elif Q[q]==mm:
        ans += Q[q]
        q+=1
        y+=1
    if (x+y+r)==(X+Y):
        break
    # print(p,q,r)

print(ans)

# print(p,q,r)

Submission status: Accepted

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

p_dat = list(map(int, input().split()))
q_dat = list(map(int, input().split()))
r_dat = list(map(int, input().split()))

p_max_list = sorted(p_dat, reverse=True)
p_max_list = p_max_list[0:X]
q_max_list = sorted(q_dat, reverse=True)
q_max_list = q_max_list[0:Y]

join_list = p_max_list + q_max_list + r_dat
join_list = sorted(join_list, reverse=True)
join_list = join_list[0:(X+Y)]

print(sum(join_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()))
p.sort()
q.sort()
ans=[]
for i in range(X):
    a=i+1
    ans.append(p[-a])
for i in range(Y):
    a=i+1
    ans.append(q[-a])
for i in r:
    ans.append(i)
ans.sort()
Ans=0
for i in range(X+Y):
    a=i+1
    Ans+=ans[-a]
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)

pqr = []

for i in range(x):
    pqr.append(p[i])
for i in range(y):
    pqr.append(q[i])
for i in range(c):
    pqr.append(r[i])

pqr.sort(reverse=True)

delicious = 0
for i in range(x+y):
    delicious += pqr[i]

print(delicious)

Submission status: Accepted

Solution code:
import sys
import numpy as np
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
X, Y, A, B, C = [int(x) for x in input().strip().split()]
p = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:X]
q = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:Y]
r = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:min(C, X+Y)]

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p = sorted(p, reverse=True)[:X]
q = sorted(q, reverse=True)[:Y]
t = sorted(p+q+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)

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

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

Submission status: Accepted

Solution code:
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)
pp = p[:x]
qq = q[:y]
if x+y <= c:
  rr = r[:(x+y)]
else:
  rr = r
ppqqrr = pp + qq + rr
ppqqrr.sort(reverse = True)
print(sum(ppqqrr[: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]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
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()))

PQ = [(p,0) for p in P] + [(q,1) for q in Q]
PQ.sort(key=lambda x:x[0])
R.sort()
x=0
y=0
z=0
ans = 0
while x+y+z < X+Y:
    if R and PQ[-1][0] < R[-1]:
        ans += R.pop()
        z+=1
    else:
        tmp, label = PQ.pop()
        if label == 0 and x < X:
            ans+=tmp
            x+=1
        elif label == 1 and y < Y:
            ans+=tmp
            y+=1

print(ans)

Submission status: Accepted

Solution code:
# input
X, Y, A, B, C = map(int, input().split())
P = [int(x) for x in input().split()]
Q = [int(x) for x in input().split()]
R = [int(x) for x in input().split()]

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

def eat(idx):
    p = -1 if idx[0] == X else P[idx[0]]
    q = -1 if idx[1] == Y else Q[idx[1]]
    r = -1 if idx[2] == C else R[idx[2]]

    if p > q:
        if p > r:
            idx[0] += 1
            return p 
        else:
            idx[2] += 1
            return r
    else:
        if q > r:
            idx[1] += 1
            return q
        else:
            idx[2] += 1
            return r

ans = 0
idx = [0, 0, 0]
while True:
    ans += eat(idx)
    if sum(idx) == X+Y:
        break

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

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

print(sum(pqr))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import numpy as np
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
X, Y, A, B, C = [int(x) for x in input().strip().split()]
p = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:X]
q = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:Y]
r = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:min(C, X+Y)]

pq = np.hstack((p, q))
pq.sort()
ri = 0
for i, t in enumerate(pq):
    if t < r[ri]:
        pq[i] = r[ri]
        ri += 1
    if ri == len(r):
        break
print(sum(pq))

Submission status: Accepted

Solution code:
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort()
p.reverse()
q.sort()
q.reverse()
r.sort()
r.reverse()
xp,yq = p[:X],q[:Y]
xp.extend(yq)
xp.extend(r)
xp.sort()
xp.reverse()
print(sum(xp[:(X+Y)]))

Submission status: Accepted

Solution code:
#abc.py
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= list(map(int,input().split()))
P=P[0:X]
Q=Q[0:Y]
R.extend(P)
R.extend(Q)
R=sorted(R,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
x,y,a,b,c=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
arr3=list(map(int,input().split()))
arr1.sort(reverse=True)
arr2.sort(reverse=True)
sum=0
for i in range(x):
    arr3.append(arr1[i])
for j in range(y):
    arr3.append(arr2[j])
arr3.sort(reverse=True)
for k in range(x+y):
    sum+=arr3[k]
print(sum)

Submission status: Accepted

Solution code:
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial,hypot
#import sys
#from fractions import gcd
setrecursionlimit(10**6+1)
input=stdin.readline

def main():
    x,y,a,b,c=map(int,input().split())
    p=sorted([int(i) for i in input().split()],reverse=1)[:x]
    q=sorted([int(i) for i in input().split()],reverse=1)[:y]
    r=[int(i) for i in input().split()]
    print(sum(sorted(p+q+r,reverse=1)[:x+y]))

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
X,Y,A,B,C = list(map(int, input().split()))
P = sorted(list(map(int, input().split())))[-X:]
Q = sorted(list(map(int, input().split())))[-Y:]
R = list(map(int, input().split()))

total = sorted(P + Q + R)[-X-Y:]
print(sum(total))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,y,a,b,c=map(int,input().split())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
R=list(map(int,input().split()))
P.sort(reverse=True)
P=P[:x]
Q.sort(reverse=True)
Q=Q[:y]
P=P+Q
P.sort()
R.sort(reverse=True)
for i in range(min(x+y,c)):
    if P[i]<R[i]:
        P[i]=R[i]
    else:
        break
print(sum(P))

Submission status: Accepted

Solution code:
#E red and green apples

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)

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

for i in range(c):
    if r[i] > ans1[i]:
        ans1[i] = r[i]
    else:
        break

print(sum(ans1))

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

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

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

def cumsum(lst): #元のリストを保持
    res = lst[:]
    for i in range(1,len(res)):
        res[i] += res[i-1]
    return res
cum_p = cumsum(p)
cum_q = cumsum(q)
ans = 0
for i in range(max(0,a-c),a+1): #赤色りんごの個数制限
    if i == 0:
        ans = max(ans,cum_q[x+y-i-1])
    else:
        ans = max(ans,cum_p[i-1] + cum_q[x+y-i-1])

print(ans)

Submission status: Accepted

Solution code:
x, y, a, b, c = map(int,input().split())
datp = sorted(list(map(int, input().split())), reverse=True)
datq = sorted(list(map(int, input().split())), reverse=True)
datr = sorted(list(map(int, input().split())), reverse=True)
dat = sorted(datp[:x] + datq[:y] + datr, reverse=True)
print(sum(dat[:x+y]))

Submission status: Accepted

Solution code:
# coding: utf-8

# 標準入力 <int><int>
X, Y, A, B, C = map(int, input().split())

# 標準入力 <int> list[]
p = sorted([int(i) for i in input().split()])
q = sorted([int(i) for i in input().split()])
r = sorted([int(i) for i in input().split()])

l = p[A - X:] + q[B - Y:] + r

print(sum(sorted(l)[(X+Y) * -1:]))

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=[]
apples.extend(p[:x])
apples.extend(q[:y])
apples.extend(r)

apples.sort(reverse=True)

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

Submission status: Accepted

Solution code:
X,Y,A,B,C=map(int,input().split())
p=sorted([int(p) for p in input().split()])[-X:]
q=sorted([int(q) for q in input().split()])[-Y:]
r=[int(r) for r in input().split()]
lst=sorted(p+q+r)
print(sum(lst[-(X+Y):]))