Problem p03078 (python)

Fixed submission:
import numpy as np
from heapq import *

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

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

h = []
heappush(h, (-A[0]-B[0]-C[0], 0, 0, 0))
used = set()
result = []

for _ in range(K):
    sum, i, j, k = heappop(h)
    result.append(-sum)
    if i < X-1 and (i+1, j, k) not in used:
        heappush(h, (-A[i+1]-B[j]-C[k], i+1, j, k))
        used.add((i+1, j, k))
    if j < Y-1 and (i, j+1, k) not in used:
        heappush(h, (-A[i]-B[j+1]-C[k], i, j+1, k))
        used.add((i, j+1, k))
    if k < Z-1 and (i, j, k+1) not in used:
        heappush(h, (-A[i]-B[j]-C[k+1], i, j, k+1))
        used.add((i, j, k+1))

for v in result:
    print(v)

Buggy submission (verdict: Runtime Error):
import numpy as np
from heapq import *

X, Y, Z, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))

# 二分探索でK個の選び方を探す
up = 10 ** 10 + 1 # 不可能
low = 0 # 可能
A_max = A.max()
B_max = B.max()
C_max = C.max()
while up > low + 1:
    mid = (up+low)// 2
    if (A >= A_max - mid).sum() * (B >= B_max - mid).sum() * (C >= C_max - mid).sum() >= K:
        low = mid
    else:
        up = mid
A_line = A_max - low
B_line = B_max - low
C_line = C_max - low
A = [x for x in A if x >= A_line]
B = [x for x in B if x >= B_line]
C = [x for x in C if x >= C_line]
L = []
heapify(L)
for a in A:
    for b in B:
        for c in C:
            heappush(L, -(a+b+c))
for i in range(K):
    n = heappop(L)
    print(-n)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 7)

import numpy as np
from heapq import *

X, Y, Z, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))

# 二分探索でK個の選び方を探す
up = 10 ** 10 + 1 # 不可能
low = 0 # 可能
while up > low + 1:
    mid = (up+low)// 2
    if (A >= A.max() - mid).sum() * (B >= B.max() - mid).sum() * (C >= C.max() - mid).sum() >= K:
        low = mid
    else:
        up = mid
A_line = A.max() - low
B_line = B.max() - low
C_line = C.max() - low
A = [x for x in A if x >= A_line]
B = [x for x in B if x >= B_line]
C = [x for x in C if x >= C_line]
L = []
heapify(L)
for a in A:
    for b in B:
        for c in C:
            heappush(L, -(a+b+c))
for i in range(K):
    n = heappop(L)
    print(-n)

Buggy submission (verdict: Runtime Error):
import numpy as np
from heapq import *

X, Y, Z, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))

# 二分探索でK個の選び方を探す
up = 10 ** 10 + 1 # 不可能
low = 0 # 可能
while up > low + 1:
    mid = (up+low)// 2
    if (A >= A.max() - mid).sum() * (B >= B.max() - mid).sum() * (C >= C.max() - mid).sum() >= K:
        low = mid
    else:
        up = mid
A = [x for x in A if x >= A.max() - low]
B = [x for x in B if x >= B.max() - low]
C = [x for x in C if x >= C.max() - low]
L = []
heapify(L)
for a in A:
    for b in B:
        for c in C:
            heappush(L, -(a+b+c))
for i in range(K):
    n = heappop(L)
    print(-n)