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: Wrong Answer

Solution code:
from collections import deque

x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort()
q.sort()
r.sort(reverse=True)
xlis = deque(p[len(p)-x:])
ylis = deque(q[len(q)-y:])
r = deque(r)
while True:
    if len(r) == 0:
        break
    xs = xlis.popleft()
    ys = ylis.popleft()
    rm = r.popleft()
    if rm < xs and rm < ys:
        xlis.append(xs)
        ylis.append(ys)
        break
    elif xs < ys and xs < rm:
        xlis.append(rm)
        ylis.append(ys)
    elif ys <= xs and ys < rm:
        ylis.append(rm)
        xlis.append(xs)
    else:
        xlis.append(xs)
        ylis.append(ys)
print(sum(xlis)+sum(ylis))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

# if X + Y < C:
#     r = r[: (X + Y)]
#     C = X + Y

cum_p = [0]
for pi in p:
    cum_p.append(cum_p[-1] + pi)
cum_q = [0]
for qi in q:
    cum_q.append(cum_q[-1] + qi)
cum_r = [0]
for ri in r:
    cum_r.append(cum_r[-1] + ri)


ans = 0

while A + B + C > X + Y:
    kouho = np.array([10 ** 9 + 1] * 3)
    if (A > 0) and (X < A + C):
        kouho[0] = p[A - 1]
    if (B > 0) and (X < B + C):
        kouho[1] = q[B - 1]
    if C > 0:
        kouho[2] = r[C - 1]

    argmin = np.argmin(kouho)

    if argmin == 0:
        A -= 1
    elif argmin == 1:
        B -= 1
    else:
        C -= 1


ans = cum_p[A] + cum_q[B] + cum_r[C]
print(ans)
pass

Submission status: Wrong Answer

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)
#print(p,q,r)
redidx=0
greenidx=0
noneidx=0
delicious=0
for i in range(X):
    if (noneidx<C)and(p[redidx]<=r[noneidx]):
        delicious=delicious+r[noneidx]
        noneidx=noneidx+1
    else:
        delicious=delicious+p[redidx]
        redidx=redidx+1
for i in range(Y):
    if (noneidx<C)and(q[greenidx]<=r[noneidx]):
        delicious=delicious+r[noneidx]
        noneidx=noneidx+1
    else:
        delicious=delicious+q[greenidx]
        greenidx=greenidx+1
print(delicious)

Submission status: Wrong Answer

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 = sorted(a)[::-1]
b = sorted(b)[::-1]
c = sorted(c)[::-1]

a = a[:x]
b = b[:y]
ans = a+b
ans = ans[::-1]
index = 0

for i in range(0,C):
    if(c[i] > ans[index]):
        ans[index] = c[i]
        index = index + 1
    if(index == x+y):
        break
print(sum(ans))

Submission status: Wrong Answer

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()
ans = 0
for i in range(x):
    ans += p[i]
for i in range(y):
    ans += q[i]
#print(ans)
a1 = a-1
b1 = b-1
for i in range(c):
    if r[i] > p[a1] and p[a1] <= q[b1]:
        ans += r[i] - p[a1]
        a1 -= 1
    elif r[i] > q[b1] and q[b1] < p[a1]:
        ans += r[i] - q[b1]
        b1 -= 1
print(ans)

Submission status: Wrong Answer

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)
q = sorted(q)
r = sorted(r)
x_ = a-x
y_ = b-y
ans = sum(p[x_:]) + sum(q[y_:])
for i in r[::-1]:
    if x_>=a or y_>=b:
        break
    if p[x_] > q[y_]:
        if q[y_] < i:
            ans += i - q[y_]
            y_ += 1
        else:
            break
    else:
        if p[x_] < i:
            ans += i - p[x_]
            x_ += 1
        else:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
x,y,a,b,c=map(int,input().split())
P=sorted(list(map(int,input().split())))[::-1]
Q=sorted(list(map(int,input().split())))[::-1]
R=sorted(list(map(int,input().split())))[::-1]+[0]*(x+y)
L=sorted(P[:x]+Q[:y])[::-1]
l=r=0
for i in range(x+y):    
    if r+R[i]<l+L[-i-1]:
        break
    r+=R[i]
    l+=L[-i-1]
