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: Runtime Error

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][:x][::-1]
q =sorted(q)[::-1][:y][::-1]
r =sorted(r)[::-1][:x+y]

pp = 0
qq = 0
pf = True
qf = True
for rr in r:
    lll = False
    if pf == True and qf == True:
        if p[pp]<rr and q[qq]<rr:
            lll = True
            if p[pp]<q[qq] and pf == True:
                p[pp] = rr
                pp += 1
                if pp == x:
                    pf = False
            elif qf == True:
                q[qq] = rr
                qq +=1
                if qq == y:
                    qf = False
    if pf == True and lll == False:
        if p[pp]<rr:
            lll = True
            if pf == True:
               p[pp] = rr
               pp += 1
               if pp == x:
                  pf = False
    if pf == True and lll == False:
        lll = True
        if q[qq]<rr:
            if qf == True:
                q[qq] = rr
                qq +=1
                if qq == y:
                    qf = False
print(sum(p)+sum(q))

Submission status: Runtime Error

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_copy = A.copy()
B_copy = B.copy()
C_copy = C.copy()
for i in range(30):
    A_copy.append(0)
    A.append(0)
    B_copy.append(0)
    B.append(0)
    C_copy.append(0)
    C.append(0)
ux_1 = 0
uy_1 = 0
for i in range(X):
    ux_1 += max(max(A),max(C_copy))
    if max(A) >= max(C_copy):
        A.pop(A.index(max(A)))
    else:
        C_copy.pop(C_copy.index(max(C_copy)))
for i in range(Y):
    uy_1 += max(max(B),max(C_copy))
    if max(B) >= max(C_copy):
        B.pop(B.index(max(B)))
    else:
        C_copy.pop(C_copy.index(max(C_copy)))
U1 = ux_1 + uy_1

ux_2 = 0
uy_2 = 0
for i in range(Y):
    uy_2 += max(max(B_copy),max(C))
    if max(B_copy) >= max(C):
        B_copy.pop(B_copy.index(max(B_copy)))
    else:
        C.pop(C.index(max(C)))
for i in range(X):
    ux_2 += max(max(A_copy),max(C))
    if max(A_copy) >= max(C):
        A_copy.pop(A_copy.index(max(A_copy)))
    else:
        C.pop(C_copy.index(max(C)))
U2 = ux_2 + uy_2
print(max(U1,U2))

Submission status: Runtime Error

Solution code:
from collections import deque

x, y, a, b, c = map(int,input().split())
red = sorted(list(map(int,input().split())))[a-x:]
green = sorted(list(map(int,input().split())))[b-y:]
white = sorted(list(map(int,input().split())))
rcnt = 0
rflag = 0
gcnt = 0
gflag = 0
ans = 0
#print(red,green,white)


for i in range(x+y):
#    print(red,green,white)    
    if red[-1] == max(red[-1],green[-1],white[-1]):
#        print('hoge')
        rcnt += 1
        ans += red.pop(-1)
        if len(red) == 0:
            red = [0]
    elif green[-1] == max(red[-1],green[-1],white[-1]):
#        print('huga')
        gcnt += 1
        ans += green.pop(-1)
        if len(green) == 0:
            green = [0]
    else:
        if red[rflag] < green[gflag]:
            rcnt += 1
            rflag += 1
        else:
            gcnt += 1
            gflag += 1
#        print('foo')
        ans += white.pop(-1)
        if len(white) == 0:
            white = [0]
print(ans)

Submission status: Runtime Error

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)
rs=sorted(r,reverse=True)
pn=ps[:x]
qn=qs[:y]
mp=pn[-1]
mq=qn[-1]
s=0
t=0
for i in range(max(x,y)):
  if mp>rs[i] and mq>rs[i]:
    break
  elif mp<=mq<=rs[i]:
    s+=1
    pn.pop(-s)
    pn.append(rs[i])
    if pn[-s-1]<rs[i]:
      mp=pn[-s-1]
    else:
      mp=rs[i]
      s=s-1
  elif mq<mp<=rs[i]:
    t+=1
    qn.pop(-t)
    qn.append(rs[i])
    if qn[-t-1]<rs[i]:
      mq=qn[-t-1]
    else:
      mq=rs[i]
      t=t-1
print(sum(pn)+sum(qn))

Submission status: Runtime Error

