Problem p03078 (python)

Fixed submission:
from heapq import heappush, heappop

X, Y, Z, K = map(int, input().split())

A = sorted([int(e) for e in input().split()], reverse=True)
B = sorted([int(e) for e in input().split()], reverse=True)
C = sorted([int(e) for e in input().split()], reverse=True)


def get_value(ai, bi, ci):
    return -(A[ai] + B[bi] + C[ci])


heap = []
heappush(heap, (get_value(0, 0, 0), 0, 0, 0))
used = {(0, 0, 0)}

for k in range(K):
    v, ia, ib, ic = heappop(heap)
    print(-v)

    if ia + 1 < X and (ia + 1, ib, ic) not in used:
        heappush(heap, (get_value(ia + 1, ib, ic), ia + 1, ib, ic))
        used.add((ia + 1, ib, ic))
    if ib + 1 < Y and (ia, ib + 1, ic) not in used:
        heappush(heap, (get_value(ia, ib + 1, ic), ia, ib + 1, ic))
        used.add((ia, ib + 1, ic))
    if ic + 1 < Z and (ia, ib, ic + 1) not in used:
        heappush(heap, (get_value(ia, ib, ic + 1), ia, ib, ic + 1))
        used.add((ia, ib, ic + 1))

Buggy submission (verdict: Runtime Error):
K = int(input().split()[-1])

A = [int(e) for e in input().split()]
B = [int(e) for e in input().split()]
C = [int(e) for e in input().split()]
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# C = list(map(int, input().split()))


# def get_good(a, v):
#     return max(a)
#     if v is not None:
#         return max(a[a < v])
#     else:
#         max(a)



prev_a = max(A)
prev_b = max(B)
prev_c = max(C)

value = prev_a + prev_b + prev_c

A.remove(max(A))
B.remove(max(B))
C.remove(max(C))

print(value)

for i in range(K - 1):
    a = max(A)
    b = max(B)
    c = max(C)

    sub_a = prev_a - a
    sub_b = prev_b - b
    sub_c = prev_c - c

    if sub_a < sub_b and sub_a < sub_c:
        A.remove(a)
    if sub_b < sub_a and sub_b < sub_c:
        B.remove(b)
    if sub_c < sub_a and sub_c < sub_b:
        B.remove(c)


    value -= min(sub_a, sub_b, sub_c)
    print(value)

Buggy submission (verdict: Runtime Error):
X, Y, Z, K = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))


# def get_good(a, v):
#     return max(a)
#     if v is not None:
#         return max(a[a < v])
#     else:
#         max(a)



prev_a = max(A)
prev_b = max(B)
prev_c = max(C)

value = prev_a + prev_b + prev_c

A.remove(max(A))
B.remove(max(B))
C.remove(max(C))

print(value)

for i in range(K - 1):
    a = max(A)
    b = max(B)
    c = max(C)

    sub_a = prev_a - a
    sub_b = prev_b - b
    sub_c = prev_c - c

    if sub_a < sub_b and sub_a < sub_c:
        A.remove(a)
    if sub_b < sub_a and sub_b < sub_c:
        B.remove(b)
    if sub_c < sub_a and sub_c < sub_b:
        B.remove(c)


    value -= min(sub_a, sub_b, sub_c)
    print(value)

Buggy submission (verdict: Runtime Error):
X, Y, Z, K = map(int, input().split())

A = map(int, input().split())
B = map(int, input().split())
C = map(int, input().split())


def get_good(a, v):
    if v is not None:
        return max(a[a < v])
    else:
        max(a)


value = 0
a = b = c = None
for i in range(K):
    print(get_good(A, a) + get_good(B, b), get_good(C, c))
    a = get_good(a)
    b = get_good(b)
    c = get_good(c)

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys

X, Y, Z, K = map(int, input().split())

A = map(int, input().split())
B = map(int, input().split())
C = map(int, input().split())

def get_good(a, v):
    if v is not None:
        return max(a[a < v])
    else:
        max(a)

value = 0
a = b = c = None
for i in range(K):
    print(get_good(A, a) + get_good(B, b), get_good(C, c))
    a = get_good(a)
    b = get_good(b)
    c = get_good(c)