print(sum(L[:x+y-i])+r)

Submission status: Wrong Answer

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

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

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

rnum=0
ans=0
for i in range(X):
    if rnum != C:
        if r[rnum] < p[i]:
            ans+=p[i]
        
        else:
            ans+=r[rnum]
            rnum+=1

    else:
        ans+=p[i]


for j in range(Y):
    if rnum != C:
        if r[rnum] < q[j]:
            ans+=q[j]
        
        else:
            ans+=r[rnum]
            rnum+=1

    else:
        ans+=q[j]

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
def main():

    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    p.sort(reverse = True)
    q.sort(reverse = True)
    r.sort(reverse = True)
    countA = 0
    countB = 0
    ans = 0
    i = 0
    for j in range(X):
        if i < C:
            if p[j] > r[i]:
                countA += 1
                ans += p[j]
            else:
                ans += r[i]
                i += 1
        else:
            ans += p[j]
            countA += 1
    for j in range(Y):
        if i < C:
            if q[j] > r[i]:
                countB += 1
                ans += q[j]
            else:
                ans += r[i]
                i += 1
        else:
            ans += q[j]
            countB += 1
    return ans


if __name__ == '__main__':
    # main()
    print(main())

Submission status: Wrong Answer

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()
P = P[:X]
Q = Q[:Y]
S = []
#print(P,Q,S)
for _ in range(X+Y):
    if len(R) == 0:
        break
    s = R[-1]
    if len(P) == 0:
        p = 1000000000000
    elif len(Q) == 0:
        q = 1000000000000
    else:
        p = P[-1]
        q = Q[-1]
    #print(p,q)
    if p >= q:
        if q < s:
            del Q[-1]
            del R[-1]
            S.append(s)
        else:
            break
    else:
        if p < s:
            del P[-1]
            del R[-1]
            S.append(s)
        else:
            break
#print(P,Q,S)
ans = 0
for i in P:
    ans += i
for i in Q:
    ans += i
for i in S:
    ans += i
print(ans)

Submission status: Wrong Answer

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)
ans=sum(re[:x])
ind=0
for i in range(x):
  v=re[x-1-i]
  if i+1>c:
    break
  w=mu[i]
  if v<w:
    ans+=w-v
  else:
    ind=i
    break

ans+=sum(gr[:y])
for i in range(y):
  v=gr[y-1-i]
  if ind+i+1>c:
    break
  w=mu[ind+i]
  if v<w:
    ans+=w-v
  else:
    ind=i
    break





print(ans)
#print(re,gr,mu,ans)

Submission status: Wrong Answer

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

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

reds = deque(p)
greens = deque(q)
uncolor = deque(r)

# できるだけ値が大きいやつを使いたい
ans = 0
red_cnt = 0
green_cnt = 0

while True:
    # print(red_cnt, green_cnt, reds, greens, uncolor)
    if red_cnt == x and green_cnt == y:
        break

    # 赤の処理をするケース
    # 緑が終わってる、赤が緑より大きい
    if len(greens) == 0:
        if len(uncolor) > 0:
            if reds[0] >= uncolor[0]:
                eat = reds.popleft()
            else:
                eat = uncolor.popleft()
        else:
            eat = reds.popleft()
        ans += eat
        red_cnt += 1
        continue

    if len(reds) == 0:
        if len(uncolor) > 0:
            if greens[0] >= uncolor[0]:
                eat = greens.popleft()
            else:
                eat = uncolor.popleft()
        else:
            eat = greens.popleft()
        ans += eat
        green_cnt += 1
        continue

    if len(uncolor) == 0:
        for i in range(x - red_cnt):
            eat = reds.popleft()
            ans += eat
        for i in range(y - green_cnt):
            eat = greens.popleft()
            ans += eat
        red_cnt = x
        green_cnt = y
        continue

    if red_cnt < x and green_cnt < y:
        if reds[0] > greens[0]:
            if reds[0] >= uncolor[0]:
                eat = reds.popleft()
            else:
                eat = uncolor.popleft()
            ans += eat
            red_cnt += 1
        else:
            if greens[0] >= uncolor[0]:
                eat = greens.popleft()
            else:
                eat = uncolor.popleft()
            ans += eat
            green_cnt += 1
    elif red_cnt < x:
        if reds[0] >= uncolor[0]:
            eat = reds.popleft()
        else:
            eat = uncolor.popleft()
        ans += eat
        red_cnt += 1
    else:
        if greens[0] >= uncolor[0]:
            eat = greens.popleft()
        else:
            eat = uncolor.popleft()
        ans += eat
        green_cnt += 1

