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(l):
    t = [-1]*len(l)
    if(len(l) == 2):
        if(l[0]<l[1]):
            t[1] = l[0]
            t[0] = l[1]
        else:
            t=l
    elif(len(l) > 2):
        x = merge(l[:len(l)//2])
        y = merge(l[len(l)//2:])
        p,q = 0,0
        for i in range(len(l)):
            if(p<len(x) and q<len(y)):
                if(x[p] > y[q]):
                    t[i] = x[p]
                    p += 1
                else:
                    t[i] = y[q]
                    q += 1
            elif(p == len(x)):
                t[i] = y[q]
                q += 1
            else:
                t[i] = x[p]
                p += 1
    else:
        t = l
    return t
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()))
a = [x,y,0]
P = merge(p)
Q = merge(q)
R = merge(r)
X = P[:x]
Y = Q[:y]
for i in range(x+y):
    if(a[2] == c):
        break
    elif(a[0] == 0):
        if(Y[a[1]-1] < R[a[2]]):
                a[1] -= 1
                a[2] += 1
            else:
                break
    elif(a[1] == 0):
        if(X[a[0]-1] < R[a[2]]):
                a[0] -= 1
                a[2] += 1
            else:
                break
    else:
        if(X[a[0]-1] > Y[a[1]-1]):
            if(Y[a[1]-1] < R[a[2]]):
                a[1] -= 1
                a[2] += 1
            else:
                break
        else:
            if(X[a[0]-1] < R[a[2]]):
                a[0] -= 1
                a[2] += 1
            else:
                break
m = 0
for i in range(a[0]):
    m += P[i]
for i in range(a[1]):
    m += Q[i]
for i in range(a[2]):
    m += R[i]
print(m)

def merge(l):
    t = [-1]*len(l)
    if(len(l) == 2):
        if(l[0]<l[1]):
            t[1] = l[0]
            t[0] = l[1]
        else:
            t=l
    elif(len(l) > 2):
        x = merge(l[:len(l)//2])
        y = merge(l[len(l)//2:])
        p,q = 0,0
        for i in range(len(l)):
            if(p<len(x) and q<len(y)):
                if(x[p] > y[q]):
                    t[i] = x[p]
                    p += 1
                else:
                    t[i] = y[q]
                    q += 1
            elif(p == len(x)):
                t[i] = y[q]
                q += 1
            else:
                t[i] = x[p]
                p += 1
    else:
        t = l
    return t
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()))
a = [x,y,0]
P = merge(p)
Q = merge(q)
R = merge(r)
X = P[:x]
Y = Q[:y]
for i in range(x+y):
    if(a[2] == c):
        break
    elif(a[0] == 0):
        if(Y[a[1]-1] < R[a[2]]):
                a[1] -= 1
                a[2] += 1
        else:
            break
    elif(a[1] == 0):
        if(X[a[0]-1] < R[a[2]]):
                a[0] -= 1
                a[2] += 1
        else:
            break
    else:
        if(X[a[0]-1] > Y[a[1]-1]):
            if(Y[a[1]-1] < R[a[2]]):
                a[1] -= 1
                a[2] += 1
            else:
                break
        else:
            if(X[a[0]-1] < R[a[2]]):
                a[0] -= 1
                a[2] += 1
            else:
                break
m = 0
for i in range(a[0]):
    m += P[i]
for i in range(a[1]):
    m += Q[i]
for i in range(a[2]):
    m += R[i]
print(m)

Verdicts: Runtime Error

Accepted