Problem p02727 (python)

Fixed submission:
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)
eat_p = p[:X]
eat_q = q[:Y]

all_apple = eat_p + eat_q + r
all_apple.sort(reverse=True)

print(sum(all_apple[:X+Y]))

Buggy submission (verdict: Runtime Error):
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)
eat_p = p[:X]
eat_q = q[:Y]

ans = sum(eat_p) + sum(eat_q)
if A == 1:
    i = 0
else:
    i = -1
if B == 1:
    j = 0
else:
    j = -1
k = 0

while True:
    if k == C or (eat_p[i] >= r[k] and eat_q[j] >= r[k]):
        break
    if eat_p[i] < eat_q[j] and eat_p[i] < r[k]:
        ans += r[k] - eat_p[i]
        k += 1
        i -= 1
    elif eat_p[i] >= eat_q[j] and eat_q[j] < r[k]:
        ans += r[k] - eat_q[j]
        k += 1
        j -= 1
    if i == -A:
        i = 0
    if j == -B:
        j = 0

print(ans)

Buggy submission (verdict: Runtime Error):
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)
eat_p = p[:X]
eat_q = q[:Y]

ans = sum(eat_p) + sum(eat_q)
if A == 1:
    i = 0
else:
    i = -1
if B == 1:
    j = 0
else:
    j = -1
k = 0

while True:
    if k == C or (eat_p[i] >= r[k] and eat_q[j] >= r[k]):
        break
    if eat_p[i] < eat_q[j] and eat_p[i] < r[k]:
        ans += r[k] - eat_p[i]
        k += 1
        i -= 1
    if eat_p[i] >= eat_q[j] and eat_q[j] < r[k]:
        ans += r[k] - eat_q[j]
        k += 1
        j -= 1
    if i == -A:
        i = 0
    if j == -B:
        j = 0

print(ans)

Buggy submission (verdict: Runtime Error):
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)
eat_p = p[:X]
eat_q = q[:Y]

ans = sum(eat_p) + sum(eat_q)
if A == 1:
    i = 0
else:
    i = -1
if B == 1:
    j = 0
else:
    j = -1
k = 0

while True:
    if eat_p[i] < eat_q[j] and eat_p[i] < r[k]:
        ans += r[k] - eat_p[i]
        k += 1
        i -= 1
    if eat_p[i] >= eat_q[j] and eat_q[j] < r[k]:
        ans += r[k] - eat_q[j]
        k += 1
        j -= 1
    if k == C or (eat_p[i] >= r[k] and eat_q[j] >= r[k]):
        break
    if i == -A:
        i = 0
    if j == -B:
        j = 0

print(ans)

Buggy submission (verdict: Runtime Error):
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)
eat_p = p[:X]
eat_q = q[:Y]

ans = sum(eat_p) + sum(eat_q)
i, j, k = -1, -1, 0
while True:
    if eat_p[i] < eat_q[j] and eat_p[i] < r[k]:
        ans += r[k] - eat_p[i]
        k += 1
        i -= 1
    if eat_p[i] >= eat_q[j] and eat_q[j] < r[k]:
        ans += r[k] - eat_q[j]
        k += 1
        j -= 1
    if k == C or (eat_p[i] >= r[k] and eat_q[j] >= r[k]):
        break
    if i == -A:
        i = 0
    if j == -B:
        j = 0

print(ans)

Buggy submission (verdict: Runtime Error):
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)
eat_p = p[:X]
eat_q = q[:Y]

ans = sum(eat_p) + sum(eat_q)
i, j, k = -1, -1, 0
while True:
    if eat_p[i] < eat_q[j] and eat_p[i] < r[k]:
        ans += r[k] - eat_p[i]
        k += 1
        i -= 1
    if eat_p[i] >= eat_q[j] and eat_q[j] < r[k]:
        ans += r[k] - eat_q[j]
        k += 1
        j -= 1
    if k == C or (eat_p[i] > r[k] and eat_q[j] > r[k]):
        break
    if i == -A:
        i = 0
    if j == -B:
        j = 0

print(ans)

Buggy submission (verdict: Runtime Error):
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)
eat_p = p[:X]
eat_q = q[:Y]

ans = sum(eat_p) + sum(eat_q)
i, j, k = -1, -1, 0
while eat_p[i] < r[k] or eat_q[j] < r[k]:
    if eat_p[i] < eat_q[j]:
        ans += r[k] - eat_p[i]
        k += 1
        i -= 1
    else:
        ans += r[k] - eat_q[j]
        k += 1
        j -= 1
    if k == C:
        break
    if i == -A:
        i = 0
    if j == -B:
        j = 0

print(ans)