print(ans)

Submission status: Wrong Answer

Solution code:
x, y, na, nb, nc = map(int, input().split()) 
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

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

ai = len(a) - 1
bi = len(b) - 1
for i in c:
    # if i > a[ai] and ai >= 0:
    #     a[ai] = i
    #     bi -= 1
    # elif i > b[bi] and bi >= 0:
    #     b[bi] = i
    #     bi -= 1
    # else:
    #     break
    if i > b[bi] and bi >= 0:
        b[bi] = i
        bi -= 1
    elif i > a[ai] and ai >= 0:
        a[ai] = i
        bi -= 1
    else:
        break
print(sum(a)+sum(b))

Submission status: Wrong Answer

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 i in range(c):
    if r[cnt] < p[x-cnt_a-1] and r[cnt] < q[y-cnt_b-1]:
        break
    if p[x-cnt_a-1] < q[y-cnt_b-1]:
        ans = (ans-p[x-cnt_a-1]) + r[cnt] 
        cnt_a += 1
        cnt+=1
    else:
        ans = (ans-q[y-cnt_b-1]) + r[cnt] 
        cnt_b += 1
        cnt += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
(x,y,a,b,c),*t=[map(int,t.split())for t in open(0)]
p,q,r=[[0]+sorted(t)[::-1]for t in t]
pi=p[:]
qi=q[:]
ri=r[:]
for i in range(a):p[i+1]+=p[i]
for i in range(b):q[i+1]+=q[i]
for i in range(c):r[i+1]+=r[i]
m=0
for i in range(x+1):
    # i:赤の個数
    # j:赤に変える無の個数
    # k:無の残り
    j=x-i
    k=c-j
    if i>a or j>c:continue
    # 赤の美味しさ総和
    t=p[i]+r[j]
    # 上手いこと緑の美味しさ総和を求める
    ok=0
    ng=k+1
    while ng-ok>1:
        # 無のうちmid個を緑に変換
        mid=(ok+ng)//2
        # mid個を適用
        # 緑はy-mid個使用
        # わかんね（笑）
        if r[j+mid]-r[j]>=q[y]-q[y-mid]and ri[j+mid]>=qi[y-mid+1]:ok=mid
        else:ng=mid
    t+=q[min(b,y-ok)]+r[j+ok]-r[j]
    if t>m:m=t
print(m)

Submission status: Wrong Answer

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]
P=P+([0]*(10**5))
tmp=sorted(q)
Q=tmp[::-1]
Q=Q+([0]*(10**5))
tmp=sorted(r)
R=tmp[::-1]
R=R+([0]*(10**5))
ans=0
i=0
j=0
k=0
while(1):
	if X==0 and Y==0:
		print(ans)
		break
	elif X>0 and Y>0:
		tmp=max(P[i],Q[j],R[k])
		ans+=tmp
		if tmp==P[i]:
			i+=1
			X-=1
		elif tmp==Q[j]:
			j+=1
			Y-=1
		elif tmp==R[k]:
			if P[i]>=Q[j]:
				k+=1
				Y-=1
			else:
				k+=1
				X-=1
	elif X==0:
		tmp=max(Q[j],R[k])
		ans+=tmp
		if tmp==Q[j]:
			j+=1
			Y-=1
		elif tmp==R[k]:
			k+=1
			Y-=1
	elif Y==0:
		tmp=max(P[i],R[k])
		ans+=tmp
		if tmp==P[i]:
			i+=1
			X-=1
		elif tmp==R[k]:
			k+=1
			X-=1

Submission status: Wrong Answer

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]
r.sort(reverse=True)
ans = p + q
ans.sort()

i = 0
for rr in r:
    if ans[i] < rr:
        ans[i] = rr
    else:
        break

print(sum(ans))

Submission status: Wrong Answer

