TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
import heapq

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

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

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

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

heapq.heapify(r)
ans = 0

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

print(ans)


import heapq

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

p.sort(reverse=True)
q.sort(reverse=True)
pq = p[:x]+q[:y]
heapq.heapify(pq)

for e in r :
    heapq.heappushpop(pq, e)

print(sum(pq))


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def merge(A,B):
    C = []
    
    while len(A)!=0 and len(B) != 0:
        if A[0]>B[0]:
            C.append(A[0])
            del A[0]
        else:
            C.append(B[0])
            del B[0]

    if len(A)>len(B):
        C.extend(A)
    else:
        C.extend(B)

    return C

if __name__ == "__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 = [1,23,4,1,2]
    # Q = [4,3,56]
    # R = [70,20,1]

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

    S = merge(P[:X],Q[:Y])
    S = merge(S,R)

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



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)-i>len(B)-j:
        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 = [3,63,12,5,6]
# Q = [3,5,6,7,8]
# R = [13,5,6,8,23,5]
# X = 3
# Y = 2

# P = [63,12,6]
# Q = [8,7]


# j = 2
# C = [63,12,8,7]


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)



Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)
import heapq
eat=p+q
heapq.heapify(eat)
for i in r:
	j=heapq.heappop(eat)
	if j<i:
		heapq.heappush(eat,i)
	else:
		heapq.heappush(eat,j)
print(list(eat))
print(sum(list(eat)))

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)
import heapq
eat=p+q
heapq.heapify(eat)
for i in r:
	j=heapq.heappop(eat)
	if j<i:
		heapq.heappush(eat,i)
	else:
		heapq.heappush(eat,j)
#print(list(eat))
print(sum(list(eat)))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
#!/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()
z = p[-x:].extend(q[-y:]).extend(r)
z.sort()
print(sum(z[-x-y:]))

#!/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()
z = p[-x:].extend(q[-y:]).extend(r)
z.sort()
print(sum(z[-x-y]))

#!/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()
z = p[-x:]
z.extend(q[-y:])
z.extend(r)
z.sort()
#print(z)
print(sum(z[-x-y:]))

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
X,Y,A,B,C = [int(x) for x in input().split()]
R = [int(x) for x in input().split()]
G = [int(x) for x in input().split()]
CL = [int(x) for x in input().split()]

dp = [[0]*(X+1) for d in range(Y+1)]
for i in range(X):
    for j in range(Y):
        MAX = max(max(R[j],CL[j]),max(G[i],CL[i]))
        dp[i][j] = MAX
        if MAX == R[j]:
            A.pop(0)
        elif MAX == G[i]:
            B.pop(0)
        else:
            C.pop(0)

print(dp[-1])

X,Y,A,B,C = [int(x) for x in input().split()]
R = sorted([int(x) for x in input().split()],reverse = True)[:X]
G = sorted([int(x) for x in input().split()],reverse = True)[:Y]
CL = sorted([int(x) for x in input().split()],reverse = True)[:X+Y]
total = sorted(R+G+CL, reverse=True)[:X+Y]
print(sum(total))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
X, Y, A, B, C = map(int, input().split())
p = map(int, input().split())
q = map(int, input().split())
r = map(int, input().split())

# X, Y, A, B, C = 1, 2, 2, 2, 1
# p = [2, 4]

# r = [3]

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

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

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


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

# X, Y, A, B, C = 1, 2, 2, 2, 1
# p = [2, 4]

# r = [3]

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

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

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


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)

result = sum(p[:x]) + sum(q[:y])
i = 0
red_min = x-1
blue_min = y-1
flag = True

while flag == True:
    if r[i] > p[red_min] or r[i] > q[blue_min]:
        if p[red_min] < q[blue_min]:
            result = result - p[red_min] + r[i]
            i += 1
            red_min -= 1
        else:
            result = result - q[blue_min] + r[i]
            i += 1
            blue_min -= 1
    else:
        flag = False
print(result)
    

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.insert(0, 10**9)
p.append(0)
q.insert(0, 10**9)
q.append(0)
r.append(0)

result = sum(p[1:x+1]) + sum(q[1:y+1])
i = 0
red_min = x
blue_min = y
flag = True

while flag == True:
    if r[i] > p[red_min] or r[i] > q[blue_min]:
        if p[red_min] < q[blue_min]:
            result = result - p[red_min] + r[i]
            i += 1
            red_min -= 1
        else:
            result = result - q[blue_min] + r[i]
            i += 1
            blue_min -= 1
    else:
        flag = False
