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 numpy as np
#inp = input
fin = open("case_21.txt")
inp = fin.readline

X, Y, A, B, C = map(int, inp().split())

red = np.array(list(map(int, inp().split())), np.int32)
green = np.array(list(map(int, inp().split())), np.int32)
white = np.array(list(map(int, inp().split())), np.int32)
fin.close()

red[::-1].sort()
green[::-1].sort()
white[::-1].sort()
idr = 0
idg = 0
idw = 0

total = 0.0
countr = 0
countg = 0
while X > countr and Y > countg:
    if red[idr] > green[idg]:
        #compare green 1st
        if idw < C and green[idg] < white[idw]:
            #eat white
            total += white[idw]
            idw += 1
        else:
            #eat green
            total += green[idg]
            idg += 1
        countg += 1

    else:
        #compare red 1st
        if idw < C and red[idr] < white[idw]:
            #eat white
            total += white[idw]
            idw += 1
        else:
            #eat red
            total += red[idr]
            idr += 1

        countr += 1

#eat remain
while X > countr:
    # compare red 1st
    if idw < C and red[idr] < white[idw]:
        # eat white
        total += white[idw]
        idw += 1
    else:
        # eat red
        total += red[idr]
        idr += 1
    countr += 1

while Y > countg:
    # compare green 1st
    if idw < C and green[idg] < white[idw]:
        # eat white
        total += white[idw]
        idw += 1
    else:
        # eat green
        total += green[idg]
        idg += 1
    countg += 1

print(int(total))

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

P = sorted(P, reverse=True)[:X]
Q = sorted(Q, reverse=True)[:Y]

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

Submission status: Runtime Error

Solution code:
import heapq
x,y,a,b,c = map(int,input().split())
red = list(map(int,input().split()))
green = list(map(int,input().split()))
clear = list(map(int,input().split()))
heapq.heapify(red)
heapq.heapify(green)
heapq.heapify(clear)
while(1):
    if len(clear):
        current_red = heapq.heappop(red)
        current_green = heapq.heappop(green)
        current_clear = heapq.heappop(clear)
        if current_clear < current_red and current_clear < current_green:
            break
        else:
            if current_red < current_green:
                heapq.heappush(red,currnet_clear)
                heapq.heappush(green,current_green)
            else:
                heapq.heappush(green,current_clear)
                heapq.heappush(red,current_red)
    else:
        break
print(sum(red[len(red)-x:])+sum(green[len(green)-y:]))

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

for i in range(C):
    if R[i] > ans[i]:
        ans[i] = R[i]

print(sum(ans))

Submission status: Runtime Error

Solution code:
from collections import deque 
#from copy import copy
#初期入力
X,Y,A,B,C = (int(x) for x in input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))


# ソート⇒無色と比較
p.sort()
q.sort()
r.sort()

p_dq =deque(p[A-X:])
q_dq =deque(q[B-Y:])
ans_sum =sum(p[A-X:]) + sum(q[B-Y:])
p_change =p_dq.popleft()
q_change =q_dq.popleft()
count_p =0
count_q =0
for i in r:
    if p_change < q_change:
        if i > p_change and count_p < X:
            count_p +=1
            ans_sum = ans_sum -p_change +i
            p_change =p_dq.popleft()

    elif p_change > q_change and count_q < Y:
        if i > q_change:
            count_q +=1
            ans_sum = ans_sum -q_change +i
            q_change =q_dq.popleft()
print(ans_sum)

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()), reverse=True)
pi = len(p) - x
qi = len(q) - y
ri = 0
for _ in range(len(r)):
    if r[ri] <= min(p[pi], q[qi]):
        break
    else:
        if pi >= len(p) and qi >= len(q):
            break
        else:
            if pi < len(p) and qi < len(q):
                if p[pi] < q[qi]:
                    p[pi] = r[ri]
                    pi += 1
                else:
                    q[qi] = r[ri]
                    qi += 1
            elif pi >= len(p) and qi < len(q):
                if q[qi] < r[ri]:
                    q[qi] = r[ri]
                    qi += 1
            elif pi < len(p) and qi >= len(q):
                if p[pi] < r[ri]:
                    p[pi] = r[ri]
                    pi += 1
            ri += 1
            continue
