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())
red = list(map(int,input().split()))
green = list(map(int,input().split()))
nocolor =  list(map(int,input().split()))
red.sort()
green.sort()
nocolor.sort(reverse=True)
red = red[a-x:]
green = green[b-y:]
rr = 0
gg = 0
rr_max = len(red)
gg_max = len(green)
for i in range(len(nocolor)):
    if red[rr] < green[gg]:
        if rr < rr_max:
            if red[rr] < nocolor[i]:
                red[rr] = nocolor[i]
                rr += 1
            else:
                break
        else:
            if green[gg] < nocolor[i]:
                green[gg] = nocolor[i]
                gg += 1
            else:
                break
    else:
        if gg < gg_max:
            if green[gg] < nocolor[i]:
                green[gg] = nocolor[i]
                gg += 1
            else:
                break
        else:
            if red[rr] < nocolor[i]:
                red[rr] = nocolor[i]
                rr += 1
            else:
                break
print(sum(red)+sum(green))

Submission status: Runtime Error

Solution code:
x,y,a,b,c = map(int,input().split())
red = list(map(int,input().split()))
green = list(map(int,input().split()))
nocolor =  list(map(int,input().split()))
red.sort()
green.sort()
nocolor.sort(reverse=True)
red = red[a-x:]
green = green[b-y:]
rr = 0
gg = 0
for i in range(len(nocolor)):
    if red[rr] <= green[gg]:
        if red[rr] <= nocolor[i]:
            red[rr] = nocolor[i]
            rr += 1
        else:
            break
    else:
        if green[gg] <= nocolor[i]:
            green[gg] = nocolor[i]
            gg += 1
        else:
            break
print(sum(red)+sum(green))

Submission status: Runtime Error

Solution code:
x,y,a,b,c = map(int,input().split())
red = list(map(int,input().split()))
green = list(map(int,input().split()))
nocolor =  list(map(int,input().split()))
red.sort()
green.sort()
nocolor.sort(reverse=True)
red = red[a-x:]
green = green[b-y:]
rr = 0
gg = 0
for i in range(len(nocolor)):
    if red[rr] < green[gg]:
        if red[rr] < nocolor[i]:
            red[rr] = nocolor[i]
            rr += 1
        else:
            break
    else:
        if green[gg] < nocolor[i]:
            green[gg] = nocolor[i]
            gg += 1
        else:
            break
print(sum(red)+sum(green))

Submission status: Runtime Error

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

# 組み合わせ
mod = 10 ** 9 + 7
N = 2* 10 ** 5  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)