print(result)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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, Q = sorted(P, reverse=True), sorted(Q, reverse=True)
P, Q = P[:A], Q[:B]
ans = sum(sorted(P + Q + R, reverse=True)[:A + B])
print(ans)

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, Q = sorted(P, reverse=True), sorted(Q, reverse=True)
P, Q = P[:X], Q[:Y]
ans = sum(sorted(P + Q + R, reverse=True)[:X + Y])
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

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

A_p = p[:X]
B_q = q[:Y]
C_r = r

ans = A_p + B_q + C_r
ans.sort(reverse=True)
sum(ans[: X+Y])

X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
 
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
 
A_p = p[:X]
B_q = q[:Y]
C_r = r
 
ans = A_p + B_q + C_r
ans.sort(reverse=True)
print(sum(ans[: X+Y]))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import heapq
from collections import deque

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

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

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

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

print(sum(pq))

import heapq
from collections import deque

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

r.sort()

if A < X:
  p += r[C - (X - A):]
  r = r[:C - (X - A)]
  A = X

if B < Y:
  q += r[C - (Y - B):]
  r = r[:C - (Y - B)]
  B = Y

p.sort()
q.sort()

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

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

print(sum(pq))

import heapq
from collections import deque

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

r.sort()

if A < X:
  p += r[-(X - A):]
  r = r[:-(X - A)]
  A = X

if B < Y:
  q += r[-(Y - B):]
  r = r[:-(Y - B)]
  B = Y

p.sort()
q.sort()

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

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

print(sum(pq))

import heapq
from collections import deque

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

r.sort()

if A < X:
  p += r[-(X - A):]
  r = r[:-(X - A)]
  A = X

if B < Y:
  q += r[-(Y - B):]
  r = r[:-(Y - B)]
  B = Y

p.sort()
q.sort()

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

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

print(sum(pq))


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
x, y, a, b, c = map(int, input().split())
red = [int(x) for x in input().split()]
green = [int(x) for x in input().split()]
red.sort(reverse=True)
green.sort(reverse=True)
candidates = [int(x) for x in input().split()] + red[x:] + green[:y]
candidates.sort(reverse=True)
print(sum(candidates[:x+y]))

x, y, a, b, c = map(int, input().split())
print(sum(sorted(
    sorted(int(x) for x in input().split())[-x:] +
    sorted(int(x) for x in input().split())[-y:] +
    [int(x) for x in input().split()])[-(x+y):]))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
X,Y,A,B,C = map(int,readline().split())
P = list(map(int,readline().split()))
Q = list(map(int,readline().split()))
R = list(map(int,readline().split()))
P = sorted(P,reverse=True)
Q = sorted(Q,reverse=True)
R = sorted(R,reverse=True)
P = P[:X]
Q = Q[:Y]
PQ = sorted(P+Q,reverse = True)
XY = X+Y
total = sum(PQ)
for i in range(C):
    if R[i] < PQ[-(i+1)]:
      if i ==0:
        ans = total
      else:
        ans = total + sum(R[:i]) - sum(PQ[-i:])
      break
    if i == max(C-1,XY-1):
      ans = total + sum(R[:i+1]) - sum(PQ[-(i+1):])
print(ans)