print(sum(p[-x:]) + sum(q[-y:]))

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()), reverse=True)
pi = len(p) - x
qi = len(q) - y
ri = 0
for _ in range(len(r)):
    if r[ri] <= min(p[pi], q[qi]):
        break
    else:
        if pi < len(p) and qi < len(q):
            if p[pi] < q[qi]:
                p[pi] = r[ri]
                pi += 1
                ri += 1
                continue
            else:
                q[qi] = r[ri]
                qi += 1
                ri += 1
                continue
        elif pi >= len(p) and qi < len(q):
            if q[qi] < r[ri]:
                q[qi] = r[ri]
                qi += 1
                ri += 1
                continue
        elif pi < len(p) and qi >= len(q):
            if p[pi] < r[ri]:
                p[pi] = r[ri]
                pi += 1
                ri += 1
                continue
        else:
            break
print(sum(p[-x:]) + sum(q[-y:]))

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()), reverse=True)
pi = len(p) - x
qi = len(q) - y
ri = 0
for _ in range(len(r)):
    if r[ri] <= min(p[pi], q[qi]):
        break
    else:
        if pi < len(p):
            if p[pi] < r[ri]:
                p[pi] = r[ri]
                pi += 1
                ri += 1
                continue
        if qi < len(q):
            if q[qi] < r[ri]:
                q[qi] = r[ri]
                qi += 1
                ri += 1
                continue
        else:
            break
print(sum(p[-x:]) + sum(q[-y:]))

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)

red = sorted(P[:X])
gre = sorted(Q[:Y])
ans = sum(red) + sum(gre) 
j, k = 0, 0

for i in range(min(X+Y,C)):
    if(red[j] <= gre[k]):
        if R[i] > red[j] :
            ans = ans - red[j] + R[i]
            j += 1
        else:
            break
    else:
        if R[i] > gre[k] :
            ans = ans - gre[k] + R[i]
            k += 1
        else:
            break
print(ans)

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)

red = sorted(P[:X])
gre = sorted(Q[:Y])
ans = sum(red) + sum(gre) 
j, k = 0, 0

for i in range(min(X+Y),C):
    if(red[j] <= gre[k]):
        if R[i] > red[j] :
            ans = ans - red[j] + R[i]
            j += 1
        else:
            break
    else:
        if R[i] > gre[k] :
            ans = ans - gre[k] + R[i]
            k += 1
        else:
            break
print(ans)

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)

red = sorted(P[:X])
gre = sorted(Q[:Y])
ans = sum(red) + sum(gre) 
j, k = 0, 0

for i in range(X+Y):
    if(red[j] <= gre[k]):
        if R[i] > red[j] :
            ans = ans - red[j] + R[i]
            j += 1
        else:
            break
    else:
        if R[i] > gre[k] :
            ans = ans - gre[k] + R[i]
            k += 1
        else:
            break
print(ans)

Submission status: Runtime Error

Solution code:
X,Y,A,B,C=map(int,input().split())
ls_a=sorted(list(map(int,input().split())))
ls_b=sorted(list(map(int,input().split())))
ls_c=sorted(list(map(int,input().split())))
ls_x=ls_a[A-X:A]
ls_y=ls_b[B-Y:B]
ls_c.reverse()

ans=sum(ls_x)+sum(ls_y)
a=b=c=0
for _ in range(X+Y):
  if a==len(ls_x):
    m=min([ls_y[b],ls_c[c]])
    if m==ls_y[b]:
      ans+=(-ls_y[b]+ls_c[c])
      b+=1
      c+=1
    else:
      break
  elif b==len(ls_y):
    m=min([ls_x[a],ls_c[c]])
    if m==ls_x[a]:
      ans+=(-ls_x[a]+ls_c[c])
      a+=1
      c+=1
    else:
      break
  else:    
    m=min([ls_x[a],ls_y[b],ls_c[c]])
    if m==ls_x[a]:
      ans+=(-ls_x[a]+ls_c[c])
      a+=1
      c+=1
    elif m==ls_y[b]:
      ans+=(-ls_y[b]+ls_c[c])
      b+=1
      c+=1
    else:
      break
print(ans)

Submission status: Runtime Error

Solution code:
X,Y,A,B,C=map(int,input().split())
ls_a=sorted(list(map(int,input().split())))
ls_b=sorted(list(map(int,input().split())))
ls_c=sorted(list(map(int,input().split())))
ls_x=ls_a[A-X:A]
ls_y=ls_b[B-Y:B]
ls_c.reverse()