def cmb(n, r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % mod
  
# 深さ優先探索
def dfs(v, p=-1):

    # print(v, p, [x + 1 for x in E[v]])
    
    dp_l = 1  # 自分自身しかない場合
    size_l = 1 # 自分自身のサイズを含める

    # 子の情報をあわせて数え上げる
    for u in E[v]:
        
        # 親へのルートは辿らない
        if u == p:
            continue

        d, s = dfs(u, v)
        d %= mod
        size_l += s
        dp_l = dp_l * d * cmb(size_l-1, s) % mod

    dp[v] = dp_l
    size[v] = size_l
        
    return (int(dp_l), size_l)
  
def bfs(v, p=-1):
    
    for u in E[v]:
        if u == p:
            continue
        
        # u がなくなった場合の dp[v] 値、 size を求める
        # 一旦、uを切り離す

        partial_v = int(dp[v] / dp[u] / cmb(N - 1, size[u]))
        
        # u に v 側の部分木が接続された場合の値を求める
        # u に v を根とする部分木をつける

        dp_l = dp[u] * partial_v * cmb(N-1, size[u]-1)
        
        dp[u] = dp_l
    
        bfs(u,v)

# 入力処理
N = int(input())
E = [[] for _ in range(N)]

for _ in range(N-1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)
      
dp = [1] * N
size = [1] * N


dfs(0)

bfs(0)

for i in range(N):
    print(dp[i])

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
x,y,a,b,c=map(int,input().split())
sa=list(map(int, input().split()))
sb=list(map(int, input().split()))
sc=list(map(int, input().split()))
sa.sort(reverse=True)
sb.sort(reverse=True)
sc.sort(reverse=True)
rr=[]
rg=[]
for i in range(x):
    rr.append(sa.pop(0))
for i in range(y):
    rg.append(sb.pop(0))
for i in range(10**9):
    if sc[0]<=min(min(rr),min(rg)):
        break
    elif sc[0]>min(min(rr),min(rg)):
        if sc==[]:
            break
        elif sc[0]>min(rr):
            rr.remove(min(rr))
            rr.append(sc.pop(0))
        elif sc[0]>min(rg):
            rg.remove(min(rg))
            rg.append(sc.pop(0))
d=sum(rr)+sum(rg)
print(d)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
x,y,a,b,c=map(int,input().split())
sa=list(map(int, input().split()))
sb=list(map(int, input().split()))
sc=list(map(int, input().split()))
# sa.sort(reverse=True)
# sb.sort(reverse=True)
sc.sort(reverse=True)
rr=[]
rg=[]
for i in range(x):
    rr.append(max(sa))
    sa.remove(max(sa))
for i in range(y):
    rg.append(max(sb))
    sb.remove(max(sb))
while sc[0]>min(min(rr),min(rg)):
    if sc==[]:
        break
    elif sc[0]>min(rr):
        rr.remove(min(rr))
        rr.append(sc.pop(0))
    elif sc[0]>min(rg):
        rg.remove(min(rg))
        rg.append(sc.pop(0))



d=sum(rr)+sum(rg)
print(d)

Submission status: Runtime Error

Solution code:
x,y,a,b,c=map(int,input().split())
sa=list(map(int, input().split()))
sb=list(map(int, input().split()))
sc=list(map(int, input().split()))
sa.sort(reverse=True)
sb.sort(reverse=True)
sc.sort(reverse=True)
rr=[]
rg=[]
for i in range(x):
    rr.append(sa.pop(0))
for i in range(y):
    rg.append(sb.pop(0))
while sc[0]>min(min(rr),min(rg)):
    if sc[0]>min(rr):
        rr.pop(min(rr))
        rr.append(sc.pop(0))
    elif sc[0]>min(rg):
        rg.pop(min(rg))
        rg.append(sc.pop(0))
    if sc==[]:
        break


d=sum(rr)+sum(rg)
print(d)

Submission status: Runtime Error

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

p = list(int(input().split())
q = list(int(input().split())
r = list(int(input().split())
p = sorted(p,reverse=True)
p = p[:X]
q = sorted(q, reverse=True)
q = q[:Y]
r = sorted(r, reverse=True)

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

Submission status: Runtime Error

Solution code:
na, nb, a, b, c = map(int, input().split())
ab_list = [0 for i in range(na + nb)]
ab_list[:na] = list(map(int, input().split()))[:na]
ab_list[na:] = list(map(int, input().split()))[:nb]
c_list = list(map(int, input().split()))[:min(na + nb, c)]

ab_list.sort()
c_list.sort(reverse=True)

c_max = c_list[0]
for index in range(len(ab_list)):
    if c_max <= ab_list[index]:
        ab_index = index
        break
ab_list[:ab_index] = sorted(ab_list[:ab_index] + c_list[:ab_index], reverse=True)[:ab_index]

print(sum(ab_list))

Submission status: Runtime Error

Solution code:
x, y, a, b, c = map(int, input("").split())
X = list(map(int,input("").split()))
Y = list(map(int,input("").split()))
Z = list(map(int,input("").split()))
sum = 0
for i in range(x):
    if max(X)>max(Z):
        sum += max(X)
        X.pop(X.index(max(X)))
    else:
        sum += max(Z)
        Z.pop(Z.index(max(Z)))
    print(sum)

for i in range(y):
    if max(Y)>max(Z):
        sum += max(Y)
        Y.pop(Y.index(max(Y)))
    else:
        sum += max(Z)
        Z.pop(Z.index(max(Z)))
    print(sum)
print("FINAL SUM", sum)

Submission status: Runtime Error

Solution code:
xyabc=input().split()
x=int(xyabc[0])
y=int(xyabc[1])
a=int(xyabc[2])
b=int(xyabc[3])
c=int(xyabc[4])
list1=input().split()
list2=input().split()
list3=input().split()
d=a-x+b-y
an=[]
bn=[]
cn=[]
for num in list1 :
  an.append(int(num))
for num in list2 :
  bn.append(int(num))
for num in list3 :
  cn.append(int(num))

count=0
for i in range(x) :
  k=max(an)
  count+=k
  an.pop(k)
  
for i in range(y) :
  k=max(bn)
  count+=k
  an.pop(k)
  

for i in range(d) :
  k=max(cn)
  count+=k
  an.pop(k)
  
print(count)

Submission status: Runtime Error

Solution code:
import heapq

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

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

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

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

heapq.heapify(r)
ans = 0

for i in range(x+y) :
    print(i, pq[i], -r[0])
    if len(r) != 0 :
        if  pq[i] < -r[0] :
            ans += -heapq.heappop(r)
        else :
            ans += pq[i]

print(ans)

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()]
from collections import deque
P_sort = sorted(P,reverse=True)[0:X]
Q_sort = sorted(Q,reverse=True)[0:Y]
R_sort = deque(sorted(R,reverse=True)[0:X+Y])
PQ = sorted(P_sort + Q_sort)
for i in range(len(PQ)):
    if R_sort[0] > PQ[i]:
        r = R_sort.popleft
        PQ[i] = r
print(sum(PQ))

Submission status: Runtime Error

Solution code:
#heapqすら使わなくても良い
x,y,a,b,c=map(int,input().split())
def _int(x):
    return -int(x)
p=sorted(list(map(_int,input().split())),reverse=True)[:x]
q=sorted(list(map(_int,input().split())),reverse=True)[:y]
r=sorted(list(map(_int,input().split())),reverse=True)

p.extend(q)
ans=sorted(p)

#ansは小さい順、rは大きい順
for i in range(x+y):
    if len(r)==0:break
    if r[i]>=ans[i]:
        ans[i]=r[i]
    else:
        break
print(sum(ans))

Submission status: Runtime Error

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

p=A-X
q=B-Y

ans=0

for item in R:

	if item > P[p] and p<A:
		ans+=item
		p+=1
	elif item > Q[q] and q<B:
		ans+=item
		q+=1

print(ans+sum(P[p:])+sum(Q[q:]))

Submission status: Runtime Error

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

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


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

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


happy = psum + qsum

print(happy)

Submission status: Runtime Error

Solution code:
import statistics

def quickSort(arr):
  left = []
  right = []
  if len(arr) <= 1:
   return arr
  median = int(statistics.median(arr))
  medianFlg = 0

  for element in arr:
   if element < median:
    left.append(element)
   elif element > median:
    right.append(element)
   else:
    medianFlg += 1
  left = quickSort(left)
  right = quickSort(right)
  return left + [median] * medianFlg + right

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()))
t1 = time.time()
PP=quickSort(P)
QQ=quickSort(Q)
S=PP[A-X:A]+QQ[B-Y:B]+R
SS=quickSort(S)
D=0
for r in range(X+Y):
 D+=SS[C+r]
print(D)
t2 = time.time()
elapsed_time = t2-t1
print(f"経過時間：{elapsed_time}")import time
import statistics

def quickSort(arr):
  left = []
  right = []
  if len(arr) <= 1:
   return arr
  median = int(statistics.median(arr))
  medianFlg = 0

  for element in arr:
   if element < median:
    left.append(element)
   elif element > median:
    right.append(element)
   else:
    medianFlg += 1
  left = quickSort(left)
  right = quickSort(right)
  return left + [median] * medianFlg + right

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()))
PP=quickSort(P)
QQ=quickSort(Q)
S=PP[A-X:A]+QQ[B-Y:B]+R
SS=quickSort(S)
D=0
for r in range(X+Y):
 D+=SS[C+r]
