Problem p02727 (python)

Fixed submission:
x, y, a, b, c = map(int, input().split())
r = sorted(list(map(int, input().split())))[a - x:]
g = sorted(list(map(int, input().split())))[b - y:]
m = list(map(int, input().split()))

ans = sorted(r + g + m)
print(sum(ans[len(ans) - x - y:]))

Buggy submission (verdict: Runtime Error):
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)
M = sorted(list(map(int, input().split())), reverse=True)

ans, r, g, m = 0, 0, 0, 0

for i in range(x + y):
    if r >= x:
        if m >= c:
            ans += G[g]
            g += 1
        elif G[g] >= M[m]:
            ans += G[g]
            g += 1
        else:
            ans += M[m]
            m += 1
    elif g >= y:
        if m >= c:
            ans += R[r]
            r += 1
        elif R[r] >= M[m]:
            ans += R[r]
            r += 1
        else:
            ans += M[m]
            m += 1
    elif R[r] > G[g]:
        if m >= c:
            ans += R[r]
            r += 1
        elif R[r] >= M[m]:
            ans += R[r]
            r += 1
        else:
            ans += M[m]
            m += 1
    elif R[r] <= G[g]:
        if m >= c:
            ans += G[g]
            g += 1
        if G[g] >= M[m]:
            ans += G[g]
            g += 1
        else:
            ans += M[m]
            m += 1
print(ans)

Buggy submission (verdict: Runtime Error):
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)
M = sorted(list(map(int, input().split())), reverse=True)

ans, r, g, m = 0, 0, 0, 0

for i in range(x + y):
    if r >= x:
        if m >= c:
            ans += G[g]
            g += 1
        elif G[g] >= M[m]:
            ans += G[g]
            g += 1
        else:
            ans += M[m]
            m += 1
    elif g >= y:
        if m >= c:
            ans += R[r]
            r += 1
        elif R[r] >= M[m]:
            ans += R[r]
            r += 1
        else:
            ans += M[m]
            m += 1
    elif R[r] >= G[g]:
        if m >= c:
            ans += R[r]
            r += 1
        elif R[r] >= M[m]:
            ans += R[r]
            r += 1
        else:
            ans += M[m]
            m += 1
    elif R[r] < G[g] or r >= x:
        if m >= c:
            ans += G[g]
            g += 1
        if G[g] >= M[m]:
            ans += G[g]
            g += 1
        else:
            ans += M[m]
            m += 1
print(ans)

Buggy submission (verdict: Runtime Error):
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)
M = sorted(list(map(int, input().split())), reverse=True)

ans, r, g, m = 0, 0, 0, 0
mr = R[x - 1]
mg = G[y - 1]

for i in range(x + y):
    if r >= x:
        if m >= c:
            ans += G[g]
            g += 1
        elif G[g] > M[m]:
            ans += G[g]
            g += 1
        else:
            ans += M[m]
            m += 1
    elif g >= y:
        if m >= c:
            ans += R[r]
            r += 1
        elif R[r] > M[m]:
            ans += R[r]
            r += 1
        else:
            ans += M[m]
            m += 1
    elif R[r] >= G[g]:
        if m >= c:
            ans += R[r]
            r += 1
        elif R[r] > M[m]:
            ans += R[r]
            r += 1
        else:
            ans += M[m]
            m += 1
    elif R[r] < G[g] or r >= x:
        if m >= c:
            ans += G[g]
            g += 1
        if G[g] > M[m]:
            ans += G[g]
            g += 1
        else:
            ans += M[m]
            m += 1
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque

x, y, a, b, c = map(int, input().split())
R = sorted(list(map(int, input().split())))[a - x:]
G = sorted(list(map(int, input().split())))[b - y:]
M = deque(sorted(list(map(int, input().split())), reverse=True))

ans = sum(R) + sum(G)
r, g, m = 0, 0, 0
for i in range(x + y):
    if not M:
        break
    if r >= x:
        if G[g] < M[m]:
        ans = ans - G[g] + M[m]
        g += 1
        m += 1
    elif g >= y:
        if R[r] < M[m]:
            ans = ans - R[r] + M[m]
        r += 1
        m += 1
    else:
        if

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)
M = sorted(list(map(int, input().split())), reverse=True)

ans, r, g, m = 0, 0, 0, 0
mr = R[x - 1]
mg = G[y - 1]

for i in range(x + y):
    if r >= x:
        if m >= c:
            ans += G[g]
            g += 1
        elif G[g] > M[m]:
            ans += G[g]
            g += 1
        else:
            ans += M[m]
            m += 1
    elif g >= y:
        if m >= c:
            ans += R[r]
            r += 1
        elif R[r] > M[m]:
            ans += R[r]
            r += 1
        else:
            ans += M[m]
            m += 1
    elif R[r] >= G[g]:
        if m >= c:
            ans += R[r]
            r += 1
        elif R[r] > M[m]:
            ans += R[r]
            r += 1
        else:
            ans += M[m]
            m += 1
    elif R[r] < G[g] or r >= x:
        if m >= c:
            ans += G[g]
            g += 1
        if G[g] > M[m]:
            ans += G[g]
            g += 1
        else:
            ans += M[m]
            m += 1
print(ans)

Buggy submission (verdict: Runtime Error):
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)
M = sorted(list(map(int, input().split())), reverse=True)

ans, r, g, m = 0, 0, 0, 0
mr = R[x - 1]
mg = G[y - 1]

for i in range(x + y):
    print(r, g, m)
    if r >= x:
        if G[g] > M[m] or m >= c:
            ans += G[g]
            g += 1
        else:
            ans += M[m]
            m += 1
    elif g >= y:
        if R[r] > M[m] or m >= c:
            ans += R[r]
            r += 1
        else:
            ans += M[m]
            m += 1
    elif R[r] >= G[g]:
        if R[r] > M[m] or m >= c:
            ans += R[r]
            r += 1
        else:
            ans += M[m]
            m += 1
    elif R[r] < G[g] or r >= x:
        if G[g] > M[m] or m >= c:
            ans += G[g]
            g += 1
        else:
            ans += M[m]
            m += 1
print(ans)