Buggy python submission (verdict: Runtime Error):
X,Y,A,B,C=map(int,input().split())
P=sorted(map(int,input().split()), reverse=True)[:X]
Q=sorted(map(int,input().split()), reverse=True)[:Y]
R=sorted(map(int,input().split()), reverse=True)[:X+Y]
i,j=X-1,Y-1
for r in R:
    if i==-1 and j==-1:
        break
    elif j==-1:
        if r>P[i]:
            p[i]=r
            i-=1
        else:
            break
    elif i==-1:
        if r>Q[j]:
            Q[j]=r
            j-=1
        else:
            break
    elif P[i]>Q[j]:
        if r>Q[j]:
            Q[j]=r
            j-=1
        else:
            break
    else:
        if r>P[i]:
            p[i]=r
            i-=1
        else:
            break
print(sum(P)+sum(Q))

Fixed submission:
X,Y,A,B,C=map(int,input().split())
P=sorted(map(int,input().split()), reverse=True)[:X]
Q=sorted(map(int,input().split()), reverse=True)[:Y]
R=sorted(map(int,input().split()), reverse=True)[:X+Y]
i,j=X-1,Y-1
for r in R:
    if i==-1 and j==-1:
        break
    elif j==-1:
        if r>P[i]:
            P[i]=r
            i-=1
        else:
            break
    elif i==-1:
        if r>Q[j]:
            Q[j]=r
            j-=1
        else:
            break
    elif P[i]>Q[j]:
        if r>Q[j]:
            Q[j]=r
            j-=1
        else:
            break
    else:
        if r>P[i]:
            P[i]=r
            i-=1
        else:
            break
print(sum(P)+sum(Q))

Buggy python submission (verdict: Runtime Error):
X,Y,A,B,C=map(int,input().split())
P=sorted(map(int,input().split()), reverse=True)
Q=sorted(map(int,input().split()), reverse=True)
R=sorted(map(int,input().split()), reverse=True)
Sp,Sq,Sr=[0],[0],[0]
for i in range(A):
    Sp.append(Sp[-1]+P[i])
for i in range(B):
    Sq.append(Sq[-1]+Q[i])
l,r=0,2*10**14
while not l+1==r:
    x=(l+r)//2
    tmp=Sp[X]+Sq[Y]
    i,j,k=X,Y,0
    while tmp<x and k<C:
        if i==0 and j==0:
            break
        elif i==0:
            if R[k]>Q[j-1]:
                tmp+=R[k]-Q[j-1]
                j-=1
                k+=1
            else:
                break
        elif j==0:
            if R[k]>P[i-1]:
                tmp+=R[k]-P[i-1]
                i-=1
                k+=1
            else:
                break
        elif P[i-1]>Q[j-1]:
            if R[k]>Q[j-1]:
                tmp+=R[k]-Q[j-1]
                j-=1
                k+=1
            else:
                break
        else:
            if R[k]>P[j-1]:
                tmp+=R[k]-P[i-1]
                i-=1
                k+=1
            else:
                break
    if tmp>=x:
        l=x
    else:
        r=x

print(l)

Fixed submission:
X,Y,A,B,C=map(int,input().split())
P=sorted(map(int,input().split()), reverse=True)[:X]
Q=sorted(map(int,input().split()), reverse=True)[:Y]
R=sorted(map(int,input().split()), reverse=True)[:X+Y]
i,j=X-1,Y-1
for r in R:
    if i==-1 and j==-1:
        break
    elif j==-1:
        if r>P[i]:
            P[i]=r
            i-=1
        else:
            break
    elif i==-1:
        if r>Q[j]:
            Q[j]=r
            j-=1
        else:
            break
    elif P[i]>Q[j]:
        if r>Q[j]:
            Q[j]=r
            j-=1
        else:
            break
    else:
        if r>P[i]:
            P[i]=r
            i-=1
        else:
            break
print(sum(P)+sum(Q))