print(D)

Submission status: Runtime Error

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

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

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

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


happy = psum + qsum

print(happy)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

X, Y, A, B, C = map(int, sys.stdin.readline().rstrip().split())
P = list(map(int, sys.stdin.readline().rstrip().split()))
Q = list(map(int, sys.stdin.readline().rstrip().split()))
R = list(map(int, sys.stdin.readline().rstrip().split()))

if A == 1 and B == 1 and C == 1:
    ans = sum(sorted([P[0], Q[0], R[0]], reverse=True)[:2])
    print(ans)
    sys.exit()

Pmin = np.min(P)
Qmin = np.min(Q)
Rmax = np.max(R)

# 着色する必要がない場合
if Pmin > Rmax and Qmin > Rmax:
    sP = np.sort(P)[::-1] if len(set(P)) > 1 else P
    sQ = np.sort(Q)[::-1] if len(set(Q)) > 1 else Q
    ans = np.sum(sP[:X]) + np.sum(sQ[:Y])
    print(ans)
    sys.exit()

gS = P + Q + R
p = A + B
iX = 0
iY = 0
iR = []
aX = [0] * X
aY = [0] * Y
aR = []
ans = 0
for index in np.argsort(gS)[::-1]:
    if iX == X and iY == Y:
        break
    if index < A:
        if iX == X:
            continue
        else:
            aX[iX] = gS[index]
            iX += 1
    elif index < p:
        if iY == Y:
            continue
        else:
            aY[iY] = gS[index]
            iY += 1
    else:
        iR.append((iX, iY))
        aR.append(gS[index])