Solution code:
from collections import deque
x0,y0,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 = deque(p)
q = deque(q)
r = deque(r)
x,y = 0,0
red = p.pop()
green = q.pop()
mu = r.pop()
ans = 0

def newred():
  if p:
    return p.pop()
  return 0
def newgreen():
  if q:
    return q.pop()
  return 0
def newmu():
  if r:
    return r.pop()
  return 0


while x < x0 or y < y0:
  if x < x0 and y < y0:
    if red >= mu and green >= mu:
      ans += red + green
      red = newred()
      green = newgreen()
    elif red >= mu:
      ans += red + mu
      red = newred()
      mu = newmu()
    elif green >= mu:
      ans += green + mu
      green = newgreen()
      mu = newmu()
    elif r:
      ans += r.pop() + mu
    elif red >= green:
      ans += mu + red
      newred()
      newmu()
    else:
      ans += mu + green
      newgreen()
      newmu()
    x += 1
    y += 1
  elif x < x0:
    if red >= mu:
      ans += red
      newred()
    else:
      ans += mu
      newmu()
    x += 1
  else:
    if green >= mu:
      ans += green
      newgreen()
    else:
      ans += mu
      newmu()
    y += 1
print(ans)

Submission status: Wrong Answer

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

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

	P = p[0:X]
	Q = q[0:Y]
	Z = min(len(r),X+Y)
	R = r[0:Z]

	x = X
	y = Y

	ans = 0

	while(x>0 or y>0):
		if x > 0 and y > 0:
			a = P[0]
			b = Q[0]
			c = R[0]
		elif x == 0:
			a = 0
			b = Q[0]
			c = R[0]
		elif y == 0:
			a = P[0]
			b = 0
			c = R[0]

		m = max(a,b,c)

		if m == a:
			ans += a
			x -= 1
			P.pop(0)
		elif m == b:
			ans += b
			y -= 1
			Q.pop(0)
		elif m == c:
			ans += c
			R.pop(0)
			if a >= b:
				x -= 1
			elif b >= a:
				y -= 1

	print(ans)

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = map(int,input().split())
datp = list(map(int, input().split()))
datq = list(map(int, input().split()))
datr = list(map(int, input().split()))
datp.sort(reverse=True)
datq.sort(reverse=True)
datr.sort(reverse=True)
res = sum(datp[:x]) + sum(datq[:y])
pl, pr = 0, x - 1
ql, qr = 0, y - 1
#print(datp)
#print(datq)
#print(datr)
#print("defaultt", res)
for i in range(c):
    #print(" musyoku ", i , "=", datr[i])
    diffp, diffq = -1, -1
    if pr >= 0:
        diffp = datr[i] - datp[pr] # この無色を取ったときのメリット
    if qr >= 0:
        diffq = datr[i] - datq[qr] # この無色を取ったときのメリット
    #print("diffp", diffp, "diffq", diffq)
    if diffp <= 0 and diffq <= 0: # デメリットしか両者ないならいらない
        #print("break")
        break
    if diffp >= diffq: # pを押し出したほうがいいなら
        #print("get p")
        res += diffp
        pr -= 1
    else: #qを押し出したほうがいいなら
        #print("get q")
        res += diffq
        pr -= 1
print(res)

Submission status: Wrong Answer

Solution code:
def calc(x,y,a,b,c):
    p=[]
    s=0
    for i in a:
        p.append(i)
    for i in b:
        p.append(i)
    for i in c:
        p.append(i)
    p.sort(reverse=True)
    for i in range(x+y):
        s=s+p[i]
    return s
x,y,a,b,c=input().split()
x=int(x)
y=int(y)
a=int(a)
b=int(b)
c=int(c)
p=input().split()

p=list(map(int,p))
q=input().split()
q=list(map(int,q))
r=input().split()
r=list(map(int,r))
print(calc(x,y,p,q,r))

Submission status: Wrong Answer

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 = sum(P[:X]) + sum(Q[:Y])
x = X-1
y = Y-1
c = 0
while x >= 0 and y >= 0 and c < C:
    p = P[x]
    q = Q[y]
    r = R[c]
    if p <= q and p < r:
        ans = ans - p + r
        x -= 1
        c += 1
    elif q < p and q < r:
        ans = ans - q + r
        y -= 1
        c += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

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

