Problem p03078 (python)

Fixed submission:
from itertools import product

X, Y, Z, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

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

a = []
count = 0
for i in range(X):
    for j in range(Y):
        if (i+1)*(j+1) > K:
            break
        for k in range(Z):
            if (i+1)*(j+1)*(k+1) > K:
                break
            a.append(A[i] + B[j] + C[k])

a.sort(reverse=True)

for i in range(K):
    print(a[i])

Buggy submission (verdict: Runtime Error):
from itertools import product

X, Y, Z, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

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

a1 = []
mXY = min(X, Y)
for i, j in product(A[0:min(mXY, 3000)], B[0:min(mXY, 3000)]):
    a1.append(i + j)
a1.sort(reverse=True)

ans_list = []
for i, j in product(a1[0:min(mXY, 3000)], C[0:min(Z, 3000)]):
    ans_list.append(i + j)
ans_list.sort(reverse=True)

for i in range(K):
    print(ans_list[i])

Buggy submission (verdict: Runtime Error):
from itertools import product

X, Y, Z, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

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

if X * Y * Z > 3000:
    X = 3000
    Y = 3000
    Z = 3000

a1 = []
mXY = min(X,Y)
for i, j in product(A[0:mXY], B[0:mXY]):
    a1.append(i + j)
a1.sort(reverse=True)

ans_list = []
for i, j in product(a1[0:min(mXY,Z)], C[0:min(mXY,Z)]):
    ans_list.append(i + j)

ans_list.sort(reverse=True)

for i in range(K):
    print(ans_list[i])

Buggy submission (verdict: Runtime Error):
X, Y, Z, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

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

if X * Y * Z > 3000:
    X = 3000
    Y = 3000
    Z = 3000

ans_list = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            sum = A[i]+B[j]+C[k]
            ans_list.append(sum)        
ans_list.sort(reverse=True)
for i in range(K):
    print(ans_list[i])

Buggy submission (verdict: Runtime Error):
X, Y, Z, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

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

if X * Y * Z > 3000:
    X = 3000
    Y = 3000
    Z = 3000

ans_list = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            sum = A[i]+B[j]+C[k]
            ans_list.append(sum)        
ans_list.sort()
ans_list.reverse()
for i in range(K):
    print(ans_list[i])

Buggy submission (verdict: Runtime Error):
X, Y, Z, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

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

if X * Y * Z > 3000:
    X = 3000
    Y = 3000
    Z = 3000

ans_list = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            sum = A[i]+B[j]+C[k]
            ans_list.append(sum)        
ans_list.sort()
ans_list.reverse()
for i in range(K):
    print(ans_list[i])