sumX = sum(aX)
sumY = sum(aY)
for (iX, iY), s in zip(iR, aR):
    print(aX, aY)
    if len(aX) == 0:
        sumY = sumY + s - aY.pop()
        if len(aY) == 0:
            break
    elif len(aY) == 0:
        sumX = sumX + s - aX.pop()
        if len(aX) == 0:
            break
    else:
        if s <= aX[-1] and s <= aY[-1]:
            break
        if iX == X:
            sumY = sumY + s - aY.pop()
        elif iY == Y:
            sumX = sumX + s - aX.pop()
        else:
            if aX[-1] < aY[-1]:
                sumX = sumX + s - aX.pop()
            else:
                sumY = sumY + s - aY.pop()

print(sumX + sumY)

Submission status: Runtime Error

Solution code:
import bisect
X, Y, A, B, C = map(int, input().split())
red = [int(x) for x in input().split()]
gre = [int(x) for x in input().split()]
non = [int(x) for x in input().split()]
red.sort(reverse=True)
gre.sort(reverse=True)
non.sort()
ans = red[:X] + gre[:Y]
ans.sort(reverse=True)
if non[-1] > ans[-1]:
    c = non[-1]
    index = bisect_right_reverse(ans, c)
    ans.insert(index, c)
    non.pop(-1)
    ans.pop(-1)
print(sum(ans))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

X, Y, A, B, C = map(int, sys.stdin.readline().rstrip().split())
P = list(map(int, sys.stdin.readline().rstrip().split()))
Q = list(map(int, sys.stdin.readline().rstrip().split()))
R = list(map(int, sys.stdin.readline().rstrip().split()))

if A == 1 and B == 1 and C == 1:
    ans = sum(sorted([P[0], Q[0], R[0]], reverse=True)[:2])
    print(ans)
    sys.exit()

Pmin = np.min(P)
Qmin = np.min(Q)
Rmax = np.max(R)

# 着色する必要がない場合
if Pmin > Rmax and Qmin > Rmax:
    sP = np.sort(P)[::-1] if len(set(P)) > 1 else P
    sQ = np.sort(Q)[::-1] if len(set(Q)) > 1 else Q
    ans = np.sum(sP[:X]) + np.sum(sQ[:Y])
    print(ans)
    sys.exit()