ans=sum(ls_x)+sum(ls_y)
a=b=c=0
for i in range(C):
  m=min([ls_x[a],ls_y[b],ls_c[c]])
  if m==ls_x[a]:
    ans+=(-ls_x[a]+ls_c[c])
    a+=1
    c+=1
  elif m==ls_y[b]:
    ans+=(-ls_y[b]+ls_c[c])
    b+=1
    c+=1
  else:
    break
print(ans)

Submission status: Runtime Error

Solution code:
N = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]
Q = [int(i) for i in input().split()]
R = [int(i) for i in input().split()]

answerList = []

for i in range(N[0]):
    i = i + 1
    answerList.append(sorted(P)[-i])

for i in range(N[1]):
    i = i + 1
    answerList.append(sorted(Q)[-i])

for i in range(N[4]):
    if N[i] > min(answerList):
        for j in range(len(answerList)):
            if R[i] > answerList[j]:
                answerList[j] = R[i]

print(sum(answerList))

Submission status: Runtime Error

Solution code:
N = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]
Q = [int(i) for i in input().split()]
R = [int(i) for i in input().split()]

answerList = []

for i in range(N[0]):
    i = i + 1
    answerList.append(sorted(P)[-i])

for i in range(N[1]):
    i = i + 1
    answerList.append(sorted(Q)[-i])

for i in range(len(answerList)):
    i = i + 1
    for j in range(N[4]):
        j = j + 1
        if sorted(R)[j] > sorted(answerList)[-i]:
            answerList[-i] = R[j]
        break

print(sum(answerList))

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)

eat_list = []

for _ in range(x):
    if p[0] < r[0]:
        eat_list.append(r.pop(0))
    else:
        eat_list.append(p.pop(0))

for _ in range(y):
    if q[0] < r[0]:
        eat_list.append(r.pop(0))
    else:
        eat_list.append(q.pop(0))

print(sum(eat_list))

Submission status: Runtime Error

Solution code:
import sys
from io import StringIO
import unittest
import copy
def resolve():
    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(key=lambda xx: -xx)
    q.sort(key=lambda xx: -xx)
    r.sort(key=lambda xx: -xx)

    # 着色を一切行わない場合の値
    def_red = copy.copy(p[0:x])
    def_grren = copy.copy(q[0:y])

    # 無職のリンゴに置換していく・・
    redcnt = -1
    grncnt = -1
    for i in range(len(r)):
        if not (r[i] > def_red[redcnt] or r[i] > def_grren[grncnt]):
            continue

        if def_red[redcnt] > def_grren[grncnt] and r[i] > def_grren[grncnt]:
            def_grren[grncnt] = r[i]
            grncnt -= 1
        else:
            def_red[redcnt] = r[i]
            redcnt -= 1

    print(sum(def_red) + sum(def_grren))





class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """1 2 2 2 1
2 4
5 1
3"""
        output = """12"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """2 2 2 2 2
8 6
9 1
2 1"""
        output = """25"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4"""
        output = """74"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Runtime Error

Solution code:
import sys
from io import StringIO
import unittest

def resolve():
    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(key=lambda xx: -xx)
    q.sort(key=lambda xx: -xx)
    r.sort(key=lambda xx: -xx)

    # 着色を一切行わない場合の値
    def_red = p[0:x].copy()
    def_grren = q[0:y].copy()

    # 無職のリンゴに置換していく・・
    redcnt = -1
    grncnt = -1
    for i in range(len(r)):
        if not (r[i] > def_red[redcnt] or r[i] > def_grren[grncnt]):
            continue

        if def_red[redcnt] > def_grren[grncnt] and r[i] > def_grren[grncnt]:
            def_grren[grncnt] = r[i]
            grncnt -= 1
        else:
            def_red[redcnt] = r[i]
            redcnt -= 1

    print(sum(def_red) + sum(def_grren))





class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """1 2 2 2 1
2 4
5 1
3"""
        output = """12"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """2 2 2 2 2
8 6
9 1
2 1"""
        output = """25"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4"""
        output = """74"""
        self.assertIO(input, output)

if __name__ == "__main__":
    unittest.main()
    # resolve()

