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:
import sys
import math
import collections
from collections import deque
#x = int(input())
x, y, A, B, C = map(int, sys.stdin.readline().split())
#s = input()

def ijpop():
    if ic < A:
        if jc < B:
            return (p.popleft(), q.popleft())
        else:
            return (p.popleft(), 0)
    else:
        if jc < B:
            return (0, q.popleft())
        else:
            return (0, 0)

def ikpop():
    if ic < A:
        if kc < C:
            return (p.popleft(), r.popleft())
        else:
            return (p.popleft(), 0)
    else:
        if kc < C:
            return (0, r.popleft())
        else:
            return (0, 0)

def jkpop():
    if jc < B:
        if rc < C:
            return (q.popleft(), r.popleft())
        else:
            return (q.popleft(), 0)
    else:
        if rc < C:
            return (0, r.popleft())
        else:
            return (0, 0)

def ipop():
    if ic < A:
        return p.popleft()
    else:
        return 0

def jpop():
    if jc < B:
        return q.popleft()
    else:
        return 0

def kpop():
    if kc < C:
        return r.popleft()
    else:
        return 0

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

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

p = deque(a)
q = deque(b)
r = deque(c)

ans = 0
xc = 1
yc = 1
i = p.popleft()
j = q.popleft()
k = r.popleft()
ic = 1
jc = 1
kc = 1
while (True):
    if kc <= C:
        if xc <= x and yc <= y:
            if i >= k and j >= k:
                ans += (i+j)
                xc += 1
                yc += 1
                i, j = ijpop()
            elif i >= k and j < k:
                ans += (i+k)
                xc += 1
                yc += 1
                i, k = ikpop()
                kc += 1
            elif i < k and j >= k:
                ans += (j+k)
                xc += 1
                yc += 1
                j, k = jkpop()
                kc += 1
            else:
                ans += k
                if i >= j:
                    yc += 1
                    j, k = jkpop()
                else:
                    xc += 1
                    i, k = jkpop()
                kc += 1
                    
            continue

        elif xc > x and yc <= y:
            if j >= k:
                ans += j
                yc += 1
                j = jpop()
            else:
                ans += k
                yc += 1
                k = kpop()
                kc += 1

            continue

        elif xc <= x and yc > y:
            if i >= k:
                ans += i
                xc += 1
                i = ipop()
            else:
                ans += k
                xc += 1
                k = kpop()
                kc += 1

            continue

        else:
            break

    else:
        while (xc <= x):
            ans += i
            i = ipop()
            xc += 1
        while (yc <= y):
            ans += j
            j = jpop()
            yc += 1

        break

print(ans)

Submission status: Runtime Error

Solution code:
 
X, Y, A, B, C = [int(i) for i in input().split()]
P = sorted([int(i) for i in input().split()])[-X:]
Q = sorted([int(i) for i in input().split()])[-Y:]
R = sorted([int(i) for i in input().split()])[::-1]
heapq.heapify(P)
heapq.heapify(Q)
i = 0
while(True):
    if P[0] >= R[i] and Q[0] >= R[i]:
        break
    if P[0] > Q[0]:
        if Q[0] < R[i]:
            heapq.heappop(Q)
            heapq.heappush(Q, R[i])
    else:
        if P[0] < R[i]:
            heapq.heappop(P)
            heapq.heappush(P, R[i])
    i += 1
    if i == len(R):
        break
print(sum(P) + sum(Q))

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)

ans = sum(p[:x]) + sum(q[:y])

i, j = 0, 0
while i < x and j < y and i + j < c:
    change = min(p[x - 1 - i], q[y - 1 - j])
    if r[i + j] > change:
        ans += r[i + j] - change
    elif:
        break
    if p[x - 1 - i] < q[y - 1 - j]:
        i += 1
    elif p[x - 1 - i] > q[y - 1 - j]:
        j += 1
    else:
        s, t = 0, 0
        while i + s < x and j + t < y and i + j + s + t < c:
            if p[x - 1 - i - s] < q[y - 1 - j - s]:
                i += 1
                break
            elif p[x - 1 - i - s] > q[y - 1 - j - s]:
                j += 1
                break
            else:
                s += 1
                t += 1
                if not(i + s < x and j + t < y and i + j + s + t < c):
                    i += 1
                    break

print(ans)

Submission status: Runtime Error

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

p.sort()
q.sort()
r.sort()

x=0
y=0