gS = P + Q + R
p = A + B
iX = 0
iY = 0
iR = []
aX = [0] * X
aY = [0] * Y
aR = []
ans = 0
for index in np.argsort(gS)[::-1]:
    if iX == X and iY == Y:
        break
    if index < A:
        if iX == X:
            continue
        else:
            aX[iX] = gS[index]
            iX += 1
    elif index < p:
        if iY == Y:
            continue
        else:
            aY[iY] = gS[index]
            iY += 1
    else:
        iR.append((iX, iY))
        aR.append(gS[index])

sumX = sum(aX)
sumY = sum(aY)
for (iX, iY), s in zip(iR, aR):
    if s <= aX[-1] and s <= aY[-1]:
        break
    if iX == X or len(aX) == 0:
        sumY = sumY + s - aY.pop()
        if len(aY) == 0:
            break
    elif iY == Y or len(aY) == 0:
        sumX = sumX + s - aX.pop()
        if len(aX) == 0:
            break
    else:
        if aX[-1] < aY[-1]:
            sumX = sumX + s - aX.pop()
        else:
            sumY = sumY + s - aY.pop()

print(sumX + sumY)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

X, Y, A, B, C = map(int, sys.stdin.readline().rstrip().split())
P = list(map(int, sys.stdin.readline().rstrip().split()))
Q = list(map(int, sys.stdin.readline().rstrip().split()))
R = list(map(int, sys.stdin.readline().rstrip().split()))

if A == 1 and B == 1 and C == 1:
    ans = sum(sorted([P[0], Q[0], R[0]], reverse=True)[:2])
    print(ans)
    sys.exit()

Pmin = np.min(P)
Qmin = np.min(Q)
Rmax = np.max(R)

# 着色する必要がない場合
if Pmin > Rmax and Qmin > Rmax:
    sP = np.sort(P)[::-1] if len(set(P)) > 1 else P
    sQ = np.sort(Q)[::-1] if len(set(Q)) > 1 else Q
    ans = np.sum(sP[:X]) + np.sum(sQ[:Y])
    print(ans)
    sys.exit()

gS = P + Q + R
p = A + B
iX = 0
iY = 0
iR = []
aX = [0] * X
aY = [0] * Y
aR = []
ans = 0
for index in np.argsort(gS)[::-1]:
    if iX == X and iY == Y:
        break
    if index < A:
        if iX == X:
            continue
        else:
            aX[iX] = gS[index]
            iX += 1
    elif index < p:
        if iY == Y:
            continue
        else:
            aY[iY] = gS[index]
            iY += 1
    else:
        iR.append((iX, iY))
        aR.append(gS[index])

sumX = sum(aX)
sumY = sum(aY)
for (iX, iY), s in zip(iR, aR):
    if (len(aX) == 0 or s <= aX[-1]) and (len(aY) == 0 and s <= aY[-1]):
        break
    if iX == X or len(aX) == 0:
        sumY = sumY + s - aY.pop()
    elif iY == Y or len(aY) == 0:
        sumX = sumX + s - aX.pop()
    else:
        if aX[-1] < aY[-1]:
            sumX = sumX + s - aX.pop()
        else:
            sumY = sumY + s - aY.pop()

print(sumX + sumY)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

X, Y, A, B, C = map(int, sys.stdin.readline().rstrip().split())
P = list(map(int, sys.stdin.readline().rstrip().split()))
Q = list(map(int, sys.stdin.readline().rstrip().split()))
R = list(map(int, sys.stdin.readline().rstrip().split()))

if A == 1 and B == 1 and C == 1:
    ans = sum(sorted([P[0], Q[0], R[0]], reverse=True)[:2])
    print(ans)
    sys.exit()

Pmin = np.min(P)
Qmin = np.min(Q)
Rmax = np.max(R)

# 着色する必要がない場合
if Pmin > Rmax and Qmin > Rmax:
    sP = np.sort(P)[::-1] if len(set(P)) > 1 else P
    sQ = np.sort(Q)[::-1] if len(set(Q)) > 1 else Q
    ans = np.sum(sP[:X]) + np.sum(sQ[:Y])
    print(ans)
    sys.exit()