Solution code:
X,Y,A,B,C=map(int,input().split())
p=sorted(map(int,input().split()))
q=sorted(map(int,input().split()))
r=sorted(map(int,input().split()))
ans=[]
ans+=p[A-X:]
ans+=q[B-Y:]
i=0
j=0
while True:
	i=max(r)
	j=min(ans)
	if i>j:
		ans.remove(j)
		ans.append(i)
		r.remove(i)
	else:
		break
print(sum(ans))

Submission status: Runtime Error

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)
#dp問題と予想
ans=0
P=[]
for i in range(X):
    P.append(p[i])
    ans+=p[i]
P.sort()
Q=[]
for i in range(Y):
    Q.append(q[i])
    ans+=q[i]
Q.sort()
rc=0
gc=0
tc=0
fr=False
fg=False
while(1):
    val1=ans
    val2=ans
    if tc>(C-1):
        break
    if rc>(A-1):
        fr=True
    if gc>(B-1):
        fg=True
    if fr and fg:
        break
    if fr:
        b=r[tc]-Q[gc]
        if b<=0:
            break
        val2+=b
        ans=val2
        gc+=1
        tc+=1
    if gc:
        a=r[tc]-P[rc]
        if a<=0:
            break
        val1+=a
        ans=val1
        rc+=1
        tc+=1
    a=r[tc]-P[rc]
    b=r[tc]-Q[gc]
    if a<=0 and b<=0:
        break

    val1+=a
    val2+=b
    if val1>val2:
        rc+=1
        tc+=1
        ans=val1
    else:
        gc+=1
        tc+=1
        ans=val2

print(ans)

Submission status: Runtime Error

Solution code:
import sys

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

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

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

P = P[:X]
P.sort()
Q = Q[:Y]
Q.sort()

ans = 0
i, j, k = 0, 0, 0
while C > k:

    if P[i] >= Q[j]:
        if R[k] > Q[i] and Y > j:
            Q[j] = R[k]
            j += 1
            k += 1
        elif R[k] > P[i] and X > i:
            P[i] = R[k]
            i += 1
            k += 1
        else:
            break

    elif P[i] < Q[j]:
        if R[k] > P[i] and X > i:
            P[i] = R[k]
            i += 1
            k += 1
        elif R[k] > Q[i] and Y > j:
            Q[j] = R[k]
            j += 1
            k += 1
        else:
            break
        

# print(P)
# print(Q)
print(sum(P) + sum(Q))

Submission status: Runtime Error

Solution code:
import sys
import math
from collections import defaultdict
x,y,a,b,c=map(int,sys.stdin.readline().split())
red=list(map(int,sys.stdin.readline().split()))
green=list(map(int,sys.stdin.readline().split()))
color=list(map(int,sys.stdin.readline().split()))
red.sort()
green.sort()
color.sort()
s=0
for i in range(a-x,a):
    s+=red[i]
for i in range(b-y,b):
    s+=green[i]
i,j,k=c-1,a-x,b-y
#print(red,'red')
#print(green,'green')
#print(color,'color')
#print(s,'s',x,'x',y,'y',i,'i',j,'j',k,'k')
while i>=0 and j<a and k<b:
    if color[i]>red[j] and color[i]>green[k]:
        if green[k]>red[j]:
            s-=red[j]
            s+=color[i]
            j+=1
            i-=1
            continue
        else:
            s-=green[k]
            s+=color[i]
            k+=1
            i-=1
            continue
    if color[i]>red[j]:
        s-=red[j]
        s+=color[i]
        i-=1
        j+=1
        continue
    if color[i]>green[k]:
        s-=green[k]
        s+=color[i]
        i-=1
        k+=1
        continue
    i-=1
if i==0:
    print(s)
else:
    while i>=0 and j<a:
        if color[i]>red[j]:
            s-=red[j]
            s+=color[i]
            i-=1
            j+=1
            continue
        i+=1
    while i>=0 and k<b:
        if color[i]>green[k]:
            s-=green[k]
            s+=color[i]
            i-=1
            k+=1
            continue
        i-=1
    print(s)

Submission status: Runtime Error

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()
ans=0

z=x+y