import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
X,Y,A,B,C = map(int,readline().split())
P = list(map(int,readline().split()))
Q = list(map(int,readline().split()))
R = list(map(int,readline().split()))
P = sorted(P,reverse=True)
Q = sorted(Q,reverse=True)
R = sorted(R,reverse=True)
P = P[:X]
Q = Q[:Y]
PQR = sorted(P+Q+R,reverse = True)
ans = sum(PQR[:X+Y])
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)
p2=p[:x]
q2=q[:y]
memop=x-1
memoq=y-1
sp=sum(p2)
sq=sum(q2)
k=0
flagp=0
flagq=0
while k<c:
    if memop<0:
        flagp=1
    if memoq<0:
        flagq=1
    if flagp*flagq==1:
        print(sp+sq)
        exit()
    elif flagq==1:
        if p2[memop]>=r[k]:
            print(sp+sq)
            exit()
        else:
            sp-=p2[memop]
            sp+=r[k]
            k+=1
            memop-=1
    elif flagp==1:
        if q2[memoq]>=r[k]:
            print(sp+sq)
            exit()
        else:
            sq-=q2[memoq]
            sq+=r[k]
            k+=1
            memoq-=1
    elif p2[memop]>=r[k] and q2[memoq]>=r[k] and flagp+flagq==0:
        print(sp+sq)
        exit()
    elif p2[memop]>q2[memoq]:
        sq-=q2[memoq]
        sq+=r[k]
        k+=1
        memoq-=1
    elif p2[memop]<=q2[memoq]:
        sp-=p2[memop]
        sp+=r[k]
        k+=1
        memop-=1


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)
p2=p[:x]
q2=q[:y]
memop=x-1
memoq=y-1
sp=sum(p2)
sq=sum(q2)
k=0
flagp=0
flagq=0
while k<c:
    if memop<0:
        flagp=1
    if memoq<0:
        flagq=1
    if flagp*flagq==1:
        print(sp+sq)
        exit()
    elif flagq==1:
        if p2[memop]>=r[k]:
            print(sp+sq)
            exit()
        else:
            sp-=p2[memop]
            sp+=r[k]
            k+=1
            memop-=1
    elif flagp==1:
        if q2[memoq]>=r[k]:
            print(sp+sq)
            exit()
        else:
            sq-=q2[memoq]
            sq+=r[k]
            k+=1
            memoq-=1
    elif p2[memop]>=r[k] and q2[memoq]>=r[k] and flagp+flagq==0:
        print(sp+sq)
        exit()
    elif p2[memop]>q2[memoq]:
        sq-=q2[memoq]
        sq+=r[k]
        k+=1
        memoq-=1
    elif p2[memop]<=q2[memoq]:
        sp-=p2[memop]
        sp+=r[k]
        k+=1
        memop-=1
print(sp+sq)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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, reverse=True)
q = sorted(q, reverse=True)

pq = sorted(p[:x] + q[:y])
r = sorted(r)
ans=0
j = r.pop()
for i in pq:
  if i < j:
    ans+=j
    j = 0
    if r:
      j = r.pop()
    else: break
  else:
    ans += i
    
print(ans)

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

pq = sorted(p[:x] + q[:y])
r = sorted(r)
ans=0
j = r.pop()
for i in pq:
  if i < j:
    ans += j
    j = 0
    if r:
      j = r.pop()
  else:
    ans += i
    
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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()))

l = p[:x] + q[:y] + r
l.sort(reverse=True)

print(sum(l[:x+y]))

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)

l = p[:x] + q[:y] + r
l.sort(reverse=True)

print(sum(l[:x+y]))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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_ind = X-1
q_ind = Y-1
r_ind = 0

while 1:

    print(p_ind, q_ind, r_ind)
    if p_ind == -1 and q_ind == -1:
        break

    if q_ind == -1 or p[p_ind] < q[q_ind]:
        worst = p[p_ind]
        apple = "p"
    else:
        worst = q[q_ind]
        apple = "q"
    
    if worst <= r[r_ind]:
        r_ind += 1
        if apple == "p":
            p_ind -= 1
        else:
            q_ind -= 1
            
        if r_ind == C:
            break
    else:
        break

eat_p = p[:p_ind+1]
eat_q = q[:q_ind+1]
eat_r = r[:r_ind]

if p_ind == -1:
    eat_p = []
if q_ind == -1:
    eat_q = []

print(sum(eat_p) + sum(eat_q) + sum(eat_r))

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_ind = X-1
q_ind = Y-1
r_ind = 0

while 1:

    if p_ind == -1 and q_ind == -1:
        break

    if q_ind == -1 or p[p_ind] < q[q_ind]:
        worst = p[p_ind]
        apple = "p"
    else:
        worst = q[q_ind]
        apple = "q"
    
    if worst <= r[r_ind]:
        r_ind += 1
        if apple == "p":
            p_ind -= 1
        else:
            q_ind -= 1
            
        if r_ind == C:
            break
    else:
        break

eat_p = p[:p_ind+1]
eat_q = q[:q_ind+1]
eat_r = r[:r_ind]

if p_ind == -1:
    eat_p = []
if q_ind == -1:
    eat_q = []


print(sum(eat_p) + sum(eat_q) + sum(eat_r))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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,reverse=True)
q=sorted(q,reverse=True)
r=sorted(r,reverse=True)
answer=p[:X]+q[:Y]
sum=0
answer=sorted(answer,reverse=True)
i=0

while answer[-i-1]<r[i]:
    answer[-i-1]=r[i]
    i+=1

for a in answer:
    sum+=a

print(sum)

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,reverse=True)
q=sorted(q,reverse=True)
r=sorted(r,reverse=True)
answer=p[:X]+q[:Y]
sum=0
answer=sorted(answer)
i=0

