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


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)
red = list(map(int, inp().split()))
green = list(map(int, inp().split()))
white = list(map(int, inp().split()))
red.sort(reverse=True)
green.sort(reverse=True)
white.sort(reverse=True)
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] and red[idr] >= white[idw]:
        #eat red
        total += red[idr]
        idr += 1
        countr += 1
    elif green[idg] > red[idr] and green[idg] >= white[idw]:
        # eat green
        total += green[idg]
        idg += 1
        countg += 1
    else:
        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))


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)
red = list(map(int, inp().split()))
green = list(map(int, inp().split()))
white = list(map(int, inp().split()))
red.sort(reverse=True)
green.sort(reverse=True)
white.sort(reverse=True)
fin.close()

#red[::-1].sort()
#green[::-1].sort()
#white[::-1].sort()

idr = 0
idg = 0
idw = 0

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

#eat remain
if Y <= countg:
    while X > countr+countw:
        # 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

if X <= countr:
    while Y > countg+countw:
        # 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))


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)
red = list(map(int, inp().split()))
green = list(map(int, inp().split()))
white = list(map(int, inp().split()))
red.sort(reverse=True)
green.sort(reverse=True)
white.sort(reverse=True)
#fin.close()

#red[::-1].sort()
#green[::-1].sort()
#white[::-1].sort()

idr = 0
idg = 0
idw = 0

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

#eat remain
if Y <= countg:
    while X > countr+countw:
        # 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

if X <= countr:
    while Y > countg+countw:
        # 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))


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted