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:
def merge(A,B):
    C = []
    i = 0
    j = 0
    while i < len(A) and j < len(B):
        if A[i]>B[j]:
            C.append(A[i])
            i += 1
        else:
            C.append(B[j])
            j += 1

    if len(A)>len(B):
        C.extend(A[i:])
    else:
        C.extend(B[j:])

    return C

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 = merge(P[:X],Q[:Y])
S = merge(S,R)

score = 0
for i in range(X+Y):
    score += S[i]
print(score)

Submission status: Runtime Error

Solution code:
x,y,a,b,c = map(int,input().split())
p_a = list(map(int,input().split()))
p_b = list(map(int,input().split()))
p_c = list(map(int,input().split()))
p_a.sort(reverse=True)
p_b.sort(reverse=True)
p_c.sort(reverse=True)
p_c += [0]

ans = p_a[:x] + p_b[:y]
ans.sort(reverse=True)
i = -1
p_c_sum = 0
while True:
    if ans[i] > p_c[0]:
        break
    else:
        ans[i] = 0
        i -= 1
        p_c_sum += p_c[0]
        p_c.pop(0)
print(sum(ans) + p_c_sum )

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())))[::-1]
if c<x+y:
  r+=[0]*(x+y-c)
i=0
j=0
ans=0
for k in range(x+y):
  if r[k]>p[i] and i<x and p[i]<=q[j]:
    ans+=r[k]
    i+=1
  elif r[k]>q[j] and j<y:
    ans+=r[k]
    j+=1
  else:
    break
if i==x:
  p1=0
else:
  p1=sum(p[i:])
if j==y:
  q1=0
else:
  q1=sum(q[j:])
print(ans+p1+q1)

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())))[::-1]
if c<x+y:
  r+=[0]*(x+y-c)
i=0
j=0
ans=0
for k in range(x+y):
  if r[k]>p[i] and i<x and p[i]<=q[j]:
    ans+=r[k]
    i+=1
  elif r[k]>q[j] and j<y:
    ans+=r[k]
    j+=1
  else:
    break
print(ans+sum(p[i:])+sum(q[j:]))

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())))[::-1]
if c<x+y:
  r+=[0]*(x+y-c)
i=0
j=0
ans=0
for k in range(x+y):
  if r[k]>p[i] and i<x:
    ans+=r[k]
    i+=1
  elif r[k]>q[j] and j<y:
    ans+=r[k]
    j+=1
  else:
    break
print(ans+sum(p[i:])+sum(q[j:]))

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)
ls = []
for i in range(X):
    ls.append(p[i])
for i in range(Y):
    ls.append(q[i])
while(r != []):
    for i in range(len(r)):
        minimum = min(ls)
        if r[i] > minimum:
            ls[ls.index(minimum)] = r[i]
        r.pop(0)
print(sum(ls))

Submission status: Runtime Error

Solution code:
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split())).sort(reverse = True)
q= list(map(int, input().split())).sort(reverse = True)
r= list(map(int, input().split())).sort(reverse = True)
ls = []
for i in range(X):
    ls.append(p[i])
for i in range(Y):
    ls.append(q[i])
    
while(r != []):
    for i in range(len(r)):
        minimum = min(ls)
        if r[i] >= min(ls):
            ls[ls.index(minimum)] = r[i]
        r.pop(0)
print(sum(ls))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
# int(input()) # 入力が1つ
x, y, a, b, c = map(int, input().split()) # 入力が複数

reds = sorted([int(i) for i in input().split()], reverse=True)
greens = sorted([int(i) for i in input().split()], reverse=True)
whites = sorted([int(i) for i in input().split()], reverse=True)

reds = reds[:x] + [-float('inf')]
greens = greens[:y] + [-float('inf')]
whites.append(-float('inf'))

ans = 0
num = 0
r = g = w = 0
while num != x + y:
    red = reds[r]
    green = greens[g]
    white = whites[w]
    if red > green and red > white:
        r += 1
        ans += red
    elif green > red and green > white:
        g += 1
        ans += green
    else:
        w += 1
        ans += white
    num += 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()