while i<=min(X+Y-1,C-1) and answer[i]<r[i]:
    answer[i]=r[i]
    i+=1

for a in answer:
    sum+=a

print(sum)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
s = []
r.extend( [0 for i in range(x+y)])
p.sort()
q.sort()
r.sort()


for i in range(x):
    if  p[-1]>= r[-1]:
        s.append(p.pop())
    else:
        s.append(r.pop())
    
for i in range(y):
    if  q[-1]>= r[-1]:
        s.append(q.pop())
    else:
        s.append(r.pop())
        
print(sum(s))

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

s = []
p.sort(reverse=True)
p = p[:x]

q.sort(reverse=True)
q = q[:y]

s = p + q + r
s.sort(reverse=True)
s = s[:x+y]
print(sum(s))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

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

l = p[:x] + q[:y]
l.sort()

i = 0
while l[i] < r[i] and i < len(l) and i < len(r):
    l[i] = r[i]
    i += 1

print(sum(l))

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

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

l = p[:x] + q[:y]
l.sort()

i = 0
while i < len(l) and i < len(r):
  if l[i] < r[i]:
    l[i] = r[i]
    i += 1
  else:
    break

print(sum(l))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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):]))


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):]))


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


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
X,Y,A,B,C = map(int,input().split())

p = sorted(list(map(int,input().split()))) #A
q = sorted(list(map(int,input().split()))) #B
r = sorted(list(map(int,input().split()))) #C

xlist = p[-X:] #X
ylist = q[-Y:] #Y


for i in range(min(X,Y)):
    if xlist[i] < ylist[i] and min(xlist) < max(r):
        xlist.remove(min(xlist))
        xlist.append(max(r))
        r.pop()
    elif ylist[i] < xlist[i] and min(ylist) < max(r):
        ylist.remove(min(xlist))
        ylist.append(max(r))
        r.pop()
    else:
        continue

print(sum(xlist)+sum(ylist))

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

p = sorted(list(map(int,input().split()))) #A
q = sorted(list(map(int,input().split()))) #B
r = sorted(list(map(int,input().split()))) #C

xlist = p[-X:] #X
ylist = q[-Y:] #Y

"""
def main(X,Y,xlist,ylist,r):
    for i in range(min(X,Y)):
        if xlist[i] < ylist[i] and min(xlist) < max(r):
            xlist.remove(min(xlist))
            xlist.append(r.pop())
            
        elif ylist[i] < xlist[i] and min(ylist) < max(r):
            ylist.remove(min(ylist))
            ylist.append(r.pop())
            
        elif min(xlist) >= max(r) and min(ylist) >= max(r):
            break
        else:
            continue
    
    print(sum(xlist + ylist))

main(X,Y,xlist,ylist,r)
"""
all_apples = sorted(xlist + ylist + r)
print(sum(all_apples[-(X+Y):]))







Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
X,Y,A,B,C=map(int,input().split())
red=sorted(list(map(int,input().split())),reverse=True)
green=sorted(list(map(int,input().split())),reverse=True)
nocolor=sorted(list(map(int,input().split())),reverse=True)

X_cnt=0
Y_cnt=0
ans=[]

for i in range(X):
    ans.append(red[i])
    X_cnt+=1
    if X_cnt==X:
        break
    elif X_cnt<X:
        continue
for i in range(Y):
    ans.append(green[i])
    Y_cnt+=1
    if Y_cnt==Y:
        break
    elif Y_cnt<Y:
        continue

ans=sorted(ans)
ans_sum=sum(ans)    
for i in range(C):
    if ans[i]<nocolor[i]:
        ans_sum=ans_sum_nocolor[i]-ans[i]
        
print(ans_sum)



X,Y,A,B,C=map(int,input().split())
R=sorted(list(map(int,input().split())),reverse=True)
G=sorted(list(map(int,input().split())),reverse=True)
RG=sorted(list(map(int,input().split())),reverse=True)


d=R[:X]+G[:Y]+RG
d.sort(reverse=True)
 
print(sum(d[:X+Y]))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import heapq as hp
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()))

lp = hp.nlargest(x, p)
lq = hp.nlargest(y, q)
pq = lp + lq
lpq = hp.nlargest(x+y, pq)
lr = hp.nlargest(c, r)
d = min(len(lr),len(lpq))
for i in range(1,d):
  if lpq[x+y-i] < lr[i-1]:
    lpq[x+y-i] = lr[i-1]
  else:
    break