Submission status: Runtime Error

Solution code:
import sys
from io import StringIO
import unittest

def resolve():
    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(key=lambda xx: -xx)
    q.sort(key=lambda xx: -xx)
    r.sort(key=lambda xx: -xx)

    # 着色を一切行わない場合の値
    def_red = p[0:x].copy()
    def_grren = q[0:y].copy()

    # 無職のリンゴに置換していく・・
    redcnt = -1
    grncnt = -1
    for i in range(len(r)):
        if not (r[i] > def_red[redcnt] or r[i] > def_grren[grncnt]):
            continue

        if def_red[redcnt] > def_grren[grncnt] and r[i] > def_grren[grncnt]:
            def_grren[grncnt] = r[i]
            grncnt -= 1
        else:
            def_red[redcnt] = r[i]
            redcnt -= 1

    print(sum(def_red) + sum(def_grren))





class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """1 2 2 2 1
2 4
5 1
3"""
        output = """12"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """2 2 2 2 2
8 6
9 1
2 1"""
        output = """25"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4"""
        output = """74"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon May 25 15:06:19 2020

@author: Administrator
"""
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()
p = len(P)
q = len(Q)
r = len(R)
tot=0

while(X):
    if P[-1]>R[-1]:
        tot += P[-1]
        P.pop()
    else:
        tot += R[-1]
        R.pop()
    X-=1
while(Y):
    if Q[-1]>R[-1]:
        tot += Q[-1]
        Q.pop()
    else:
        tot += R[-1]
        R.pop()
    Y-=1
print(tot)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon May 25 15:06:19 2020

@author: Administrator
"""
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()
p = len(P)
q = len(Q)
r = len(R)
tot=0

while(X):
    if P[-1]>R[-1]:
        tot += P[-1]
        P.remove(P[-1])
    else:
        tot += R[-1]
        R.remove(R[-1])
    X-=1
while(Y):
    if Q[-1]>R[-1]:
        tot += Q[-1]
        Q.remove(Q[-1])
    else:
        tot += R[-1]
        R.remove(R[-1])
    Y-=1
print(tot)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon May 25 15:06:19 2020

@author: Administrator
"""
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()))

tot=0

while(X):
    if max(P)>max(R):
        tot += max(P)
        P.remove(max(P))
    else:
        tot += max(R)
        R.remove(max(R))
    X-=1
while(Y):
    if max(Q)>max(R):
        tot += max(Q)
        Q.remove(max(Q))
    else:
        tot += max(R)
        R.remove(max(R))
    Y-=1
print(tot)

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)
q = sorted(q)

p = p[(len(p)-x):]
q = q[(len(q)-y):]
r.append(p)
r.append(q)
r = sorted(r)
print(sum(r[(len(r)-x-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()))
p = sorted(p)
q = sorted(q)

p = p[(len(p)-x):]
q = q[(len(q)-y):]
r.append(p)
r.append(q)
sort(r)
print(sum(r[(len(r)-x-y):]))

Submission status: Runtime Error

Solution code:
def main():
    x, y, a, b, c = map(int, input().split())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))
    R = list(map(int, input().split()))
    t = [1]
    t.sort()
    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)

    s = P[:x] + Q[:y]
    s.sort()
    for i in range(x + y):
        if s[i] < R[i] and i < c:
            s[i] = R[i]
        else:
            break
    print(sum(s))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def main():
    x, y, a, b, c = map(int, input().split())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))
    R = list(map(int, input().split()))
    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)

    s = P[:x] + Q[:y]
    s.sort()
    for i in range(x + y):
        if s[i] < R[i]:
            s[i] = R[i]
        else:
            break
    print(sum(s))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

RO=list(map(int,input().split()))
GO=list(map(int,input().split()))
TO=list(map(int,input().split()))

RO.sort()
GO.sort()
TO.sort(reverse=True)

R=RO[A-X:A]
G=GO[B-Y:B]
ans=sum(R)+sum(G)

