Problem p03078 (python)

Fixed submission:
import heapq
import sys
x, y, z, k = map(int, input().split())

a, b, c = (sorted(map(int, sys.stdin.readline().split()), reverse=True) for _ in range(3))

abc = {(0,0,0)}

stu = [[-a[0]-b[0]-c[0], 0,0,0]]
heapq.heapify(stu)
result = []
while k > 0:
    out_p, n, m, l = heapq.heappop(stu)
    if n+1<x and not((n+1,m,l) in abc):
        abc.add((n+1,m,l))
        heapq.heappush(stu, [-a[n+1]-b[m]-c[l], n+1, m, l])
    if m+1<y and not((n,m+1,l) in abc):
        abc.add((n,m+1,l))
        heapq.heappush(stu, [-a[n]-b[m+1]-c[l], n, m+1, l])
    if l+1<z and not((n,m,l+1) in abc):
        abc.add((n,m,l+1))
        heapq.heappush(stu, [-a[n]-b[m]-c[l+1], n, m, l+1])
    result.append(-out_p)
    k -= 1
result.sort(reverse=True)
for i in result:
    print(i)

Buggy submission (verdict: Runtime Error):
import heapq
x, y, z, k = map(int, input().split())

abc = []
heapq.heapify(abc)
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)

s, t, u = 0,0,0

if x>1:
    abc.append([a[0]-a[1], 0])
if y>1:
    abc.append([b[0]-b[1], 1])
if z>1:
    abc.append([c[0]-c[1], 2])
heapq.heapify(abc)
s, t, u = 0,0,0
while len(abc)>0 and s*t*u<3000:
    n, m = heapq.heappop(abc)
    if m == 0:
        s += 1
        if s < x:
            heapq.heappush(abc, [a[s-1]-a[s], 0])
    elif m == 1:
        t += 1
        if t < y:
            heapq.heappush(abc, [b[t-1]-b[t], 1])
    else:
        u += 1
        if u < z:
            heapq.heappush(abc, [c[u-1]-c[u], 2])
ABC = []
heapq.heapify(ABC)
for i in range(s):
    for j in range(t):
        for ij in range(u):
            heapq.heappush(ABC, -a[i]-b[j]-c[ij])
for _ in range(k):
    print(-heapq.heappop(ABC))

Buggy submission (verdict: Runtime Error):
import heapq
x, y, z, k = map(int, input().split())

abc = []
heapq.heapify(abc)
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)

s, t, u = 0,0,0

if x>1:
    abc.append([a[0]-a[1], 0])
if y>1:
    abc.append([b[0]-b[1], 1])
if z>1:
    abc.append([c[0]-c[1], 2])
heapq.heapify(abc)
s, t, u = 0,0,0
while len(abc)>0 and s*t*u<k:
    n, m = heapq.heappop(abc)
    if m == 0:
        s += 1
        if s < x:
            heapq.heappush(abc, [a[s-1]-a[s], 0])
    elif m == 1:
        t += 1
        if t < y:
            heapq.heappush(abc, [b[t-1]-b[t], 1])
    else:
        u += 1
        if u < z:
            heapq.heappush(abc, [c[u-1]-c[u], 2])
ABC = []
heapq.heapify(ABC)
for i in range(s):
    for j in range(t):
        for ij in range(u):
            heapq.heappush(ABC, -a[i]-b[j]-c[ij])
for _ in range(k):
    print(-heapq.heappop(ABC))

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(' ')))
ab = []
for i in range(len(a)):
    for j in range(len(b)):
        ab.append(a[i]+b[j])
ab.sort(reverse = True)
abc = []
k_1 = min([len(ab), k])
for i in range(k_1):
    for j in range(len(c)):
        abc.append(ab[i]+c[j])
abc.sorat(reverse = True)
for i in range(k):
    print(abc[i])