while(z!=0):
    while((x!=0)and(y!=0)):
            a=[]
            a.append(p[-1])
            a.append(q[-1])
            a.append(r[-1])
            if max(a)==p[-1]:
                x-=1
                z-=1
                ans+=p[-1]
                p.pop()
            elif max(a)==q[-1]:
                y-=1
                z-=1
                ans+=q[-1]
                q.pop()
            else:
                z-=1
                ans+=r[-1]
                r.pop()
            if z==0:
                break
    if z==0:
        break
        
    if x==0:
        if q[-1]>=r[-1]:
            y-=1
            z-=1
            ans+=q[-1]
            q.pop() 
        else:
            z-=1
            ans+=r[-1]
            r.pop()
            
            
    elif y==0:
        if p[-1]>=r[-1]:
            x-=1
            z-=1
            ans+=p[-1]
            p.pop()
        else:
            z-=1
            ans+=r[-1]
            r.pop()
print(ans)

Submission status: Runtime Error

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()
ans=0

z=x+y

while(z!=0):
    while((x!=0)and(y!=0)):
            a=[]
            a.append(p[-1])
            a.append(q[-1])
            a.append(r[-1])
            if max(a)==p[-1]:
                x-=1
                z-=1
                ans+=p[-1]
                p.pop()
            elif max(a)==q[-1]:
                y-=1
                z-=1
                ans+=q[-1]
                q.pop()
            else:
                z-=1
                ans+=r[-1]
                r.pop()
        
    if x==0:
        if q[-1]>=r[-1]:
            y-=1
            z-=1
            ans+=q[-1]
            q.pop() 
        else:
            z-=1
            ans+=r[-1]
            r.pop()
    elif y==0:
        if p[-1]>=r[-1]:
            x-=1
            z-=1
            ans+=p[-1]
            p.pop()
        else:
            z-=1
            ans+=r[-1]
            r.pop()
print(ans)

Submission status: Runtime Error

Solution code:
def merge_sort(arr):
    if len(arr) <= 1:
        return arr

    mid = len(arr) // 2
    # ここで分割を行う
    left = arr[:mid]
    right = arr[mid:]

    # 再帰的に分割を行う
    left = merge_sort(left)
    right = merge_sort(right)

    # returnが返ってきたら、結合を行い、結合したものを次に渡す
    return merge(left, right)


def merge(left, right):
    merged = []
    l_i, r_i = 0, 0

    # ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
    while l_i < len(left) and r_i < len(right):
        # ここで=をつけることで安定性を保っている
        if left[l_i] <= right[r_i]:
            merged.append(left[l_i])
            l_i += 1
        else:
            merged.append(right[r_i])
            r_i += 1

    # 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
    if l_i < len(left):
        merged.extend(left[l_i:])
    if r_i < len(right):
        merged.extend(right[r_i:])
    return merged

Red, Green, Rnum, Gnum, Nnum = map(int, input().split())
R = list(map(int, input().split()))
G = list(map(int, input().split()))
N = list(map(int, input().split()))

R = merge_sort(R)
G = merge_sort(G)
N = merge_sort(N)

yum = 0

mushoku = N[-1]
# 赤・緑を食べられるだけ食べる
for i in range(Red):
    if R[Rnum-1] >= mushoku:
        yum += R[Rnum-1]
        Red -= 1
        Rnum -= 1
    else:
        break;

for i in range(Green):
    if G[Gnum-1] >= mushoku:
        yum += G[Gnum-1]
        Green -= 1
        Gnum -= 1
    else:
        break;

# 無色込み
Invis = -1

if Red > 0:
    for i in range(Red):
        if len(N) >= 1:
            if R[Rnum-1] >= N[Invis]:
                yum += R[Rnum-1]
                Rnum -= 1
            else:
                yum += N[Invis]
                Invis -= 1
        else:
            yum += R[Rnum-1]
            Rnum -= 1

if Green > 0:
    for i in range(Green):
        if len(N) >= 1:
            if G[Gnum-1] >= N[Invis]:
                yum += G[Gnum-1]
                Gnum -= 1
            else:
                yum += N[Invis]
                Invis -= 1
        else:
            yum += G[Gnum-1]
            Gnum -= 1


print(yum)

Submission status: Runtime Error

Solution code:
#文字列の入力
A = input()
#コンマで区切る
A_list = A.split(' ')
for i in range(len(A_list)):
    A_list[i] = int(A_list[i])
    
