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

l = X+Y
lst = []
for i in range(X):
  lst.append(p[i])

for i in range(Y):
  lst.append(q[i])

for i in r:
  lst.append(i)

lst.sort()
lst.reverse()

ans = 0
for i in range(l):
  ans += lst[i]

print(ans)

Submission status: Accepted

Solution code:
X, Y, A, B, C, *PQR = map(int, open(0).read().split())

P = sorted(PQR[:A], reverse=True)
Q = sorted(PQR[A:A + B], reverse=True)
R = sorted(PQR[A + B:], reverse=True)

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

Submission status: Accepted

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


def main():
    x, y, a, b, c = map(int, input().split())
    red_delis = list(map(int, input().split()))
    green_delis = list(map(int, input().split()))
    musyoku_delis = list(map(int, input().split()))

    red_delis.sort(reverse=True)
    green_delis.sort(reverse=True)
    musyoku_delis.sort(reverse=True)

    new_red_delis = red_delis[:x]
    new_green_delis = green_delis[:y]

    return sum(sorted(new_red_delis + new_green_delis + musyoku_delis, reverse=True)[:x + y])


if __name__ == "__main__":
    print(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()
q.sort()
r.sort()
r.reverse()
pp = p[a-x:]
qq = q[b-y:]
ll = pp+qq
ll.sort()
ans = sum(ll)
subll = ll[:c]
rr = r+subll
rr.sort()
subrr = rr[c:]
ans += sum(subrr)-sum(subll)
print(ans)

Submission status: Accepted

Solution code:
f,g=lambda:map(int,input().split()),sorted;x,y,*_=f();print(sum(g(g(f())[-x:]+g(f())[-y:]+g(f()))[-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)[::-1]
q = sorted(q)[::-1]
r = sorted(r)[::-1]
ans = sorted(p[:X] + q[:Y] + r)[::-1]
print(sum(ans[:X + Y]))

Submission status: Accepted

Solution code:
x,y,a,b,c=map(int,input().split())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
cl=list(map(int,input().split()))
al.sort(reverse=True)
bl.sort(reverse=True)
z=al[:x]+bl[:y]+cl
z.sort(reverse=True)
print(sum(z[:x+y]))

Submission status: Accepted

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

a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))

a.sort(reverse=True)
b.sort(reverse=True)

a = a[:x]
b = b[:y]

d = a + b + c
d.sort(reverse=True)

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

Submission status: Accepted

Solution code:
import heapq
X, Y, A, B, C = map(int, input().split())
red = sorted(list(map(int, input().split())), reverse=True)
green = sorted(list(map(int, input().split())), reverse=True)
mu = list(map(int, input().split()))
eat_red = [0]*X
eat_green = [0]*Y
for i in range(X):
    eat_red[i] = red[i]
for i in range(Y):
    eat_green[i] = green[i]
heapq.heapify(eat_red)
heapq.heapify(eat_green)
for i in range(C):
    tmp = mu[i]
    r = heapq.heappop(eat_red)
    g = heapq.heappop(eat_green)
    if r <= g:
        heapq.heappush(eat_green,g)
        heapq.heappush(eat_red,max(tmp,r))
    else:
        heapq.heappush(eat_red,r)
        heapq.heappush(eat_green,max(tmp,g))
print(sum(eat_red)+sum(eat_green))

Submission status: Accepted

Solution code:
def merge(l):
    t = [-1]*len(l)
    if(len(l) == 2):
        if(l[0]<l[1]):
            t[1] = l[0]
            t[0] = l[1]
        else:
            t=l
    elif(len(l) > 2):
        x = merge(l[:len(l)//2])
        y = merge(l[len(l)//2:])
        p,q = 0,0
        for i in range(len(l)):
            if(p<len(x) and q<len(y)):
                if(x[p] > y[q]):
                    t[i] = x[p]
                    p += 1
                else:
                    t[i] = y[q]
                    q += 1
            elif(p == len(x)):
                t[i] = y[q]
                q += 1
            else:
                t[i] = x[p]
                p += 1
    else:
        t = l
    return t
x,y,a,b,c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
a = [x,y,0]
P = merge(p)
Q = merge(q)
R = merge(r)
X = P[:x]
Y = Q[:y]
for i in range(x+y):
    if(a[2] == c):
        break
    elif(a[0] == 0):
        if(Y[a[1]-1] < R[a[2]]):
                a[1] -= 1
                a[2] += 1
        else:
            break
    elif(a[1] == 0):
        if(X[a[0]-1] < R[a[2]]):
                a[0] -= 1
                a[2] += 1
        else:
            break
    else:
        if(X[a[0]-1] > Y[a[1]-1]):
            if(Y[a[1]-1] < R[a[2]]):
                a[1] -= 1
                a[2] += 1
            else:
                break
        else:
            if(X[a[0]-1] < R[a[2]]):
                a[0] -= 1
                a[2] += 1
            else:
                break
m = 0
for i in range(a[0]):
    m += P[i]
for i in range(a[1]):
    m += Q[i]
for i in range(a[2]):
    m += R[i]
print(m)

Submission status: Accepted

Solution code:
X, Y, A, B, C = map(int, input().split())
AA = list(map(int, input().split()))
BB = list(map(int, input().split()))
CC = list(map(int, input().split()))
a = sorted(AA, reverse=True)
b = sorted(BB, reverse=True)
c = sorted(CC, reverse=True)

if X < A:
  del a[X:]

if Y < B:
  del b[Y:]

NEW = a + b + c
NEWnew = sorted(NEW, reverse=True)
del NEWnew[X+Y:]
K = sum(NEWnew)
print(K)

Submission status: Accepted

Solution code:
val = input().split(' ')
x = int(val[0])
y = int(val[1])
a = int(val[2])
b = int(val[3])
c = int(val[4])
 
p_list = sorted([int(a) for a in input().split(' ')])
q_list = sorted([int(a) for a in input().split(' ')])
r_list = sorted([int(a) for a in input().split(' ')])
p_list.reverse()
q_list.reverse()
r_list.reverse()
 
xapples = p_list[0:x]
yapples = q_list[0:y]
zapples = r_list[0:x+y]
 
xapples.extend(yapples)
xapples.extend(zapples)
tmp_apples = sorted(xapples)
tmp_apples.reverse()
apples = tmp_apples[0:x+y]
print(sum(apples))

Submission status: Accepted

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

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

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

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

p_i = 0
q_i = 0

for ri in R:
    if p_i >= len(P) and q_i >= len(Q):
        break
    if p_i >= len(P):
        if ri >= Q[q_i]:
            Q[q_i] = ri
            q_i += 1
    elif q_i >= len(Q):
        if ri >= P[p_i]:
            P[p_i] = ri
            p_i += 1
    elif ri < P[p_i] and ri < Q[q_i]:
        break
    elif ri > P[p_i] and ri > Q[q_i]:
        d1 = ri - P[p_i]
        d2 = ri - Q[q_i]
        if d1 > d2:
            P[p_i] = ri
            p_i += 1
        else:
            Q[q_i] = ri
            q_i += 1
    elif ri > P[p_i] and ri < Q[q_i]:
        P[p_i] = ri
        p_i += 1
    else:
        Q[q_i] = ri
        q_i += 1


# print(P, Q)
ans = sum(P) + sum(Q)
print(ans)

Submission status: Accepted

Solution code:
def main():
    X,Y,A,B,C = map(int,input().split())
    R = [int(i) for i in input().split()]
    G =  [int(i) for i in input().split()]
    N =  [int(i) for i in input().split()]
    R.sort(reverse=True)
    G.sort(reverse=True)
    N.sort(reverse=True)
    E = R[:X] + G[:Y] + N
    E.sort(reverse=True)
    print(sum(E[:(X+Y)]))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
f=lambda:map(int,input().split());x,y,*_=f();g=sorted;print(sum(g(g(f())[-x:]+g(f())[-y:]+list(f()))[-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_use = p[:X]
q_use = q[:Y]
r_use = r[:]
p_use.extend(q_use)
p_use.extend(r_use)
total = p_use[:]
total.sort(reverse=True)
total_use = total[:X+Y]
sum = 0
for i in range(len(total_use)):
    sum += total_use[i]
print(sum)

Submission status: Accepted

Solution code:
from collections import deque

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 = deque(p[0:x])
q = deque(q[0:y])
r = deque(r)


while len(r) != 0 and min(p[-1],q[-1]) < r[0]:
  if p[-1] < q[-1]:
    p.appendleft(r.popleft())
    p.pop()
  else:
    q.appendleft(r.popleft())
    q.pop()
    
print(sum(p)+sum(q))

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

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

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

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

Submission status: Accepted

Solution code:
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.sort()
    q.sort()
    r.sort()
    
    Q = p[A-X:] + q[B-Y:] + r
    Q.sort(reverse=True)
    ans = sum(Q[:X+Y])

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
x,y,a,b,c=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort(reverse=True)
A.sort()
B.sort()
A=A[a-x:]
B=B[b-y:]
D=A+B+C
D.sort(reverse=True)
sum=0
for i in range(x+y):
    sum+=D[i]
print(sum)

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)

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

ans = sum(X[: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)

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,red,green,cl = map(int,input().split())
r = sorted(list(map(int,input().split())))[::-1]
g = sorted(list(map(int,input().split())))[::-1]
c = sorted(list(map(int,input().split())))[::-1]
s = sorted(r[:a]+g[:b]+c)[::-1]
print(sum(s[:a+b]))

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)
answer=p[:X]+q[:Y]
sum=0
answer=sorted(answer)
i=0

while i<=min(X+Y-1,C-1) and answer[i]<r[i]:
    answer[i]=r[i]
    i+=1

for a in answer:
    sum+=a

print(sum)

Submission status: Accepted

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

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

ans = deque(maxlen=(x+y))

def insertion(z):
	global x,y
	if z == p:
		x -= 1
	else:
		y -= 1
	return ans.append(z.pop())

while x > 0 or y > 0:
	if x and y:
		if p[-1] > q[-1] :
			insertion(p)
		else:
			insertion(q)
	elif not x:
		insertion(q)
	else:
		insertion(p)

while r:
	if ans[-1] < r[-1]:
		ans.appendleft(r.pop())
	else:
		break

print(sum(ans))

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a,b,X,Y,Z = inpl()
x = sorted(inpl(), reverse = True)
y = sorted(inpl(), reverse = True)
z = sorted(inpl(), reverse = True)
x = x[:a]
y = y[:b]
apples = x + y + z
apples.sort(reverse = True)
print(sum(apples[:a+b]))

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.extend(p)
r.extend(q)
r.sort(reverse=True)
ans = 0
for i in range(X+Y):
    ans += r[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()))
tmp=sorted(p)
P=tmp[::-1]
tmp=sorted(q)
Q=tmp[::-1]
tmp=sorted(r)
R=tmp[::-1]
tmp=P[:X]+Q[:Y]+R
tmp=sorted(tmp)
tmp=tmp[::-1]
ans=sum(tmp[:X+Y])
print(ans)

Submission status: Accepted

Solution code:
X,Y,A,B,C = map(int, raw_input().split())
P = map(int, raw_input().split())
Q = map(int, raw_input().split())
R = map(int, raw_input().split())
 
Ps = sorted(P, reverse=True)
Qs = sorted(Q, reverse=True)
Rs = sorted(R, reverse=True)

Z = sorted(Ps[:X] + Qs[:Y] + Rs ,reverse=True)
print sum(Z[:X+Y])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import heapq

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

    p = sorted(p)[a-x:]
    q = sorted(q)[b-y:]

    r = sorted(r)

    while(len(r)>0):
        r_ = heapq.heappop(r)
        if r_-p[0]>=0 or r_-q[0]>=0:
            if r_-p[0]>r_-q[0]:
                heapq.heappop(p)
                heapq.heappush(p,r_)
            else:
                heapq.heappop(q)
                heapq.heappush(q,r_)

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

if __name__ == "__main__":
    main()

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


resolve()

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]

gocha=sorted(p+q+r, reverse=True)
#print(p,q,r,gocha)
print(sum(gocha[:(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)
lis=p[:x]+q[:y]+r
lis.sort(reverse=True)
ans=0
for i in range(x+y):
  ans+=lis[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()
q.sort()
p.reverse()
q.reverse()
p=p[:X]
q=q[:Y]
 
a=p[:]
a.extend(q)
a.extend(r)
a.sort()
a.reverse()
sum=0
for i in range(X+Y):
  sum+=a[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()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p = p[:x]
q = q[:y]
ap = p + q + r
ap.sort(reverse=True)
print(sum(ap[:x+y]))

Submission status: Accepted

Solution code:
def main():
  X, Y, A, B, C  = map(int, input().split())
  aka_list = sorted([int(t) for t in input().split()],reverse=True)[:X]
  midori_list = sorted([int(t) for t in input().split()],reverse=True)[:Y]
  mu_list = sorted([int(t) for t in input().split()],reverse=True)
  
  sum_list = sorted(aka_list + midori_list + mu_list ,reverse=True)[:X+Y]
  print(sum(sum_list))

main()

Submission status: Accepted

Solution code:
(X,Y,*e),*l=[list(map(int,input().split()))for _ in[0]*4]
s=sorted
P,Q,R=map(s,l)
print(sum(s(P[-X:]+Q[-Y:]+R)[-X-Y:]))

Submission status: Accepted

Solution code:
x,y,a,b,c=map(int,input().split())
re=list(map(int,input().split()))
gr=list(map(int,input().split()))
mu=list(map(int,input().split()))
re.sort(reverse=1)
gr.sort(reverse=1)
mu.sort(reverse=1)
re=re[:x]
gr=gr[:y]
app=mu[:]
app.extend(re)
app.extend(gr)
app.sort(reverse=1)
app=app[:x+y]


print(sum(app))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import deque
readline = sys.stdin.readline

def main():
  x,y,a,b,c=map(int,readline().split())

  red=[int(i) for i in readline().split()]
  green=[int(i) for i in readline().split()]
  nc=sorted([int(i) for i in readline().split()], reverse=1)
  if a<x:
    red+=nc[:(x-a)]
    nc=nc[(x-a):]
  if b<y:
    green+=nc[:(y-b)]
    nc=nc[(y-b):]
  red=deque(sorted(red)[-x:])
  green=deque(sorted(green)[-y:])
  res=0
  
  def ppl(lst,i,t):
    if i>t:
      lst.popleft()
      return i
    else:
      return 0
    
  for i in nc:
    if (not red) and (not green):
      break
    if not red:
      tg=green[0]
      res+=ppl(green,i,tg)
    elif not green:
      tr=red[0]
      res+=ppl(red,i,tr)
    else:
      tr=red[0]
      tg=green[0]
      if tr<tg:
        res+=ppl(red,i,tr)
      else:
        res+=ppl(green,i,tg)
    
  print(res+sum(red)+sum(green))

main()

Submission status: Accepted

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

pa.sort(reverse=True)
qb.sort(reverse=True)
rc.sort(reverse=True)

pa = pa[:x]
qb = qb[:y]

_all = rc + pa + qb
_all.sort(reverse=True)

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

print(ans)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
x, y, a, b, c = nm()
p = nl()
q = nl()
r = nl()
p.sort()
q.sort()
l = p[-x:] + q[-y:]
l.sort()
r.sort()
for i in range(c):
    if l[i] < r[-1]:
        l[i] = r.pop()
    else:
        break
print(sum(l))

Submission status: Accepted

Solution code:
x, y, a, b, c = map(int,input().split())
red = sorted(list(map(int,input().split())),reverse=True)[:x]
green = sorted(list(map(int,input().split())),reverse=True)[:y]
white = sorted(list(map(int,input().split())),reverse=True)

l = sorted(red+green+white,reverse=True)[:x+y]
print(sum(l))

Submission status: Accepted

Solution code:
(X,Y,*e),*l=[list(map(int,input().split())) for _ in [0]*4]
s=sorted
P,Q,R=map(s,l)
print(sum(s(P[-X:]+Q[-Y:]+R)[-X-Y:]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X, Y, A, B, C = [int(i) for i in input().split()]
reds = sorted([int(i) for i in input().split()], reverse=True)
greens = sorted([int(i) for i in input().split()], reverse=True)
clears = sorted([int(i) for i in input().split()], reverse=True)

clear_acc = [0]

for i in clears:
    clear_acc.append(clear_acc[-1]+i)
        
reds = reds[:X]
greens = greens[:Y]

all_apples = sorted(reds+greens)

apple_sum = [sum(all_apples)]


for i in all_apples:
    apple_sum.append(apple_sum[-1]-i)
    

output = []

for i in range(min(X+Y, C+1)):
    output.append(apple_sum[i] + clear_acc[i])

print(max(output))

Submission status: Accepted

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

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]
R = sorted(P+Q+R, reverse=True)[:X+Y]

print(sum(R))

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
x, y, a, b, c = map(int, input().split())
p_list = list(map(int, input().split()))
p_list.sort(reverse=True)
q_list = list(map(int, input().split()))
q_list.sort(reverse=True)
r_list = list(map(int, input().split()))
r_list.sort(reverse=True)
p_list = p_list[0:x]
q_list = q_list[0:y]
p_count = 0
q_count = 0
r_count = 0
total = 0
for i in range(x + y):
    score_max = 0
    flag = 0
    if p_count < x:
        score = p_list[p_count]
        if score_max < score:
            score_max = score
            flag = 1
    if q_count < y:
        score = q_list[q_count]
        if score_max < score:
            score_max = score
            flag = 2
    if r_count < c:
        score = r_list[r_count]
        if score_max < score:
            score_max = score
            flag = 3
    if flag == 1:
        p_count += 1
    elif flag == 2:
        q_count += 1
    else:
        r_count += 1
    total += score_max
print(total)

Submission status: Accepted

Solution code:
x,y,a,b,c=map(int,input().split())
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[:x]
q=q[: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())
red = list(map(int,input().split()))
green = list(map(int,input().split()))
non = list(map(int,input().split()))


red_trunc = sorted(red,reverse=True)[:x]
green_trunc = sorted(green,reverse=True)[:y]
# print(red_trunc)
# print(green_trunc)
total = non + red_trunc + green_trunc
total = sorted(total, reverse=True)
print(sum(total[:x+y]))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
X,Y,A,B,C=map(int,input().split())
p=input().split()
P=[int(a) for a in p]
q=input().split()
Q=[int(a) for a in q]
r=input().split()
R=[int(a) for a in r]
P=sorted(P,reverse=True)
P=P[:X]
Q=sorted(Q,reverse=True)
Q=Q[:Y]
answers=P+Q+R
answers=sorted(answers,reverse=True)
answers=answers[:(X+Y)]
print(sum(answers))

Submission status: Accepted

Solution code:
X,Y,A,B,C = [int(i.strip()) for i in input().split(' ')]
p = [int(i.strip()) for i in input().split(' ')]
q = [int(i.strip()) for i in input().split(' ')]
r = [int(i.strip()) for i in input().split(' ')]

pd = sorted(p, reverse=True)
RED = pd[:X]
qd = sorted(q,reverse=True)
GREEN = qd[:Y]

ALL = r + RED +GREEN

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

ans = sum(r[:x + y])
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import collections
from collections import deque
#x = int(input())
x, y, A, B, C = map(int, sys.stdin.readline().split())
#s = input()

a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
c = list(map(int, sys.stdin.readline().split()))

a.sort(reverse = True)
b.sort(reverse = True)

for i in range(x):
    c.append(a[i])

for i in range(y):
    c.append(b[i])

c.sort(reverse = True)
ans = 0
for i in range(x+y):
    ans += c[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()))
tmp = 0
p.sort(reverse=True)
p.append(0)
q.sort(reverse=True)
q.append(0)
r.sort(reverse=True)
r.append(0)
z = X+Y
e, f, g = 0, 0, 0
for i in range(z):
    if X>0 and ((p[e]>=q[f] and p[e]>=r[g]) or (Y==0 and p[e]>=r[g])):
        tmp = tmp+p[e]
        e += 1
        X -= 1
    elif Y>0 and ((q[f]>=p[e] and q[f]>=r[g]) or (X==0 and q[f]>=r[g])):
        tmp = tmp+q[f]
        f += 1
        Y -= 1
    elif r[g]>p[e] or r[g]>q[f]:
        tmp = tmp+r[g]
        g += 1
        
print(tmp)

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()))
s = X + Y
R.sort(reverse=True)
P.sort(reverse=True)
Q.sort(reverse=True)

Z = P[:X]+Q[:Y]+R
Z.sort(reverse=True)
w = 0
for i in range(s):
    w += Z[i]
print(w)

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)

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

l = n_p +n_q +r
l.sort(reverse=True)

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

print(ans)

Submission status: Accepted

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

(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）を美味しい順にX個だけにする
sorted_P = sorted(P, reverse=True)
delicious_P = sorted_P[:X]

# 緑色のリンゴ（Q）を美味しい順にY個だけにする
sorted_Q = sorted(Q, reverse=True)
delicious_Q = sorted_Q[:Y]

# 残ったリンゴと無色のリンゴを美味しい順に並べてX+Y個取る
# つまり赤と緑の残ったリンゴの美味しくない物から順に無色のリンゴに置き換わる
apples = delicious_P + delicious_Q + R
sorted_apples = sorted(apples, reverse=True)
remaining = sorted_apples[:X+Y]
print(sum(remaining))

Submission status: Accepted

Solution code:
mod = 10**9 + 7

def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <=0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n-r+1, n+1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r+1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        #print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

#####################################################ライブラリ集ここまで

def main():
    X, Y, A, B, C = iip()
    p = iip(listed=True)
    p.extend([0 for i in range(10**6)])
    q = iip(listed=True)
    q.extend([0 for i in range(10**6)])
    r = iip(listed=True)

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

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

    ir = 0
    ib = 0
    for nocolor in r:
        if min(red[ir], blue[ib]) < nocolor:
            if red[ir] < blue[ib]:
                red[ir] = nocolor
                if ir <= len(red)-2:
                    ir += 1
            else:
                blue[ib] = nocolor
                if ib <= len(blue)-2:
                    ib +=1
        else:
            break

    print(sum(red)+sum(blue))



    pass

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
x, y, a, b, c = list(map(int, input().split()))
ppp = list(map(int, input().split()))
qqq = list(map(int, input().split()))
rrr = list(map(int, input().split()))
ppp.sort(reverse=True)
qqq.sort(reverse=True)
ppqq = ppp[:x] + qqq[:y]
ppqq.extend(rrr)
ppqq.sort(reverse=True)
print(sum(ppqq[:x + y]))