for i in range(0,X):
  x += max(p[-1],r[-1])
  if max(p[-1],r[-1]) ==  p[-1]:
    del p[-1]
  elif max(p[-1],r[-1]) ==  r[-1]:
    del r[-1]
    
for i in range(0,Y):
  y += max(q[-1],r[-1])
  if max(q[-1],r[-1]) ==  q[-1]:
    del q[-1]
  elif max(q[-1],r[-1]) ==  r[-1]:
    del r[-1]

    
print(x+y)

Submission status: Runtime Error

Solution code:
##E
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)

psum = 0
plist = []

for i in range(X):
        plist.append(p[i])
for i in range(Y):
        plist.append(q[i])
        
plist.sort()
        
for i in range(C):
    if r[i] > plist[0]:
        plist.pop(i)
        plist.append(r[i])
        
print(sum(plist))

Submission status: Runtime Error

Solution code:
import heapq

i = list(map(int, input().split()))
X = i[0]
Y = i[1]
A = i[2]
B = i[3]
C = i[4]
r = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

r = list(map(lambda x:x*(-1), r)) #各要素を-1倍
b = list(map(lambda x:x*(-1), b))
c = list(map(lambda x:x*(-1), c))
heapq.heapify(r) #リストのヒープ化
heapq.heapify(b)
heapq.heapify(c)

r2 = []
b2 = []
a = []

for i in range(X):
    r2.append(heapq.heappop(r)*(-1))
for i in range(Y):
    b2.append(heapq.heappop(b)*(-1))

for i in range(len(r2)):
    a.append(heapq.heappop(r2))
for i in range(len(b2)):
    a.append(heapq.heappop(b2))
    
heapq.heapify(a)

while a[0] < c[0]*-1:
    heapq.heappop(a)
    a.append(heapq.heappop(c)*(-1))
    heapq.heapify(a)
    
sum(a)

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)
ans = 0
ans += sum(p[:x])
ans += sum(q[:y])
pq = p[:x] + q[:y]
pq = sorted(pq)
if a+b >= c:
  for i in range(c):
    if pq[i] < r[i]:
      ans = ans - pq[i] + r[i]
  print(ans)
else:
  for i in range(c-a-b):
    ans += r[i]
  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(x+y):
  ptmp = 0
  qtmp = 0
  valid_p = True
  valid_q = True
  if pidx < a:
  	ptmp = p[pidx]
  else:
    valid_p = False
  if qidx < b:
    qtmp = q[qidx]
  else:
    valid_q = False
  sel_p = True # pを探索
  if valid_q:
    if not valid_p:
      sel_p = False
    elif ptmp<qtmp:
      sel_p = False
  rtmp = r[c - 1 - i] # 逆順
  if sel_p:
    if ptmp < rtmp and pidx < a:
      p[pidx] = rtmp
      pidx += 1
  else:
    if qtmp < rtmp and qidx < b:
      q[qidx] = rtmp
      qidx += 1
print (sum(p) + sum(q))

Submission status: Runtime Error

Solution code:
from itertools import *

def merge(x,y):
  while 1:
    if x and y and x[0] >= y[0] or (not (x and y)) and x:
      yield x.pop(0)
    else y:
      yield y.pop(0)
    else:
      return

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

S = sum(islice(merge(P,R), X))
S += sum(islice(merge(Q,R), Y))
print(S)

Submission status: Runtime Error

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

ra = list(map(int, input().split()))
gb = list(map(int, input().split()))
sc = list(map(int, input().split()))

ra.sort(reverse=True)
gb.sort(reverse=True)
sc.sort(reverse=True)

curr_red_min_val = ra[x-1]
curr_green_min_val = gb[y-1]
tmp_x = x
tmp_y = y

for i in range(c):
  if tmp_x > 0 and curr_red_min_val < curr_green_min_val:
    if sc[i] > curr_red_min_val:
      ra[tmp_x-1] = sc[i]
      tmp_x -= 1
      if tmp_x != 0:
        curr_red_min_val = ra[tmp_x-1]
      else:
        curr_red_min_val = ra[0]
  else tmp_y > 0:
    if sc[i] > curr_green_min_val:
      gb[tmp_y-1] = sc[i]
      tmp_y -= 1
      if tmp_y != 0:
        curr_green_min_val = gb[tmp_y-1]
      else:
        curr_green_min_val = gb[0]
      
print(sum(ra[:x])+sum(gb[:y]))

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

import copy

pp = p[:]
qq = q[:]
rr = r[:]

count = 0
another_count = 0