gS = P + Q + R
p = A + B
iX = 0
iY = 0
iR = []
aX = [0] * X
aY = [0] * Y
aR = []
ans = 0
for index in np.argsort(gS)[::-1]:
    if iX == X and iY == Y:
        break
    if index < A:
        if iX == X:
            continue
        else:
            aX[iX] = gS[index]
            iX += 1
    elif index < p:
        if iY == Y:
            continue
        else:
            aY[iY] = gS[index]
            iY += 1
    else:
        iR.append((iX, iY))
        aR.append(gS[index])

sumX = sum(aX)
sumY = sum(aY)
for (iX, iY), s in zip(iR, aR):
    if s <= aX[-1] and s <= aY[-1]:
        break
    if iX == X or len(aX) == 0:
        sumY = sumY + s - aY.pop()
    elif iY == Y or len(aY) == 0:
        sumX = sumX + s - aX.pop()
    else:
        if aX[-1] < aY[-1]:
            sumX = sumX + s - aX.pop()
        else:
            sumY = sumY + s - aY.pop()

print(sumX + sumY)

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)
pp = p[:x]
qq = q[:y]
if x+y <= c:
  rr = r[:(x+y)]
else:
  rr = r
ppqq = pp + qq
ppqq.sort()
for i in range(len(ppqq)):
  if ppqq[i] < rr[0]:
    ppqq[i] = rr[0]
    del rr[0]
print(sum(ppqq))

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)
pp = p[:x]
qq = q[:y]
rr = r[:(x+y)]
ppqq = pp + qq
ppqq.sort()
for i in range(len(ppqq)):
  if ppqq[i] < rr[0]:
    ppqq[i] = rr[0]
    del rr[0]
print(sum(ppqq))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
x,y,a,b,c=map(int,input().split())
r=list(map(int,input().split()))+[0]
b=list(map(int,input().split()))+[0]
n=list(map(int,input().split()))+[0]
r.sort(reverse=True)
b.sort(reverse=True)
n.sort(reverse=True)
ri=0
bi=0
ni=0
ans=0
while ri+bi+ni<x+y:
    l=[n[bi]]
    if ri<x:
        l.append(r[ri])
    if bi<y:
        l.append(b[bi])
    t=max(l)
    if r[ri]==t and ri<x:
        ans+=r[ri]
        ri+=1
    elif b[bi]==t and bi<y:
        ans+=b[bi]
        bi+=1
    else:
        ans+=n[ni]
        ni+=1
print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque
x,y,a,b,c = map(int,input().split())
red = [int(i) for i in input().split()]
g = [int(i) for i in input().split()]
w = [int(i) for i in input().split()]
red.sort(reverse=True)
g.sort(reverse=True)
g = g[:y]
gw = g+w
gw.sort(reverse=True)
gwrui = []
rui = 0
for i in range(y+c):
    rui += gw[i]
    gwrui.append(rui)
redq = deque(red[:x])
ans = 0
oisr = 0
#print(red,gw,gwrui)
for i in range(1,x+1):
    oisr += redq.popleft()
    temp = oisr
    temp += gwrui[x+y-i-1]
    ans = max(ans,temp)
print(ans)

Submission status: Runtime Error

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

# X, Y, A, B, C = 1, 2, 2, 2, 1
# p = [2, 4]
# q = [5, 1]
# r = [3]

p.sort()
q.sort()
r.sort()
p = p[-X:]
q = q[-Y:]

d = []
d += p
d += q
d += r
d.sort()

print(sum(d[-X-Y:]))

Submission status: Runtime Error

Solution code:
# coding: utf-8

x, y, a, b, c = map(int,input().split())
L = []
Pa = list(map(int,input().split()))
Pb = list(map(int,input().split()))
Pc = list(map(int,input().split()))
Pa.sort(reverse = True)
Pb.sort(reverse = True)
Pc.sort(reverse = True)

ca = 0
cb = 0
cc = 0
flg1 = True
flg2 = True
ans = 0
for i in range(x+y):
    if ca == x:
        flg1 = False
        ca = 0
        Pa[ca] = 0
    if cb == y:
        flg2 = False
        cb = 0
        Pb[cb] = 0
    if Pa[ca] == max(Pa[ca], Pb[cb], Pc[cc]) and flg1:
        ans += Pa[ca]
        ca += 1
    elif Pb[cb] == max(Pa[ca], Pb[cb], Pc[cc]) and flg2:
        ans += Pb[cb]
        cb += 1
    else:
        ans += Pc[cc]
        cc += 1