a_list = list(map(int, input().split()))
a_list.sort(reverse=True)
b_list = list(map(int, input().split()))
b_list.sort(reverse=True)
c_list = list(map(int, input().split()))
c_list.sort(reverse=True)

a_index =0
b_index =0
c_index = 0
count = 0
for i in range(x+y):
    if (a_index < x) and \
        (b_index >= y or a_list[a_index] > b_list[b_index]) and \
        (c_index >= c or a_list[a_index] > c_list[c_index]):
        count += a_list[a_index]
        a_index += 1
    elif (b_index < y) and \
        (a_index >= x or b_list[b_index] > a_list[a_index]) and \
        (c_index >= c or b_list[b_index] > c_list[c_index]):
        count += b_list[b_index]
        b_index += 1
    elif (c_index < c) and \
        (a_index >= x or c_list[c_index] > a_list[a_index]) and \
        (b_index >= y or c_list[c_index] > b_list[b_index]):
        count += c_list[c_index]
        c_index += 1
    
print(count)

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = map(int, input().split())
p = sorted(map(int, input().split()))[::-1]
q = sorted(map(int, input().split()))[::-1]
r = sorted(map(int, input().split()))[::-1]

l, m, n = 0, 0, 0
red, green = 0, 0
ans = 0
while True:
    if l < a and p[l] <= q[m]:
        if red < x:
            if n >= c or p[l] >= r[n]:
                ans += p[l]
                l += 1
            else:
                ans += r[n]
                n += 1
            red += 1
        elif green < y:
            if n >= c or q[m] >= r[n]:
                ans += q[m]
                m += 1
            else:
                ans += r[n]
                n += 1
            green += 1
    else:
        if green < y:
            if n >= c or q[m] >= r[n]:
                ans += q[m]
                m += 1
            else:
                ans += r[n]
                n += 1
            green += 1
        elif red < x:
            if n >= c or p[l] >= r[n]:
                ans += p[l]
                l += 1
            else:
                ans += r[n]
                n += 1
            red += 1
    if red == x and green == y:
        break

print(ans)

Submission status: Wrong Answer

Solution code:

x,y,a,b,c = [int(c) for c in input().split()]
ps = [int(c) for c in input().split()]
qs = [int(c) for c in input().split()]
rs = [int(c) for c in input().split()]

ps.sort(reverse=True)
qs.sort(reverse=True)
rs.sort(reverse=True)

pind = x-1
qind = y-1
rind = 0
for i in range(c+1):
    p = ps[pind]
    q = qs[qind]
    r = rs[rind]
    if min(p,q)>= r:
        break
    if p <= q:
        ps[pind] = r
        pind -= 1
    else:
        qs[qind] = r
        qind -= 1
    rind += 1
    if rind >= c:
        break
print(sum(ps[:x]) + sum(qs[:y]))

Submission status: Wrong Answer

Solution code:
x, y, al, bl, cl = 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)
am = x-1
bm = y-1
cm = 0
while True:
    #print(am)
    #print(bm)
    #print(cm)
    if cm >= cl:
        break
    elif am == -1:
        if bm == -1:
            break
        else:
            if c[cm] > b[bm]:
                cm += 1
                bm -= 1
            else:
                break
    elif bm == -1:
        if c[cm] > a[am]:
            cm += 1
            am -= 1
        else:
            break
    elif (c[cm] <= a[am]) & (c[cm] <= b[bm]):
        break
    elif (c[cm] > a[am]) & (c[cm] <= b[bm]):
        cm += 1
        am -= 1
    elif (c[cm] <= a[am]) & (c[cm] > b[bm]):
        cm += 1
        bm -= 1
    else:
        if (c[cm]-a[am]) < (c[cm]-b[bm]):
            cm += 1
            bm -= 1
        else:
            cm += 1
            am -= 1
ans = 0
if am != 0:
    for i in range(am+1):
        ans += a[i]
if bm != 0:
    for j in range(bm+1):
        ans += b[j]
if cm != 0:
    for k in range(cm):
        ans += c[k]

print(ans)

Submission status: Wrong Answer