idxR=0
idxG=0
for i in range(C):
    t=TO[i]
    if idxR<A and idxG<B:
        mi=min(R[idxR],G[idxG],t)
        if mi==t:break
        elif mi==R[idxR]:
            ans=ans-R[idxR]+t
            idxR+=1
        elif mi==G[idxG]:
            ans=ans-G[idxG]+t
            idxG+=1
    elif idxR>=A and idxG<B:
        mi=min(G[idxG],t)
        if mi==t:break
        else:
            ans=ans-G[idxG]+t
            idxG+=1
    elif idxR<A and idxG>=B:
        mi=min(R[idxR],t)
        if mi==t:break
        else:
            ans=ans-R[idxR]+t
            idxR+=1
    elif idxR>=A and idxG>=B:break
print(ans)

Submission status: Runtime Error

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

RO=list(map(int,input().split()))
GO=list(map(int,input().split()))
TO=list(map(int,input().split()))

RO.sort()
GO.sort()
TO.sort(reverse=True)

R=RO[A-X:A]
G=GO[B-Y:B]
ans=sum(R)+sum(G)

idxR=0
idxG=0
for t in TO:
    if idxR<A and idxG<B:
        mi=min(R[idxR],G[idxG],t)
        if mi==t:break
        elif mi==R[idxR]:
            ans=ans-R[idxR]+t
            idxR+=1
        elif mi==G[idxG]:
            ans=ans-G[idxG]+t
            idxG+=1
    elif idxR>=A and idxG<B:
        mi=min(G[idxG],t)
        if mi==t:break
        else:
            ans=ans-G[idxG]+t
            idxG+=1
    elif idxR<A and idxG>=B:
        mi=min(R[idxR],t)
        if mi==t:break
        else:
            ans=ans-R[idxR]+t
            idxR+=1
    elif idxR>=A and idxG>=B:break
print(ans)

Submission status: Runtime Error

Solution code:
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
IronMan = sorted(p)
CaptainAmerica = sorted(q)
for i in range(X):
    r.append(IronMan.pop())
for i in range(Y):
    CaptainAmerica.append(q.pop())
SpiderMan = sorted(r)[::-1]
print(sum(SpiderMan[:X+Y]))

Submission status: Runtime Error

Solution code:
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
sorted(p)
sorted(q)
for i in range(X):
    r.append(p.pop())
for i in range(Y):
    r.append(q.pop())
SpiderMan = sorted(r)[::-1]
print(sum(SpiderMan[:X+Y]))

Submission status: Runtime Error

Solution code:
from collections import deque

x,y,ak,bk,ck = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

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

c = deque(c)
ab = a[:x]+b[:y]
ab.reverse()
j=0
for i in range(x+y):
    if ab[i+1] > c[-1]:
        break

    while c:
        if c[0] > ab[i]:
            ab[i] = c[0]
            c.popleft()
            break
        else:
            c.popleft()
    
    if c==[]:
        break
        
ans = sum(ab)
print(ans)

Submission status: Runtime Error

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

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

ab = a[:x]+b[:y]
ab.reverse()
j=0
for i in range(x+y):
    if ab[i] >= max(c[j:]):
        break
    while j <= ck-1:
        if c[j] > ab[i]:
            ab[i] = c[j]
            j+=1
            break
        j+=1

ans = sum(ab)
print(ans)

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()))
 
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
 
Z = 0
while Z < C:
  if min(p[X - 1], q[Y - 1], r[Z]) < r[Z]:
    if p[X - 1] < q[Y - 1]:
      X -= 1
      Z += 1
  	else:
      Y -= 1
      Z += 1
    continue
  break
 
print(sum(p[:X]) + sum(q[:Y]) + sum(r[:Z]))

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()))
 
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
 
Z = 0
while True:
  if p[X - 1] < r[Z]:
    X -= 1
    Z += 1
  elif q[Y - 1] < r[Z]:
    Y -= 1
    Z += 1
  else:
    break
 
print(sum(p[:X]) + sum(q[:Y]) + sum(r[:Z]))

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()))
 
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
 
Z = 0
while True:
  if p[X - 1] < r[Z]:
    X -= 1
    Z += 1
  else if q[Y - 1] < r[Z]:
    Y -= 1
    Z += 1
  else:
    break
 
print(sum(p[:X]) + sum(q[:Y]) + sum(r[:Z]))

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

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

Z = 0
while True:
  if max(p[X - 1], q[Y - 1], r[Z]) == r[Z]:
    if p[X - 1] < q[Y - 1]:
      X -= 1
      Z += 1
    else:
      Y -= 1
      Z += 1
  else:
    break