#文字列の入力
p = input()
#コンマで区切る
p_list = p.split(' ')
for i in range(len(p_list)):
    p_list[i] = int(p_list[i])
#文字列の入力
q = input()
#コンマで区切る
q_list = q.split(' ')
for i in range(len(q_list)):
    q_list[i] = int(q_list[i])
#文字列の入力
r = input()
#コンマで区切る
r_list = r.split(' ')
for i in range(len(r_list)):
    r_list[i] = int(r_list[i])
    
ans_list = []
#無色を考えない
for i in range(A_list[0]):
  ans_list.append(max(p_list))
  p_list.remove(max(p_list))
for i in range(A_list[1]):
  ans_list.append(max(q_list))
  q_list.remove(max(q_list))

for i in range(len(ans_list)):
  if(ans_list[i] < max(r_list)):
    ans_list[i] = max(r_list)
    r_list.remove(max(r_list))
    
    
ans = sum(ans_list)


print(ans)

Submission status: Runtime Error

Solution code:
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 = sorted(list(map(int, input().split(' '))))[-x-y:]

pidx = 0
qidx = 0
for i in range(c):
  ptmp = p[pidx]
  qtmp = q[pidx]
  rtmp = r[c - 1 - i] # 逆順
  if ptmp < qtmp:
    if ptmp < rtmp:
      p[pidx] = rtmp
      pidx += 1
  else:
    if qtmp < rtmp:
      q[qidx] = rtmp
      qidx += 1
print (sum(p) + sum(q))

Submission status: Runtime Error

Solution code:
#文字列の入力
A = input()
#コンマで区切る
A_list = A.split(' ')
for i in range(len(A_list)):
    A_list[i] = int(A_list[i])
    
#文字列の入力
p = input()
#コンマで区切る
p_list = p.split(' ')
for i in range(len(p_list)):
    p_list[i] = int(p_list[i])
#文字列の入力
q = input()
#コンマで区切る
q_list = q.split(' ')
for i in range(len(q_list)):
    q_list[i] = int(q_list[i])
#文字列の入力
r = input()
#コンマで区切る
r_list = r.split(' ')
for i in range(len(r_list)):
    r_list[i] = int(r_list[i])
    
ans_list = []
#無色を考えない
for i in range(A_list[0]):
  ans_list.append(max(p_list))
  p_list.remove(max(p_list))
for i in range(A_list[1]):
  ans_list.append(max(q_list))
  q_list.remove(max(q_list))

for i in rannge(len(ans_list)):
  if(ans_list[i] < max(r_list)):
    ans_list[i] = max(r_list)
    r_list.remove(max(r_list))
    
    
ans = sum(ans_list)


print(ans)

Submission status: Runtime Error

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][:x][::-1]
q =sorted(q)[::-1][:y][::-1]
r =sorted(r)[::-1][:x+y]

pp = 0
qq = 0
pf = True
qf = True
for rr in r:
    if pf == True and qf == True and  p[pp]<rr and q[qq]<rr:
            if p[pp]<q[qq] and pf == True:
                p[pp] = rr
                pp += 1
                if pp == x:
                    pf = False
            elif qf == True:
                q[qq] = rr
                qq +=1
                if qq == y:
                    qf = False
    elif pf == True and p[pp]<rr:
            if pf == True:
               p[pp] = rr
               pp += 1
               if pp == x:
                  pf = False
    elif pf == True and q[qq]<rr:
            if qf == True:
                q[qq] = rr
                qq +=1
                if qq == y:
                    qf = False
print(sum(p)+sum(q))

Submission status: Runtime Error

Solution code:
import sys
import math
from collections import defaultdict
x,y,a,b,c=map(int,sys.stdin.readline().split())
red=list(map(int,sys.stdin.readline().split()))
green=list(map(int,sys.stdin.readline().split()))
color=list(map(int,sys.stdin.readline().split()))
red.sort()
green.sort()
color.sort()
s=0
for i in range(a-x,a):
    s+=red[i]
for i in range(b-y,b):
    s+=green[i]