ans = 0
for i in range(0,len(lpq)):
  ans += lpq[i]
print(ans)

import heapq as hp
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()))

lp = hp.nlargest(x, p)
lq = hp.nlargest(y, q)
pq = lp + lq
lpq = hp.nlargest(x+y, pq)
lr = hp.nlargest(c, r)
d = min(len(lr),len(lpq))
for i in range(1,d+1):
  if lpq[x+y-i] < lr[i-1]:
    lpq[x+y-i] = lr[i-1]
  else:
    break

ans = 0
for i in range(0,len(lpq)):
  ans += lpq[i]
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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()
r = sorted(r,reverse = True)
p = p[A-X:]
q = q[B-Y:]
if X+Y<C:
    r = r[:X+Y+1]
px = 0
qx = 0
for i in range(X+Y):
    if px == len(p) or qx ==len(q):
        break
    if min(p[px],q[qx],r[i]) ==p[px]:
        p[px] = r[i]
        px +=1
    elif min(p[px],q[qx],r[i]) ==q[qx]:
        q[qx] = r[i]
        qx += 1
    else:
        px += 1
        qx += 1
print(sum(p)+sum(q))

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()
r = sorted(r,reverse = True)
p = p[A-X:]
q = q[B-Y:]
if X+Y<C:
    r = r[:X+Y]
px = 0
qx = 0
for i in range(C):
    if px == len(p) and qx == len(q):
        break
    elif px == len(p):
        if min(q[qx],r[i])==q[qx]:
            q[qx] =r[i]
            qx += 1
        else:
            break
    elif qx == len(q):
        if min(p[px],r[i])==p[px]:
            p[px] =r[i]
            px += 1
        else:
            break
    else:
        if min(p[px],q[qx],r[i]) ==p[px]:
            p[px] = r[i]
            px +=1
        elif min(p[px],q[qx],r[i]) ==q[qx]:
            q[qx] = r[i]
            qx += 1
        else:
            break
print(sum(p)+sum(q))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
x,y,a,b,c = map(int, input().split())
li_p = list(map(int, input().split()))
li_q = list(map(int, input().split()))
li_r = list(map(int, input().split()))
li_p.sort(reverse=True)
li_q.sort(reverse=True)
li_r.sort(reverse=True)
p,q = [],[]
for i in range(x):
  r.append(li_p[i])
for i in range(y):
  r.append(li_q[i])
for i in range(c):
  r.append(li_r[i])
r.sort(reverse=True)
print(sum(r[:x+y]))

from heapq import heapify, heappush, heappop
x,y,a,b,c = map(int, input().split())
li_p = list(map(int, input().split()))
li_q = list(map(int, input().split()))
li_r = list(map(int, input().split()))
li_p.sort(reverse=True)
li_q.sort(reverse=True)
li_r.sort(reverse=True)
s = 0
for i in range(x):
  s += li_p[i]
for i in range(y):
  s += li_q[i]
li_p.extend(li_q)
li_p.sort(reverse=True)
s_p = [0] * (a+b+1)
s_r = [0] * (c+1)
for i in range(1,a+b):
  s_p[i] = s_p[i-1] + li_p[i]
for i in range(1, c):
  s_r[i] = s_r[i-1] + li_r[i]
delta = -1
zz = -1
for i in range(min(c, a+b)):
  k = s_r[i] - s_p[i]
  if k > delta:
    zz = i
    delta = k
print(s+delta)


x,y,a,b,c = map(int, input().split())
li_p = list(map(int, input().split()))
li_q = list(map(int, input().split()))
li_r = list(map(int, input().split()))
li_p.sort(reverse=True)
li_q.sort(reverse=True)
li_r.sort(reverse=True)
r = []
for i in range(x):
  r.append(li_p[i])
for i in range(y):
  r.append(li_q[i])
for i in range(c):
  r.append(li_r[i])
r.sort(reverse=True)
print(sum(r[:x+y]))


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-

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

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


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

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

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

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

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


# -*- coding: utf-8 -*-

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

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


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

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

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

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


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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(min(len(arrayR), len(arrayAns)):
    if arrayAns[i] <= int(arrayR[i]):
        arrayAns[i] = int(arrayR[i])
    else:
        break
print(sum(arrayAns))


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(min(len(arrayR), len(arrayAns))):
    if arrayAns[i] <= int(arrayR[i]):
        arrayAns[i] = int(arrayR[i])
    else:
        break
print(sum(arrayAns))


Verdicts: Runtime Error

Accepted