Solution code:
(x,y,a,b,c),*t=[map(int,t.split())for t in open(0)]
p,q,r=[[0]+sorted(t)[::-1]for t in t]
pi=p[:]
qi=q[:]
ri=r[:]
for i in range(a):p[i+1]+=p[i]
for i in range(b):q[i+1]+=q[i]
for i in range(c):r[i+1]+=r[i]
m=0
for i in range(x+1):
    # i:赤の個数
    # j:赤に変える無の個数
    # k:無の残り
    j=x-i
    k=c-j
    if i>a or j>c:continue
    # 赤の美味しさ総和
    t=p[i]+r[j]
    # 上手いこと緑の美味しさ総和を求める
    ok=0
    ng=k+1
    while ng-ok>1:
        # 無のうちmid個を緑に変換
        mid=(ok+ng)//2
        # mid個を適用
        # 緑はy-mid個使用
        # わかんね（笑）
        if ri[j+mid]>=qi[y-mid+1]:ok=mid
        else:ng=mid
    t+=q[min(b,y-ok)]+r[j+ok]-r[j]
    if t>m:m=t
print(m)

Submission status: Wrong Answer

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]
R=R+([0]*(10**5))
ans=0
i=0
j=0
k=0
while(1):
	if X==0 and Y==0:
		print(ans)
		break
	elif X>0 and Y>0:
		tmp=max(P[i],Q[j],R[k])
		ans+=tmp
		if tmp==P[i]:
			i+=1
			X-=1
		elif tmp==Q[j]:
			j+=1
			Y-=1
		elif tmp==R[k]:
			if P[i]>=Q[j]:
				k+=1
				Y-=1
			else:
				k+=1
				X-=1
	elif X==0:
		tmp=max(Q[j],R[k])
		ans+=tmp
		if tmp==Q[j]:
			j+=1
			Y-=1
		elif tmp==R[k]:
			k+=1
			Y-=1
	elif Y==0:
		tmp=max(P[i],R[k])
		ans+=tmp
		if tmp==P[i]:
			i+=1
			X-=1
		elif tmp==R[k]:
			k+=1
			X-=1

Submission status: Wrong Answer

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()
P = P[:X]
Q = Q[:Y]
S = []
#print(P,Q,S)
for _ in range(X+Y+5):
    if len(R) == 0:
        break
    s = R[-1]
    if len(P) == 0:
        p = 1000000000000
    elif len(Q) == 0:
        q = 1000000000000
    else:
        p = P[-1]
        q = Q[-1]
    #print(p,q)
    if p >= q:
        if q < s:
            del Q[-1]
            del R[-1]
            S.append(s)
        else:
            break
    else:
        if p < s:
            del P[-1]
            del R[-1]
            S.append(s)
        else:
            break
#print(P,Q,S)
ans = sum(P) + sum(Q) + sum(S)
print(ans)

Submission status: Wrong Answer

Solution code:
x,y,a,b,c=[int(i) for i in input().split()]
p=sorted([int(i) for i in input().split()], reverse=True)
q=sorted([int(i) for i in input().split()], reverse=True)
r=sorted([int(i) for i in input().split()], reverse=True)
pi=0
qi=0
ri=0
ret=0
for i in range(x):
    if ri >= len(r) or p[pi] >= r[ri]:
        ret += p[pi]
        pi+=1
    else:
        ret += r[ri]
        ri+=1
for i in range(y):
    if ri >= len(r) or q[qi] >= r[ri]:
        ret += q[qi]
        qi+=1
    else:
        ret += r[ri]
        ri+=1
print(ret)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    X,Y,A,B,C = LMIIS()
    P = LMIIS()
    Q = LMIIS()
    R = LMIIS()
    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)
    i_p = 0
    i_q = 0
    i_r = 0
    num_red = 0
    num_green = 0
    sum_d = 0
    while i_p < X and i_q < Y and i_r < len(R) and i_p + i_q + i_r < X+Y:
        if P[i_p] < R[i_r] or Q[i_q] < R[i_r]:
            sum_d += R[i_r]
            i_r += 1
        elif P[i_p] < Q[i_q]:
            sum_d += Q[i_q]
            i_q += 1
        else:
            sum_d += P[i_p]
            i_p += 1
    while i_p < X and i_r < len(R) and i_p + i_q + i_r < X+Y:
        if P[i_p] < R[i_r]:
            sum_d += R[i_r]
            i_r += 1
        else:
            sum_d += P[i_p]
            i_p += 1
    while i_p < X and i_p + i_q + i_r < X+Y:
        sum_d += P[i_p]
        i_p += 1
    
    while i_q < Y and i_r < len(R) and i_p + i_q + i_r < X+Y:
        if Q[i_q] < R[i_r]:
            sum_d += R[i_r]
            i_r += 1
        else:
            sum_d += Q[i_q]
            i_q += 1
    
    while i_q < Y and i_p + i_q + i_r < X+Y:
        sum_d += Q[i_q]
        i_q += 1

    print(sum_d)

    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