i,j,k=c-1,a-x,b-y
#print(red,'red')
#print(green,'green')
#print(color,'color')
#print(s,'s',x,'x',y,'y',i,'i',j,'j',k,'k')
while i>=0 and j<a and k<b:
    if color[i]>red[j] and color[i]>green[k]:
        if green[k]>red[j]:
            s-=red[j]
            s+=color[i]
            j+=1
            i-=1
            continue
        else:
            s-=green[k]
            s+=color[i]
            k+=1
            i-=1
            continue
    if color[i]>red[j]:
        s-=red[j]
        s+=color[i]
        i-=1
        j+=1
        continue
    if color[i]>green[k]:
        s-=green[k]
        s+=color[i]
        i-=1
        k+=1
        continue
    i-=1
if i==c:
    print(s)
else:
    while i>=0 and j<a:
        if color[i]>red[j]:
            s-=red[j]
            s+=color[i]
            i-=1
            j+=1
            continue
        i+=1
    while i>=0 and k<b:
        if color[i]>green[k]:
            s-=green[k]
            s+=color[i]
            i-=1
            k+=1
            continue
        i-=1
    print(s)

Submission status: Runtime Error

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

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

P = P[A-X:]
Q = Q[B-Y:]

i = 0
j = 0

while min(P[i],Q[j])<R[i+j]:
    if P[i] < Q[j]:
        i += 1
    else:
        j += 1
    if i+j == C:
        break

ans = 0
for e in P[i:]:
    ans = ans + e
for e in Q[j:]:
    ans = ans + e
for a in range(i+j):
    ans = ans + R[a]

print(ans)

Submission status: Runtime Error

Solution code:
def main():
    X, Y, A, B, C = map(int, input().split())
    pA = sorted(map(int, input().split()), reverse=True)
    pB = sorted(map(int, input().split()), reverse=True)
    pC = sorted(map(int, input().split()), reverse=True)

    # dp[red_count][green_count] = (value, red-index, green-index, non-index)
    dp = [[(0, 0, 0, 0) for _ in range(Y + 1)] for _ in range(X + 1)]

    ri = 0
    gi = 0
    for i in range(0, max(X, Y) + 1):
        ri = i
        gi = i - 1
        if 0 < ri:
            v, r, g, n = dp[ri - 1][gi]
            dp[ri][gi] = max(dp[ri][gi], (v + pA[r], r + 1, g, n),
                             (v + pC[n] if n < C else v, r, g, n + 1))
        if 0 < gi:
            v, r, g, n = dp[ri][gi - 1]
            dp[ri][gi] = max(dp[ri][gi], (v + pB[g], r, g + 1, n),
                             (v + pC[n] if n < C else v, r, g, n + 1))
        ri = i - 1
        gi = i
        if 0 < ri:
            v, r, g, n = dp[ri - 1][gi]
            dp[ri][gi] = max(dp[ri][gi], (v + pA[r], r + 1, g, n),
                             (v + pC[n] if n < C else v, r, g, n + 1))
        if 0 < gi:
            v, r, g, n = dp[ri][gi - 1]
            dp[ri][gi] = max(dp[ri][gi], (v + pB[g], r, g + 1, n),
                             (v + pC[n] if n < C else v, r, g, n + 1))
        ri = i
        gi = i
        if 0 < ri:
            v, r, g, n = dp[ri - 1][gi]
            dp[ri][gi] = max(dp[ri][gi], (v + pA[r], r + 1, g, n),
                             (v + pC[n] if n < C else v, r, g, n + 1))
        if 0 < gi:
            v, r, g, n = dp[ri][gi - 1]
            dp[ri][gi] = max(dp[ri][gi], (v + pB[g], r, g + 1, n),
                             (v + pC[n] if n < C else v, r, g, n + 1))

    print(dp[X][Y][0])


main()

Submission status: Runtime Error

Solution code:
X, Y ,A, B, C = map(int,input().split())
listp = list(map(int, input().split()))
listq = list(map(int, input().split()))
listr = list(map(int, input().split()))
listp = sorted(listp, reverse=True)
listq = sorted(listq, reverse=True)
listr = sorted(listr, reverse=True)
listp = listp[:X]
listq = listq[:Y]

eat_noapple = []
oisisa = 0

for noapple in listr:
    if listp[-1] >= listq[-1] and listq[-1] < noapple:
        listq.pop(-1)
        eat_noapple.append(noapple)
    elif listp[-1] < listq[-1] and listp[-1] < noapple:
        listp.pop(-1)
        eat_noapple.append(noapple)
    else:
        break

for papple in listq:
    oisisa += papple
for qapple in listp:
    oisisa += qapple