print(ans)

Submission status: Runtime Error

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

def mergef(a,b):
    c = []
    h = j = 0
    while j<len(a) and h<len(b):
        if a[j]>b[h]:
            c.append(a[j])
            j+=1
        else:
            c.append(b[h])
            h+=1
    if j==len(a):
        for i in b[h:]:
            c.append(i)
    else:
        for i in a[j:]:
            c.append(i)
    return c

def merge_sortf(lists):
    if len(lists) <= 1:
        return lists
    middle = int(len(lists)/2)
    left = merge_sortf(lists[:middle])
    right = merge_sortf(lists[middle:])
    return mergef(left,right)


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

pm=merge_sortf(p)
qm=merge_sortf(q)
rm=merge_sortf(r)

k=0;i=X-1;j=Y-1
while i>=0 and j>=0 and k<C:
    if min((pm[i]-rm[k]),(qm[j]-rm[k])) < 0 :
        if pm[i]>=qm[j] :
            qm[j]=rm[k]
            j=j-1
        elif pm[i]<qm[j]:
            pm[i]=rm[k]
            i=i-1
        else:

    elif min((pm[i]-rm[k]),(qm[j]-rm[k])) > 0:
        break
    k=k+1

ans=sum(pm[:X])+sum(qm[:Y])
print(ans)

Submission status: Runtime Error

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()))
aa.sort(reverse=True)
bb.sort(reverse=True)
cc.sort(reverse=True)

aaa = []
bbb = []
aaa = aa[:x]
bbb = bb[:y]

aaa.extend(bbb)
aaa.sort()

for i in range(len(cc)):
    if aaa[i] < cc[i]:
        aaa[i] = cc[i]
print(sum(aaa))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

from collections import deque 
from functools import reduce

# input = sys.stdin.readline

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

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

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

p_np = np.zeros(999999)
q_np = np.zeros(999999)

if len(p) > x:
    p_np[:x] = p[:x]
else:
    l_p = len(p)
    p_np[:l_p] = p[:]

if len(q) > y:
    q_np[:y] = q[:y]
else:
    l_q = len(q)
    q_np[:l_q] = q[:]
ap_np = np.hstack((p_np[:x], q_np[:y]))
ap_np.sort()
ap_cnt = 0

for i, ri in enumerate(r):
    if (r[i] > ap_np[i]):
        ap_np[i] = r[i]
    if i >= x + y:
        break
print(int(ap_np.sum()))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

from collections import deque 
from functools import reduce

# input = sys.stdin.readline

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

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

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

p_np = np.zeros(999999)
q_np = np.zeros(999999)

if len(p) > x:
    p_np[:x] = p[:x]
else:
    p_np[:len(p)] = p[:]

if len(q) > y:
    q_np[:y] = q[:y]
else:
    q_np[:len(q)] = q[:]    

ap_np = np.hstack((p_np[:x], q_np[:y]))
ap_np.sort()
ap_cnt = 0

for i, ri in enumerate(r):
    if (r[i] > ap_np[i]):
        ap_np[i] = r[i]
    if i >= x + y:
        break
print(int(ap_np.sum()))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

from collections import deque 
from functools import reduce

# input = sys.stdin.readline

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

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

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

p_np = np.zeros(999999)
q_np = np.zeros(999999)

if len(p) > x:
    p_np[:x] = p[:x]
else:
    p_np[:len(p)] = p[:]

if len(q) > y:
    q_np[:y] = q[:y]
else:
    q_np[:len(q)] = q[:]    

ap_np = np.hstack((p_np[:x], q_np[:y]))
ap_np.sort()
ap_cnt = 0

for i, ri in enumerate(r):
    if (r[i] > ap_np[i]):
        ap_np[i] = r[i]
        break
print(int(ap_np.sum()))