x,y,a,b,c = map(int,input().split())
List_a = [int(i) for i in input().split()]
List_b = [int(i) for i in input().split()]
List_c = [int(i) for i in input().split()]
List_a.sort()
List_b.sort()
List_c.sort(reverse =True)
List_a = List_a[-x:]
List_b = List_b[-y:]
h = 0
j = 0
r = 0
for i in range(c):
    if x == h:
        r = 1
        break
    if y == j:
        r = 2
        break
    if List_a[h] < List_b[j]:
        if List_a[h] < List_c[i]:
            List_a[h] = List_c[i]
            h += 1
        else:
            break
    else:
        if List_b[j] < List_c[i]:
            List_b[j] = List_c[i]
            j += 1
        else:
            break
if r == 1:
    for i in range(c):
        if List_b[j] < List_c[i]:
            List_b[j] = List_c[i]
            j += 1
        else:
            break
if r == 2:
    for i in range(c):
        if List_a[h] < List_c[i]:
            List_a[h] = List_c[i]
            h += 1
        else:
            break
print(sum(List_a)+sum(List_b))

Submission status: Wrong Answer

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 = sum(P[:X]) + sum(Q[:Y])
x = X-1
y = Y-1
c = 0
while x >= 0 and y >= 0 and c < C:
    p = P[x]
    q = Q[y]
    r = R[c]
    if p < q and p < r:
        ans = ans - p + r
        x -= 1
        c += 1
    elif q <= p and q < r:
        ans = ans - q + r
        y -= 1
        c += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = map(int, 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)

INF = 1 << 30
p.append(-INF)
q.append(-INF)
r.append(-INF)

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

def func(c):
  global ans, pi, qi, ri, X, Y
  if c == 0:
    ans += p[pi]
    pi += 1
    X -= 1
  elif c == 1:
    ans += q[qi]
    qi += 1
    Y -= 1
  else:
    ans += r[ri]
    ri += 1
    if c == 2: X -= 1
    else: Y -= 1

while X > 0 or Y > 0:
  if p[pi] >= r[ri] and X > 0: func(0)
  elif q[qi] >= r[ri] and Y > 0: func(1)
  elif min(p[pi], p[pi]*X) <= min(q[qi], q[qi]*Y): func(2)
  else: func(3)

print(ans)

Submission status: Wrong Answer

Solution code:
x, y, na, nb, nc = map(int, input().split()) 
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

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

ai = len(a) - 1
bi = len(b) - 1
for i in c:
    if i > a[ai] and ai >= 0:
        a[ai] = i
        bi -= 1
    elif i > b[bi] and bi >= 0:
        b[bi] = i
        bi -= 1
    else:
        break
print(sum(a)+sum(b))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
INF = 10 ** 10
MOD = 10 ** 9 + 7
from heapq import heapify,heappop,heappush
input = sys.stdin.readline

def main():
    x,y,a,b,c = map(int,input().split())
    R = list(map(int,input().split()))
    G = list(map(int,input().split()))
    M = list(map(int,input().split()))
    i,j,k = 0,0,0
    R.sort(reverse = True)
    G.sort(reverse = True)
    M.sort(reverse = True)
    
    ans = 0
    for _ in range(x):
        if k < c and R[i] < M[k]:
            ans += M[k]
            k += 1
        else:
            ans+= R[i]
            i += 1
    
    for _ in range(y):
        if k < c and G[j] < M[k]:
            ans += M[k]
            k += 1
        else:
            ans += G[j]
            j += 1
    print(ans)

if __name__=='__main__':
    main()