for rapple in eat_noapple:
    oisisa += rapple

print(oisisa)

Submission status: Runtime Error

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)

S = P[:X] + Q[:Y]
S.sort(reverse=True)

S_wa = []
wa = 0
for s in S[::-1]:
    wa += s
    S_wa.append(wa)
# print(S_wa)
big = S_wa[-1]
ans = S_wa[-1]

R_wa = []
wa = 0
for r in R:
    wa += r
    R_wa.append(wa)
# print(R_wa)

for i in range(len(R_wa)):
    ans = max(ans, big + R_wa[i] - S_wa[i])
print(ans)

Submission status: Runtime Error

Solution code:
def merge(left, right):
    merged = []
    l_i, r_i = 0, 0

    # ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
    while l_i < len(left) and r_i < len(right):
        # ここで=をつけることで安定性を保っている
        if left[l_i] <= right[r_i]:
            merged.append(left[l_i])
            l_i += 1
        else:
            merged.append(right[r_i])
            r_i += 1

    # 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
    if l_i < len(left):
        merged.extend(left[l_i:])
    if r_i < len(right):
        merged.extend(right[r_i:])
    return merged


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

import numpy as np
p = np.sort(p)[-x:]
q = np.sort(q)[-y:]
r = np.sort(r)

pq = np.array(merge(p, q))
f = True
i = 1
while True:
    f = (r[-i:] >= pq[:i]).all()
    if not f:
        break
    else:
        i += 1

i -= 1
if i:
    print(np.r_[r[-i:], pq[i:]].sum())
else:
    print(pq.sum())

Submission status: Runtime Error

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)
  
  j = 0
  sum_list = sorted(aka_list + midori_list)
  for i in range(len(sum_list)):
    if sum_list[i] < mu_list[j]:
      sum_list[i] = mu_list[j]
      j += 1
  print(sum(sum_list))
  
main()

Submission status: Runtime Error

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

A = sorted(P[:x] + Q[:y])
ans = sum(A)

for i in range(c):
    if A[i] < R[-1]:
        ans = ans + R[-1] - A[i]
        R.pop(-1)

print(ans)

Submission status: Runtime Error

Solution code:
red_eat_num, green_eat_num, red_total, green_total, no_total = map(int, input().split())

red = list(map(int, input().split()))
green = list(map(int, input().split()))
no = list(map(int, input().split()))

red = sorted(red, reverse=True)
green = sorted(green, reverse=True)
no= sorted(no, reverse=True)

count_x = 0
count_y = 0
pointaA = 0
pointaB = 0
pointaC = 0
total_red = 0
total_green = 0

while 1:
    count_x = count_x + 1
    if count_x > red_eat_num:
        break
    
    if red[pointaA] >= no[pointaC]:
        total_red = total_red + red[pointaA]
        pointaA = pointaA + 1
    elif pointaA >= red_total or red[pointaA] < no[pointaC]:
        total_red = total_red + no[pointaC]
        pointaC = pointaC + 1
# print(total_red)
    
while 1:
    count_y = count_y + 1
    if count_y > green_eat_num:
        break
    
    if green[pointaB] >= no[pointaC]:
        total_green = total_green + green[pointaB]
        pointaB = pointaB + 1
    elif pointaB >= green_total or green[pointaB] < no[pointaC]:
        total_green = total_green + no[pointaC]
        pointaC = pointaC + 1
# print(total_green)
        
print(total_red + total_green)

Submission status: Runtime Error

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[0]
Q=q[0]
R=r[0]
M=0
def compere(a,A,W,r,R,M):
    for i in range(W):
        if A>=R:
            M=pop(a,A,M)
        else:
            M=pop(r,R,M)
    return M
def pop(s,S,M):
    M+=s.pop(0)
    if s:
        S=s[0]
    return M
M=compere(p,P,X,r,R,M)
M=compere(q,Q,Y,r,R,M)

print(M)

Submission status: Runtime Error

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

p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)
l = p[:X] + q[:Y]
l.sort()
for i in range(C):
    if r[i] > l[i]:
        l[i] = r[i]
print(sum(l))

Submission status: Runtime Error

Solution code:
import heapq
from collections import deque

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()
q.sort()
r.sort()

pq = deque((heapq.merge(p[A - X:], q[B - Y:])))
r = deque(r)