check_r = []
check_g = []
# 赤く塗り替える
# 赤いりんごX
for i in range(X):
    max_red = 0
    if max(p)>=max(r):
        max_red = max(p)
        p.remove(max_red)
    else:
        max_red = max(r)
        check_r.append(max_red)
        r.remove(max_red)

    count += max_red


# 緑のりんごY
for i in range(Y):
    max_green = 0
    if max(q)>=max(r):
        max_green = max(q)
        q.remove(max_green)
    else:
        max_green = max(r)
        r.remove(max_green)
    count += max_green

#
# # 緑に塗り替える
# # 緑のりんごY
# for i in range(Y):
#     max_green = 0
#     if max(qq)>=max(rr):
#         max_green = max(qq)
#         qq.remove(max_green)
#     else:
#         max_green = max(rr)
#
#         rr.remove(max_green)
#
#     another_count += max_green
#
#
# # 赤いりんごX
# for i in range(X):
#     max_red = 0
#     if max(pp)>=max(rr):
#         max_red = max(pp)
#         pp.remove(max_red)
#     else:
#         max_red = max(rr)
#         check_g.append(max_red)
#         rr.remove(max_red)
#     another_count += max_red

print(count)
# print(another_count)

Submission status: Runtime Error

Solution code:
#200329E
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)
R = sorted(r)
Red = p + r
Red = sorted(Red)
Deli =[]

for i in range(X):
    Deli.append(Red[len(Red)-1-i])
    if Red[len(Red)-1-i] == P[len(P)-1-i]:
        Red[len(Red)-1-i] = 0
        #print(Red)
        P[len(P)-1-i]= 0
    else:
        Red[len(Red)-1-i] = 0
        R[len(R)-1-i]= 0

Green = q + R
Green = sorted(Green)
for i in range(Y):
    Deli.append(Green[len(Green)-1-i])
    Green[len(Green)-1-i] = 0
    
#print(Deli)
print(int(sum(Deli)))

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)

red=0
green=0
no=0
ans=0

while True:
    if red>x-1 and green>y-1:
        break
    if no<=c-1:
        if red>x-1:
            if q[green]>=r[no]:
                ans+=q[green]
                green+=1
            else:
                ans+=r[no]
                green+=1
                no+=1
        elif green>y-1:
            if p[green]>=r[no]:
                ans+=p[red]
                red+=1
            else:
                ans+=r[no]
                red+=1
                no+=1
        else:
            if max(p[red],q[green],r[no])==p[red]:
                ans+=p[red]
                red+=1
            elif max(p[red],q[green],r[no])==q[green]:
                ans+=q[green]
                green+=1
            else:
                if p[red]>q[green]:
                    q[green]=r[no]
                else:
                    p[red]=r[no]
                no+=1
    else:
        ans+=sum(p[red:x])
        ans+=sum(q[green:y])
        break
print(ans)

Submission status: Runtime Error

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

sump = sum(p)
sumq = sum(q)
ans = sump + sumq
for c in range(C):
    rc = r[c]
    if p[-1] < rc:
        sump -= p.pop()
        sump += rc
    elif q[-1] < rc:
        sumq -= q.pop()
        sumq += rc
    ans = max(ans, sump + sumq)
print(ans)

Submission status: Runtime Error

Solution code:
#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    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()))
    i,j,k = 0,0,0
    p.sort(reverse=1)
    q.sort(reverse=1)
    r.sort(reverse=1)
    res = 0
    while k<c and i<X and j<Y:
        s = p[i]
        t = q[j]
        u = r[k]
        if s<t and s<u:
            res += t+u
            j += 1
            k += 1
        elif t<s and t<u:
            res += s+u
            i += 1
            k += 1
        else:
            res += s+t
            i += 1
            j += 1
    if i==X:
        l = q[j:] + r[k:]
        l.sort(reverse=1)
        res += sum(l[:X+Y-i-j-k])
    elif j==Y:
        l = p[i:] + r[k:]
        l.sort(reverse=1)
        res += sum(l[:X+Y-i-j-k])
    else:
        res = 0
        for i in range(X+Y-c):
            if i < X and X+Y-c-i<Y:
                res = max(res, p[:i]+q[:X+Y-c-i])
            else:
                continue
        res += sum(r)
    print(res)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#コンマで区切る
A_list = input().split(' ')
    
#コンマで区切る
p_list = input().split(' ')
for i in range(len(p_list)):
    p_list[i] = int(p_list[i])
p_list = p_list.sort()

#コンマで区切る
q_list = input().split(' ')
for i in range(len(q_list)):
    q_list[i] = int(q_list[i])