print(sum(p[:X]) + sum(q[:Y]) + sum(r[:Z]))

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

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

Z = 0
whlie True:
  if max(p[X - 1], q[Y - 1], r[Z]) == r[Z]:
    if p[X - 1] < q[Y - 1]:
      X -= 1
      Z += 1
    else:
      Y -= 1
      Z += 1
  else:
    break

print(sum(p[:X]) + sum(q[:Y]) + sum(r[:Z]))

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]+Q[:Y])
r,g,f=X,Y,0
while (R[f]>P[r] or R[f]>Q[g]) and r>=0 and g>=0 and f<C:
    if P[r]<Q[g]:
        ans=ans-P[r]+R[f]
        r-=1
        f+=1
    else:
        ans=ans-Q[g]+R[f]
        g-=1
        f+=1
print(ans)

Submission status: Runtime Error

Solution code:
X, Y, R, G, N = map(int, input().split())
r = [int(x) for x in input().split()]
g = [int(x) for x in input().split()]
n = [int(x) for x in input().split()]
r = sorted(r)[R-X:]
g = sorted(g)[G-Y:]
n = sorted(n, reverse=True)

nr = 0; ng = 0; nn = 0
for i in range(N):
    if n[nn] <= min(r[nr], g[ng]):
        break
    if ng < G and r[nr] > g[ng]:
        g[ng] = n[nn]
        ng += 1
    elif nr < R and r[nr] <= g[ng]:
        r[nr] = n[nn]
        nr += 1
    nn += 1

print(sum(r) + sum(g))

Submission status: Runtime Error

Solution code:
X, Y, R, G, N = map(int, input().split())
r = [int(x) for x in input().split()]
g = [int(x) for x in input().split()]
n = [int(x) for x in input().split()]
r = sorted(r)[R-X:]
g = sorted(g)[G-Y:]
n = sorted(n, reverse=True)

nr = 0; ng = 0; nn = 0
for i in range(N):
    if n[nn] <= min(r[nr], g[ng]):
        break
    if r[nr] > g[ng]:
        g[ng] = n[nn]
        ng += 1
    else:
        r[nr] = n[nn]
        nr += 1
    nn += 1

print(sum(r) + sum(g))

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

p_rev = sorted(p, reverse=True)
q_rev = sorted(q, reverse=True)
r_rev = sorted(r, reverse=True)
#print(p_rev[:x])
#print(q_rev[:y])
pq_rev = sorted(p_rev[:x] + q_rev[:y] , reverse=True)

num_r = len(r_rev)
start = len(pq_rev) - num_r

pq_cnt = 0
r_cnt = 0
total = 0
for i in range(len(pq_rev)):
  if pq_rev[pq_cnt] < r_rev[r_cnt] and r_cnt < num_r:
    total += r_rev[r_cnt]
    r_cnt += 1
  else:
    total += pq_rev[pq_cnt]
    pq_cnt += 1

print(total)

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

p_rev = sorted(p, reverse=True)
q_rev = sorted(q, reverse=True)
r_rev = sorted(r, reverse=True)
#print(p_rev[:x])
#print(q_rev[:y])
pq_rev = sorted(p_rev[:x] + q_rev[:y] , reverse=True)

num_r = len(r_rev)
start = len(pq_rev) - num_r

pq_cnt = 0
r_cnt = 0
total = 0
for i in range(len(pq_rev)):
  if pq_rev[pq_cnt] > r_rev[r_cnt]:
    total += pq_rev[pq_cnt]
    pq_cnt += 1
  else:
    total += r_rev[r_cnt]
    r_cnt += 1
print(total)

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

p_rev = sorted(p, reverse=True)
q_rev = sorted(q, reverse=True)
r_rev = sorted(r, reverse=True)
#print(p_rev[:x])
#print(q_rev[:y])
pq_rev = sorted(p_rev[:x] + q_rev[:y] , reverse=True)

num_r = len(r_rev)
start = len(pq_rev) - num_r
total = sum(pq_rev[:(-1)*num_r])
#print(total)
pq_cnt=0
r_cnt = 0
for i in range(num_r):
  if pq_rev[start + pq_cnt] > r_rev[r_cnt]:
    total += pq_rev[start + pq_cnt]
    pq_cnt += 1
  else:
    total += r_rev[r_cnt]
    r_cnt += 1
print(total)