while pq[0] < r[-1]:
  pq.popleft()
  pq.append(r.pop())

print(sum(pq))

Submission status: Runtime Error

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.append(-1)
q.append(-1)
r.append(-1)
def count_sort(arr):
    max_num = max(arr)
    min_num = min(arr)
    count = [0] * (max_num - min_num + 1)
    for ele in arr:
        count[ele - min_num] += 1

    return [ele for ele, cnt in enumerate(count, start=min_num) for __ in range(cnt)]
ps=count_sort(p)
qs=count_sort(q)
rs=count_sort(r)
d=0
e=0
f=0
ans=0
print(ans)

Submission status: Runtime Error

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 = p[:X]
b = q[:Y]
p_c = -1
q_c = -1
r_c = 0
k = 0


ans = sum(a)+sum(b)
while(True):
    if p_c < - X or a[p_c] >= b[q_c]:
        if b[q_c] < r[r_c] and q_c >= - Y:
            ans += ( r[r_c] - b[q_c] )
            r_c += 1
            q_c -= 1
        else:
            k = 1

    else:
        if a[p_c] < r[r_c]:
            ans += (r[r_c] - a[p_c])
            r_c += 1
            p_c -= 1
        else:
            k = 1

    if k == 1 or r_c >= C:
        break

print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
import heapq


def solve(X: int, Y: int, A: int, B: int, C: int, p: "List[int]", q: "List[int]", r: "List[int]"):
    p = sorted(p)
    q = sorted(q)
    r = sorted(r)

    result = 0
    for i in range(X):
        if p[-1] < r[-1]:
            result += r.pop()
        else:
            result += p.pop()

    for i in range(Y):
        if q[-1] < r[-1]:
            result += r.pop()
        else:
            result += q.pop()
    print(result)
    return

def solve_slow(X: int, Y: int, A: int, B: int, C: int, p: "List[int]", q: "List[int]", r: "List[int]"):
    p = [-1 * i for i in p]
    q = [-1 * i for i in q]
    r = [-1 * i for i in r]
    heapq.heapify(p)
    heapq.heapify(q)
    heapq.heapify(r)

    result = 0
    for i in range(X):
        smallest_p = heapq.nsmallest(1, p)
        smallest_r = heapq.nsmallest(1, r)
        if smallest_p < smallest_r:
            temp = heapq.heappop(p) * -1
            result += temp
        else:
            temp = heapq.heappop(r) * -1
            result += temp

    for i in range(Y):
        smallest_q = heapq.nsmallest(1, q)
        smallest_r = heapq.nsmallest(1, r)
        if smallest_q < smallest_r:
            temp = heapq.heappop(q) * -1
            result += temp
        else:
            temp = heapq.heappop(r) * -1
            result += temp
    #    print(temp)
    print(result)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(A)]  # type: "List[int]"
    q = [int(next(tokens)) for _ in range(B)]  # type: "List[int]"
    r = [int(next(tokens)) for _ in range(C)]  # type: "List[int]"
    solve(X, Y, A, B, C, p, q, r)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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()))
res = 0

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

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

p_sum = sum(p)
q_sum = sum(q)

for i in r:
    p_temp = (p_sum - p[-1] + i)
    q_temp = (q_sum - q[-1] + i)
    if p_temp >= p_sum or q_temp >= q_sum:        
        if p_temp - p_sum > q_temp - q_sum:
            p_sum = p_temp
            p.pop(-1)        
        else:
            q_sum = q_temp
            q.pop(-1)

print(p_sum + q_sum)

Submission status: Runtime Error

Solution code:
x, y, a, b, c = [int(arg) for arg in input().split()]
p = [int(arg) for arg in input().split()]
q = [int(arg) for arg in input().split()]
r = [int(arg) for arg in input().split()]

result = 0
leftX, leftY = x, y
p.sort()
q.sort()
r.sort()
while leftX != 0 and leftY != 0:
    while leftX != 0 and r[-1] < p[-1]:
        result += p.pop()
        leftX -= 1
    while leftY != 0 and r[-1] < q[-1]:
        result += q.pop()
        leftY -= 1
    if leftX != 0 or leftY != 0:
        result += r.pop()
        if leftX != 0 and leftX > leftY:
            leftX -= 1
        elif leftY != 0:
            leftY -= 1

print(result)