q_list = q_list.sort()

#コンマで区切る
r_list = input().split(' ')
for i in range(len(r_list)):
    r_list[i] = int(r_list[i])
r_list = r_list.sort()    
    
ans_list = []
#無色を考えない
del p_list[X:]
del q_list[Y:]

ans_list = p_list + p_list
ans_list = ans_list.sort()





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

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)

red = P[:X]
green = Q[:Y]
ans = sum(red) + sum(green)

ridx = 0
redidx = -1
greenidx = -1

for i in range(X+Y):
    if (red[redidx] < green[greenidx] and abs(redidx) <= len(red)) or abs(greenidx) > len(green):
        if red[redidx] < R[ridx]:
            ans -= red[redidx]
            ans += R[ridx]
            ridx += 1
            redidx -= 1
    elif (red[redidx] > green[greenidx] and abs(greenidx) <= len(green)) or abs(redidx) > len(red):
        if green[greenidx] < R[ridx]:
            ans -= green[greenidx]
            ans += R[ridx]
            ridx += 1
            greenidx -= 1

    if ridx == len(R):
        break

print(ans)

Submission status: Runtime Error

Solution code:
x, y, a, b, c = map(int, input().split())
arrayP = list(map(int, input().split()))
arrayQ = list(map(int, input().split()))
arrayR = list(map(int, input().split()))
arrayP.sort(reverse=True)
arrayQ.sort(reverse=True)
arrayR.sort(reverse=True)
arrayAns = []
for i in range(x):
    arrayAns.append(int(arrayP[i]))
for i in range(y):
    arrayAns.append(int(arrayQ[i]))
arrayAns.sort()
for i in range(len(arrayR)):
    if arrayAns[i] <= int(arrayR[i]):
        arrayAns[i] = int(arrayR[i])
    else:
        break
print(sum(arrayAns))

Submission status: Runtime Error

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
    countC = 0
    ans = 0
    i = 0
    j = 0
    k = 0
    while countA < X and countB < Y and countC < C:
        if r[k] >= p[i] and r[k] >= q[j]:
            countC += 1
            ans += r[k]
            k += 1
        else:
            if p[i] > r[k]:
                countA += 1
                ans += p[i]
                i += 1
            elif q[j] > r[i]:
                countB += 1
                ans += q[j]
                j += 1

    if countA == X:
        targ = q[j:] + r[k:]
        targ.sort(reverse = True)
        ans += sum(targ[:Y-countB-countC])
        return ans

    if countB == Y:
        targ = p[i:] + r[k:]
        targ.sort(reverse = True)
        ans += sum(targ[:X-countA-countC])
        return ans

    p = p[i:]
    q = q[j:]
    pp = [0]
    qq = [0]

    for i in range(len(p)):
        pp.append(pp[-1] + p[i])
    for i in range(len(q)):
        qq.append(qq[-1] + q[i])

    out = ans
    for k in range(countC+1):
        m = X-k
        n = Y-(countC-k)
        if 0<= m < len(pp) and 0<= n < len(qq):
            out = max(out, ans + pp[m] + qq[n])

    return out


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

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
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 = sum(p[-x:])+sum(q[-y:])
x_pos = -x
y_pos = -y
for i in range(c):
    #したから見ていく
    if min(p[x_pos],q[y_pos]) >= r[i]:
        continue
    elif p[x_pos] > q[y_pos]:
        ans += r[i] - q[y_pos]
        y_pos -= 1
    else:
        ans += r[i] - p[x_pos]
        x_pos -= 1
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)

p_point = 0
q_point = 0
r_point = 0

ans = 0

for i in range(x):

    try:

        if p[p_point] > r[r_point]:
            ans += p[p_point]
            p_point += 1
        else:
            ans += r[r_point]
            r_point += 1
    except:
        ans += r[r_point]
        r_point += 1


for i in range(y):
    try:
        if q[q_point] > r[r_point]:
            ans += q[q_point]
            q_point += 1
        else:
            ans += r[r_point]
            r_point += 1
    except:
        ans += r[r_point]
        r_point += 1
print(ans)

Submission status: Runtime Error

Solution code:
X, Y, A, B, C = 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_list = P[:X]
ANS_list.extend(Q[:Y])
ANS_list.sort()
c = 0
for i in range(len(R)):
    if ANS_list[i] >= R[i]:
        break
    c+=1

if i!=0:
    ANS_list[:c] = R[:c]

print(sum(R[:c])+sum(ANS_list[c:]))