q.sort()
r.sort()
p = p[::-1]
p = p[:x]
q = q[::-1]
q = q[:y]
r = r[::-1]
ans = p + q + r
ans.sort()
print(sum(ans[: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.sort()
q.sort()
r.sort()
p = p[::-1]
p = [:x]
q = [::-1]
q = [:y]
ans = p + q + r
ans.sort()
print(sum(ans[: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.sort()
q.sort()
r.sort()
p = p[::-1]
p = [:x]
q = [::-1]
q = [:y]
ans = p + q + r
ans.sort()
print(sum(ans[:x+y]))

Submission status: Runtime Error

Solution code:
from collections import deque
X, Y, A, B, C = map(int, input().split())
P = deque(sorted(list(map(int, input().split())), reverse=True))
Q = deque(sorted(list(map(int, input().split())), reverse=True))
R = deque(sorted(list(map(int, input().split())), reverse=True))
ans = 0
p_cnt = 0
while p_cnt < X:
  if P[0] < R[0]:
    r = R.popleft()
  else:
    r = P.popleft()
  ans += r
  p_cnt += 1
q_cnt = 0
while q_cnt < Y:
  if Q[0] < R[0]:
    g = R.popleft()
  else:
    g = Q.popleft()
  ans += g
  q_cnt += 1
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)
p += [0] * 1000
q += [0] * 1000
r += [0] * 1000
ans = 0
while X or Y:
    print(X, Y)
    a = r[0]
    if X:
        a = max(a, p[0])
    if Y:
        a = max(a, q[0])
    if X and a == p[0]:
        X -= 1
        p.pop(0)
    elif Y and a == q[0]:
        Y -= 1
        q.pop(0)
    else:
        if Y and p[0] > q[0]:
            Y -= 1
        else:
            X -= 1
        r.pop(0)
    ans += a

print(ans)

Submission status: Runtime Error

Solution code:
X, Y, A, B, C = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a = sorted(a, reverse=True)
b = sorted(b, reverse=True)
c = sorted(c, reverse=True)
#a2 = a[:]
#b2 = b[:]
#c2 = c[:]
sum1 = 0
for i in range(X):
    if a[0] < c[0]:
        sum1 += c.pop(0)
    else:
        sum1 += a.pop(0)
for i in range(Y):
    if b[0] < c[0]:
        sum1 += c.pop(0)
    else:
        sum1 += b.pop(0)
"""
sum2 = 0
for i in range(Y):
    if b2[0] < c2[0]:
        sum2 += c2.pop(0)
    else:
        sum2 += b2.pop(0)
for i in range(X):
    if a2[0] < c2[0]:
        sum2 += c2.pop(0)
    else:
        sum2 += a2.pop(0)
"""
print(sum1)

Submission status: Runtime Error

Solution code:
X, Y, A, B, C = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a = sorted(a, reverse=True)
b = sorted(b, reverse=True)
c = sorted(c, reverse=True)
a2 = a[:]
b2 = b[:]
c2 = c[:]
sum1 = 0
for i in range(X):
    if a[0] < c[0]:
        sum1 += c.pop(0)
    else:
        sum1 += a.pop(0)
for i in range(Y):
    if b[0] < c[0]:
        sum1 += c.pop(0)
    else:
        sum1 += b.pop(0)
sum2 = 0
for i in range(Y):
    if b2[0] < c2[0]:
        sum2 += c2.pop(0)
    else:
        sum2 += b2.pop(0)
for i in range(X):
    if a2[0] < c2[0]:
        sum2 += c2.pop(0)
    else:
        sum2 += a2.pop(0)        
if sum1 > sum2:
    print(sum1)
else:
    print(sum2)

Submission status: Runtime Error

Solution code:
X, Y, A, B, C = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a = sorted(a, reverse=True)
b = sorted(b, reverse=True)
c = sorted(c, reverse=True)
a2 = a[:]
b2 = b[:]
c2 = c[:]
sum1 = 0
for i in range(X):
    if a[0] < c[0]:
        sum1 += c.pop(0)
    else:
        sum1 += a.pop(0)
for i in range(Y):
    if b[0] < c[0]:
        sum1 += c.pop(0)
    else:
        sum1 += b.pop(0)
sum2 = 0
for i in range(Y):
    if b2[0] < c2[0]:
        sum2 += c2.pop(0)
    else:
        sum2 += b2.pop(0)
for i in range(X):
    if a2[0] < c2[0]:
        sum2 += c2.pop(0)
    else:
        sum2 += a2.pop(0)
        
if sum1 > sum2:
    print(sum1)
else:
    print(sum2)

Submission status: Runtime Error

Solution code:
X, Y, A, B, C = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a = sorted(a, reverse=True)
b = sorted(b, reverse=True)
c = sorted(c, reverse=True)
a2 = a[:]
b2 = b[:]
c2 = c[:]
sum1 = 0
for i in range(X):
    if a[0] < c[0]:
        sum1 += c.pop(0)
    else:
        sum1 += a.pop(0)
for i in range(Y):
    if b[0] < c[0]:
        sum1 += c.pop(0)
    else:
        sum1 += b.pop(0)
sum2 = 0
for i in range(X):
    if b2[0] < c2[0]:
        sum2 += c2.pop(0)
    else:
        sum2 += b2.pop(0)
if sum1 > sum2:
    print(sum1)
else:
    print(sum2)

Submission status: Runtime Error

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

eat = []
for i in range(X):
  p_max = max(p_list)
  r_max = max(r_list)
  if p_max >= r_max or len(r_list) == 0:
    eat.append(p_max)
    p_list.remove(p_max)
  else:
    eat.append(r_max)
    r_list.remove(r_max)
for i in range(Y):
  q_max = max(q_list)
  r_max = max(r_list)
  if q_max >= r_max or len(r_list) == 0:
    eat.append(q_max)
    q_list.remove(q_max)
  else:
    eat.append(r_max)
    r_list.remove(r_max)
print(sum(eat))

Submission status: Runtime Error

Solution code:
X, Y, A, B, C = map(int, input().split())
 
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)
 
for i in r:
    p_min = p[X - 1]
    q_min = q[Y - 1]
 
    if p_min > i and q_min > i:
        break
 
    p_min_diff = i - p_min
    q_min_diff = i - q_min
 
    if p_min_diff >= q_min_diff and p_min_diff > 0:
        p.pop()
        p.insert(0, i)
    elif q_min_diff >= p_min_diff and q_min_diff > 0:
        q.pop()
        q.insert(0, i)
 
print(sum(p) + sum(q) + sum(colored))

Submission status: Runtime Error

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

colored = []
 
for i in r:
    p_min = p[len(p) - 1]
    q_min = q[len(q) - 1]
 
    if p_min > i and q_min > i:
        break
 
    p_min_diff = i - p_min
    q_min_diff = i - q_min
 
    if p_min_diff >= q_min_diff and p_min_diff > 0:
        p.pop()
        colored.append(i)
    elif q_min_diff >= p_min_diff and q_min_diff > 0:
        q.pop()
        colored.append(i)
 
print(sum(p) + sum(q) + sum(colored))

Submission status: Runtime Error

Solution code:
import heapq
n = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

a=0
m=0
s=0
ans = 0
A = heapq.nlargest(n[0] , A)
B = heapq.nlargest(n[1] , B)
if len(C)==1:
    C = C
else:
    C = heapq.nlargest(n[0]+n[1] , C)
for i in range(0,n[0]+n[1]):
    if a==n[0] and m<n[1]:
        saidai = max([ B[m],C[s] ])

        if C[s] >= B[m]:
            s +=1
        else:
            m +=1
    elif a<n[0] and m == n[1]:
        saidai = max([ A[a],C[s] ])

        if C[s] >= A[a]:
            s +=1
        else:
            a +=1

    else:
        saidai=max([ A[a],B[m],C[s] ])

        if A[a] >= B[m] and A[a] > C[s]:
            a +=1
        elif A[a] < B[m] and B[m] > C[s]:
            m +=1
        elif C[s] >= B[m] and A[a] <= C[s]:
            s +=1
    
    ans = ans + saidai

print(ans)

Submission status: Runtime Error

Solution code:
import heapq
n = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

a=0
m=0
s=0
ans = 0
A = heapq.nlargest(n[0]+1 , A)
B = heapq.nlargest(n[1]+1 , B)
if len(C)==1:
    C = C
else:
    C = heapq.nlargest(n[0]+n[1]+1 , C)
for i in range(0,n[0]+n[1]):
    if a==n[0] and m<n[1]:
        saidai = max([ B[m],C[s] ])

        if C[s] >= B[m]:
            s +=1
        else:
            m +=1
    elif a<n[0] and m == n[1]:
        saidai = max([ A[a],C[s] ])

        if C[s] >= A[a]:
            s +=1
        else:
            a +=1

    else:
        saidai=max([ A[a],B[m],C[s] ])

        if A[a] >= B[m] and A[a] > C[s]:
            a +=1
        elif A[a] < B[m] and B[m] > C[s]:
            m +=1
        elif C[s] >= B[m] and A[a] <= C[s]:
            s +=1
    
    ans = ans + saidai

print(ans)

Submission status: Runtime Error

Solution code:
import heapq
n = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

a=0
m=0
s=0
ans = 0
A = heapq.nlargest(n[0]+1 , A)
B = heapq.nlargest(n[1]+1 , B)
C = heapq.nlargest(n[0]+n[1]+1 , C)
for i in range(0,n[0]+n[1]):
    if a==n[0] and m<n[1]:
        saidai = max([ B[m],C[s] ])

        if C[s] >= B[m]:
            s +=1
        else:
            m +=1
    elif a<n[0] and m == n[1]:
        saidai = max([ A[a],C[s] ])

        if C[s] >= A[a]:
            s +=1
        else:
            a +=1

    else:
        saidai=max([ A[a],B[m],C[s] ])

        if A[a] >= B[m] and A[a] > C[s]:
            a +=1
        elif A[a] < B[m] and B[m] > C[s]:
            m +=1
        elif C[s] >= B[m] and A[a] <= C[s]:
            s +=1
    
    ans = ans + saidai

print(ans)

Submission status: Runtime Error

Solution code:
import heapq
n = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

a=0
m=0
s=0
ans = 0
A = heapq.nlargest(n[0] , A)
B = heapq.nlargest(n[1] , B)
C = heapq.nlargest(n[0]+n[1] , C)
for i in range(0,n[0]+n[1]):
    if a==n[0] and m<n[1]:
        saidai = max([ B[m],C[s] ])

        if C[s] >= B[m]:
            s +=1
        else:
            m +=1
    elif a<n[0] and m == n[1]:
        saidai = max([ A[a],C[s] ])

        if C[s] >= A[a]:
            s +=1
        else:
            a +=1

    else:
        saidai=max([ A[a],B[m],C[s] ])

        if A[a] > B[m] and A[a] > C[s]:
            a +=1
        elif A[a] < B[m] and B[m] > C[s]:
            m +=1
        elif C[s] >= B[m] and A[a] <= C[s]:
            s +=1
    
    ans = ans + saidai

print(ans)

Submission status: Runtime Error

Solution code:
lst = input().split()
X = int(lst[0])
Y = int(lst[1])
A = int(lst[2])
B = int(lst[3])
C = int(lst[4])

p_list = [int(num) for num in input().split(" ")]
q_list = [int(num) for num in input().split(" ")]
r_list = [int(num) for num in input().split(" ")]

sort_p = sorted(p_list,reverse = True)[:X]
sort_q = sorted(q_list,reverse = True)[:Y]
sort_r = sorted(r_list,reverse = True)[:X+Y]

max_score = 0

for i in range(X+Y):
    if len(sort_p) ==0:
        if sort_q[0] >= sort_r[0]:
            max_score += sort_q[0]
            sort_q = sort_q[1:]
        else:
            max_score += sort_r[0]
            sort_r = sort_r[1:]
            sort_q.pop()
    elif len(sort_q) ==0:
        if sort_p[0] >= sort_r[0]:
            max_score += sort_p[0]
            sort_p = sort_p[1:]
        else:
            max_score += sort_r[0]
            sort_r = sort_r[1:]
            sort_p.pop()

    else:
        if sort_p[0] >= sort_q[0] and sort_p[0] >= sort_r[0]:
            max_score += sort_p[0]
            sort_p = sort_p[1:]
        elif sort_p[0] >= sort_r[0]:
            max_score += sort_q[0]
            sort_q = sort_q[1:]
        else:
            max_score += sort_r[0]
            sort_r = sort_r[1:]
            if sort_p[-1] < sort_q[-1]:
                sort_p.pop()
            else :
                sort_q.pop()
print(max_score)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
x, y, a, b, c = map(int, input().split())
P = [0]*x + [int(p) for p in input().split()]
Q = [0]*y + [int(q) for q in input().split()]
R = [int(r) for r in input().split()]

P.sort()
Q.sort()
R.sort(reverse=True)
Px = P[a:]
Qy = Q[b:]
R = R[:x+y]
pc, qc = 0, 0
pqpq = [Px, Qy]
pqc = [pc, qc]
for r in R:
    if Px[pqc[0]]<Qy[pqc[1]]:
        pq = 0
    else:
        pq = 1
    if pqpq[pq][pqc[pq]] < r:
        pqpq[pq][pqc[pq]] = r
        pqc[pq]+= 1
    else:
        break

print(sum(Px)+sum(Qy))

Submission status: Runtime Error

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

R.sort()
G.sort()
N.sort(reverse=True)
R2 = R[-X:]
G2 = G[-Y:]

W = sorted(R2 + G2)

for i in range(C):
	if W[i] < N[i]:
		W[i] = N[i]

print(sum(W))

Submission status: Runtime Error

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

#R = [0]*(10**6)
#G = [0]*(10**6)
#N = [0]*(10**6)

R = [0]*(6)
G = [0]*(6)
N = [0]*(6)
ans = []

R = list(map(int, input().split()))
G = list(map(int, input().split()))
N = list(map(int, input().split()))

R.sort()
G.sort()
N.sort(reverse=True)

#Rs = sorted(R)
#Gs = sorted(G)
#Ns = sorted(N)

R2 = R[-X:]
G2 = G[-Y:]

W = sorted(R2 + G2)

for i in range(C):
	if W[i] < N[i]:
		W[i] = N[i]



#print(R,G,N)
#print(Rs,Gs,Ns)
#print(R2,G2)
#print(W)

print(sum(W))

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)
p = p[0:x]
q = q[0:y]

indexp = len(p) - 1
indexq = len(q) - 1
#print(indexp)
#print(indexq)

for i in range(c):
  if min([p[indexp],q[indexq]]) <= r[i]:
    if p[indexp] <= q[indexq]:
      p[indexp] = r[i]
      indexp -= 1
    else:
      q[indexq] = r[i]
      indexq -= 1
  else:
    break

#print(p)
#print(q)
#print(r)
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()))

red = sorted(p, reverse=True)[:X]
green = sorted(q, reverse=True)[:Y]
white = sorted(r, reverse=True)

original = sorted(red + green)
while original[0] < white[0]:
  original[0] = white[0]
  white.pop(0)
  original.sort()
  
print(sum(original))

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

red = sorted(p, reverse=True)[:X-1]
green = sorted(q, reverse=True)[:Y-1]
white = sorted(r, reverse=True)

original = sorted(red + green)
while original[0] < white[0]:
  original[0] = white[0]
  white.pop(0)
  original.sort()
  
print(sum(original))

Submission status: Runtime Error

Solution code:
import bisect
 
x, y, a, b, c = map(int, input().split())
p = [int(_) for _ in input().split()]
q = [int(_) for _ in input().split()]
r = [int(_) for _ in input().split()]
 
p.sort()
q.sort()
r.sort()

x_list = p[-x:]
y_list = q[-y:]
r_list = r[-(x+y):]
 
while (min(x_list[0], y_list[0]) < r_list[-1]):
    if x_list[0] > y_list[0]:
        i = bisect.bisect_right(r, y_list[0])
        y_list.pop(0)
        target = r_list.pop(i)
        bisect.insort(y_list, target)
    else:
        i = bisect.bisect_right(r_list, x_list[0])
        x_list.pop(0)
        target = r_list.pop(i)
        bisect.insort(x_list, target)
 
    if len(r_list) == 0:
        break
 
print(sum(x_list) + sum(y_list))

Submission status: Runtime Error

Solution code:
[X,Y,A,B,C] = [int(x) for x in input().split()]
R_list = [int(x) for x in input().split()]
G_list = [int(x) for x in input().split()]
T_list = [int(x) for x in input().split()]
R_list.sort()
G_list.sort()
T_list.sort()
total = 0
ans = 0
r = 0
g = 0
for i in range(X+Y):
    if r == X:
        R_list = [-1]
    if g == Y:
        G_list = [-1]
    if max(R_list[-1],G_list[-1],T_list[-1]) == R_list[-1]:
        ans += R_list.pop(-1)
        r += 1
    elif max(R_list[-1],G_list[-1],T_list[-1]) == G_list[-1]:
        ans += G_list.pop(-1)
        g += 1
    elif max(R_list[-1],G_list[-1],T_list[-1]) == T_list[-1]:
        ans += T_list.pop(-1)
print(ans)

Submission status: Runtime Error

Solution code:
X,Y,A,B,C = map(int,input().split())
R = list(map(int,input().split()))
G = list(map(int,input().split()))
T = list(map(int,input().split()))
R.sort(reverse=True)
G.sort(reverse=True)
T.sort(reverse=True)
"""
print("X,Y:",X,Y)
print(R)
print(G)
print(T)
"""
R.append(0)
G.append(0)
T.append(0)

d=0
t=0
# TT = []
while X+Y-t > 0:
    # print("X+Y-t :",X+Y-t)

    if max(R[0],G[0],T[0])==R[0]:
        if X>0:
            d += R.pop(0)
            X += -1
        else:
            if G[0] >= T[0]:
                d += G.pop(0)
                Y += -1
            else:
                TT.append(T.pop(0))
                t += 1
            
    elif max(R[0],G[0],T[0])==G[0]:
        if Y>0:
            d += G.pop(0)
            Y += -1
        else:
            if R[0] >= T[0]:
                d += R.pop(0)
                X += -1
            else:
                TT.append(T.pop(0))
                t += 1
                
    else:
        d += T.pop(0)
        t += 1
    
print(d)

Submission status: Runtime Error

Solution code:
X,Y,A,B,C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort()
q.sort()
r.sort()
a = 0
while X>0:
    if p==[]:
        p[0] = 0
    if r==[]:
        r[0] = 0
    if p[-1] > r[-1]:
        a += p.pop()
    else:
        a += r.pop()
    X -= 1
while Y>0:
    if q==[]:
        q[0] = 0
    if r==[]:
        r[0] = 0
    if q[-1] > r[-1]:
        a += q.pop()
    else:
        a += r.pop()
    Y -= 1
print(a)

Submission status: Runtime Error

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

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

ans = 0

cnt = 0

while x+y-cnt > 0:
    if x > 0:
        p1 = p[-1]
    else:
        p1 = 0
    if y > 0:
        p2 = q[-1]
    else:
        p2 = 0
    p3 = r[-1]
    eat = max(p1,p2,p3)
    ans += eat
    if x > 0 and p[-1] == eat:
        x -= 1
        p.pop()
    elif y > 0 and q[-1] == eat:
        y -= 1
        q.pop()
    else:
        cnt += 1
        r.pop()
print(ans)

Submission status: Runtime Error

Solution code:
inp=list(map(int,input().strip().split()))[:5]
x,y,a,b,c=inp[0],inp[1],inp[2],inp[3],inp[4]
list1=list(map(int,input().strip().split()))[:a]
list2=list(map(int,input().strip().split()))[:b]
list3=list(map(int,input().strip().split()))[:c]
sum1=0
for i in range(x):
	sum1+=max(max(list1),max(list3))
	if(max(list1) > max(list3)):
		list1.remove(max(list1))
	else:
		list3.remove(max(list3))
for i in range(y):
	sum1+=max(max(list2),max(list3))
	if(max(list2) > max(list3)):
		list2.remove(max(list2))
	else:
		list3.remove(max(list3))
print(sum1)

Submission status: Runtime Error

Solution code:
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

#[allow(dead_code)]
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn input<T: FromStr>(&mut self) -> T {
        self.read().unwrap()
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.input()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let x: i64 = sc.input();
    let y: i64 = sc.input();
    let a: i64 = sc.input();
    let b: i64 = sc.input();
    let c: i64 = sc.input();
    let mut ps: Vec<i64> = sc.vec(a as usize);
    let mut qs: Vec<i64> = sc.vec(b as usize);
    let rs: Vec<i64> = sc.vec(c as usize);

    ps.sort_by_key(|&x| -x);
    qs.sort_by_key(|&x| -x);
    let mut v = [&ps[0..x as usize], &qs[0..y as usize], &rs].concat();
    v.sort_by_key(|&x| -x);

    let ans: i64 = v[..(x + y) as usize].iter().sum();
    println!("{}", ans);
}

Submission status: Runtime Error

Solution code:
n, x, y = input().split()
n, x, y = int(n), int(x)-1, int(y)-1
d = [[abs(i-j) for i in range(n)] for j in range(n)]
for i in range(x+1):
    for j in range(y, n):
        d[i][j] -= y-x-1
    for j in range(y-1, x+(y-x)//2, -1):
        d[i][j] = d[i][j+1]+1
for i in range(x+1, x+(y-x)//2):
    for j in range(y, n):
        d[i][j] -= i-x
    for j in range(y-1, y-(y-x)//4+1, -1):
        d[i][j] = d[i][j+1]+1
apar = [0 for i in range(n)]
for i in range(n-1):
    for j in range(i+1, n):
        apar[d[i][j]] += 1
for i in range(1, n):
    print(apar[i])

Submission status: Runtime Error

Solution code:
import bisect

x, y, a, b, c = map(int, input().split())
p = [int(_) for _ in input().split()]
q = [int(_) for _ in input().split()]
r = [int(_) for _ in input().split()]

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

x_list = p[-x:]
y_list = q[-y:]

while (min(x_list[0], y_list[0]) < r[-1]):
    if x_list[0] > y_list[0]:
        i = bisect.bisect_left(r, y_list[0])
        y_list.pop(0)
        target = r.pop(i)
        bisect.insort(y_list, target)
    else:
        i = bisect.bisect_left(r, x_list[-1])
        x_list.pop(0)
        target = r.pop(i)
        bisect.insort(x_list, target)

    if len(r) == 0:
        break

print(sum(x_list) + sum(y_list))

Submission status: Runtime Error

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

p_list=list(map(int,input().split()))
q_list=list(map(int,input().split()))
r_list=list(map(int,input().split()))

p_list.sort(reverse=True)
q_list.sort(reverse=True)
r_list.sort(reverse=True)

pi=0
qi=0
ri=0
s=0
for i in range(x+y):
    if p_list[pi]>q_list[qi] and p_list[pi] > r_list[ri] and pi+1<=x:
        s+=p_list[pi]
        pi+=1
    elif q_list[qi]>r_list[ri] and qi+1<=y:
        s+=q_list[qi]
        qi+=1
    elif ri+1<=len(r_list):
        s+=r_list[ri]
        ri+=1
    else:
        s+=sum(p_list[pi:x])
        s+=sum(q_list[qi:y])
        break
    
print(s)

Submission status: Runtime Error

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

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

ans = 0
for i in range(x + y - 1):
    ans += p[i]
print(ans)

Submission status: Runtime Error

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

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

ans = 0
for i in range(x + y):
    ans += p[i]
print(ans)

Submission status: Runtime Error

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

p.extend(q)
p.extend(r)
p.sort(reversed = True)

ans = 0
for i in range(x + y):
    ans += p[i]
print(ans)

Submission status: Runtime Error

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

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

p.extend(q)
p.extend(r)
p.sort(reversed = True)

ans = 0
for i in range(x + y):
    ans += p[i]
print(ans)

Submission status: Runtime Error

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

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

del p[a:-1]
del q[b:-1]

p.extend(q)
p.extend(r)
p.sort(reversed = True)

ans = 0
for i in range(x + y):
    ans += p[i]
print(ans)

Submission status: Runtime Error

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

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

del p[a:-1]
del q[b:-1]

p.extend(q)
p.extend(r)
p.sort(reversed = True)

ans = 0
for i in range(x + y):
    ans += p[i]
print(sum(ans))