Submission status: Runtime Error

Solution code:
x, y, a, b, c = map(int,input().split())
p = sorted(list(map(int,input().split())))[a-x:]
q = sorted(list(map(int,input().split())))[b-y:]
r = sorted(list(map(int,input().split())), reverse = True)
P=0
Q=0
for i in range(c):
  if p[P] < r[i] or q[Q] < r[i]:
    if p[P] >= q[Q]:
      q[Q]=r[i]
      if Q < b-2:
        Q += 1
    else:
      p[P]=r[i]
      if P < a-2:
        P += 1
  else:
    break
print(sum(p)+sum(q))

Submission status: Runtime Error

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  x,y,a,b,c=LI()
  la=LI()
  lb=LI()
  lc=LI()

  la.sort(reverse=True)
  lb.sort(reverse=True)
  lc.sort()

  ans_list=[]
  ans_list+=la[:x]
  ans_list+=lb[:y]

  ans_list.sort(reverse=True)
  # print(ans_list)
  i=0
  for _ in range(c):
    if len(lc)==0:
      break
    if x+y<len(lc):
      lc.pop()
    else:
      while True:
        if len(ans_list)<=i:
          break
        _c=lc.pop()
        if ans_list[i]<_c:
          ans_list[i]=_c
        else:
          lc.append(_c)
        i+=1

  # print(ans_list)
  return sum(ans_list)

# main()
print(main())

Submission status: Runtime Error

Solution code:
IN = iter(Input.split('\n')).__next__
def input():
    return IN()

# 入力
from collections import deque
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
p += [0]
q = list(map(int, input().split()))
q += [0]
r = list(map(int, input().split()))
r += [0]
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
n, m, l = 0, 0, 0
ans = 0
for i in range(x+y):
    if (p[n] >= r[l] or q[n] >= r[l]) and n < x and m < y:
        if p[n] >= q[m]:
            ans += p[n]
            n += 1
        else:
            ans += q[m]
            m += 1
    elif n == x:
        if q[m] >= r[l]:
            ans += q[m]
            m += 1
        else:
            ans += r[l]
            m += 1
            l += 1
    elif m == y:
        if p[n] >= r[l]:
            ans += p[n]
            n += 1
        else:
            ans += r[l]
            n += 1
            l += 1    
    else:
        if p[n] >= q[m]:
            ans += r[l]
            m += 1
            l += 1
        else:
            ans += r[l]
            n += 1
            l += 1
print(ans)

Submission status: Runtime Error

Solution code:
X, Y, A, B, C = map(int,input().split()) 
P = [list(map(int,input().split())) for i in range(3)]
Red = sorted(P[0], reverse=True)
Green = sorted(P[1], reverse=True)
Trans = sorted(P[2], reverse=True)

pre_max = sum(Red[:X]) + sum(Green[:Y])
Red = Red[:X]
Green = Green[:Y]
for i in range (C):
  maxo = pre_max
  if (Trans[i] > Red[-1+i]):
    maxo= pre_max + Trans[i] - Red[-1+i]
for i in range (C):
  if (Trans[i] > Green[-1+i]):
    maxo = pre_max + Trans[i] - Green[-1+i]
    
print(maxo)

Submission status: Runtime Error

Solution code:
i = list(map(int, input().split()))
red=list(map(int, input().split()))
green=list(map(int, input().split()))
white=list(map(int, input().split()))
list=[]
a=0
b=0
c=0
for j in range(i[2]-i[0],i[2]-1):
    a=red.pop(max(red))
    list.append(a)
for j in range(i[3]-i[1],i[3]-1):
    b=green.pop(max(red))
    list.append(b)
for j in range(i[0]+i[1]):
    if max(white)>min(list):
        list.remove(min(list))
        list.append(max(white))
    else:
        break
print(sum(list))

Submission status: Runtime Error

Solution code:
from collections import defaultdict
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)
dp = defaultdict(int)
dq = defaultdict(int)
dr = defaultdict(int)
ans = 0
ans += sum(p[:x])
ans += sum(q[:y])
pq = p[:x] + q[:y]
pq = sorted(pq)
for i in range(c):
  if pq[i] < r[i]:
    ans = ans - pq[i] + r[i]
print(ans)

Submission status: Runtime Error

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

p = p[:x]
q = q[:y]
r = r
e = 0
for i in range(min(x, y, c)):
    if p[-1-i] > q[-1-i]:
        if q[-1-i] < r[i+e]:
            q[-1-i] = r[i+e]
            e += 1
        else:
            continue
    elif p[-1-i] <= q[-1-i]:
        if p[-1-i] < r[i+e]:
            p[-1-i] = r[i+e]
            e += 1
            
print(sum(p)+sum(q))

Submission status: Runtime Error

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

from bisect import insort

p_list = []
q_list = []
r_list = []

for value in input().split():
  value = int(value)
  if len(p_list) >= x:
    if p_list[x-1] < value:
      insort(p_list,value)
      p_list = p_list[:x+1]
  else:
    insort(p_list,value)

for value in input().split():
  value = int(value)
  if len(q_list) >= y:
    if q_list[y-1] < value:
      insort(q_list,value)
      q_list = q_list[:y+1]
  else:
    insort(q_list,value)
  
for value in input().split():
  value = int(value)
  if len(r_list) >= x+y:
    if r_list[x+y-1] < value:
      insort(r_list.value)
      r_list = r_list[:x+y+1]
  else:
    insort(r_list,value)
  
red = 0
green = 0
white = 0

sum_num = 0

for i in range(1,x+y+1):
  if red < x:
  	red_num = p_list[(red*-1)-1]
  else:
    red_num = 0
  if green < y:
  	green_num = q_list[(green*-1)-1]
  else:
    green_num = 0
  if white < c:
  	white_num = r_list[(white*-1)-1]
  else:
    white_num = 0
  
  max_p = max([red_num,green_num,white_num])
  sum_num += max_p
  if max_p == white_num:
    white += 1
  elif max_p == red_num:
    red += 1
  elif max_p == green_num:
    green += 1

print(sum_num)

Submission status: Runtime Error

Solution code:
X, Y, A, B, C = map(int, input().strip().split())
p = list(map(int, input().strip().split()))
q = list(map(int, input().strip().split()))
r = list(map(int, input().strip().split()))
p.sort()
q.sort()
r.sort()
sum = 0
rcounter = 0
while X > 0 and Y > 0 and len(r) > 0:
    if p[-1] > q[-1] and p[-1] > r[-1]:
        X -= 1
        sum += p[-1]
        del p[-1]
    if q[-1] > p[-1] and q[-1] > r[-1]:
        Y -= 1
        sum += q[-1]
        del q[-1]
    if r[-1] > p[-1] and r[-1] > q[-1]:
        X -= 1
        Y -= 1
        sum += r[-1]
        del r[-1]
if X == 0:
    NEW = q + r
    NEW.sort()
    for i in range(Y):
        sum += NEW[-1]
        del NEW[-1]
if Y == 0:
    NEW = p + r
    NEW.sort()
    for i in range(X):
        sum += NEW[-1]
        del NEW[-1]
if len(r) == 0:
    for i in range(X):
        sum += p[-1]
        del p[-1]
    for i in range(Y):
        sum += q[-1]
        del q[-1]
NEW = p + q
NEW.sort()
for i in range(rcounter):
    sum += NEW[-1]
    del NEW[-1]
print(sum)

Submission status: Runtime Error

Solution code:
import sys

# import bisect
from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

import heapq


class Reverse:
    def __init__(self, val):
        self.val = val

    def __lt__(self, other):
        return self.val > other.val

    def __repr__(self):
        return repr(self.val)


class PriorityQueue:

    def __init__(self, x=[], desc=False):
        if desc:
            for i in range(len(x)):
                x[i] = Reverse(x[i])
        self._desc = desc
        self._container = x
        heapq.heapify(self._container)

    @property
    def is_empty(self):
        return not self._container

    def pop(self):
        if self._desc:
            return heapq.heappop(self._container).val
        else:
            return heapq.heappop(self._container)

    def push(self, item):
        if self._desc:
            heapq.heappush(self._container, Reverse(item))
        else:
            heapq.heappush(self._container, item)

    def top(self):
        if self._desc:
            return self._container[0].val
        else:
            return self._container[0]

    def __len__(self):
        return len(self._container)


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

    pp = PriorityQueue(p, desc=True)
    qq = PriorityQueue(q, desc=True)
    rr = PriorityQueue(r, desc=True)

    ans = 0
    for i in range(x):
        ptemp = pp.top()
        rtemp = rr.top()
        if ptemp >= rtemp:
            ans += pp.pop()
        else:
            ans += rr.pop()

    for j in range(y):
        qtemp = qq.top()
        rtemp = rr.top()
        if qtemp >= rtemp:
            ans += qq.pop()
        else:
            ans += rr.pop()

    print(ans)

if __name__ == '__main__':
    main()