Buggy python submission (verdict: Time Limit Exceeded):

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(key=lambda x:-x)
b.sort(key=lambda x:-x)
c.sort(key=lambda x:-x)
# queue=[beauty, indexa, indexb, indexc]
queue=[(a[0]+b[0]+c[0],0,0,0)]
canAdd=[[[1 for _ in range(z)]for _ in range(y)]for _ in range(x)]
beauty=[0 for _ in range(k)]
for index in range(k):
    queue.sort(key=lambda x:-x[0])
    # print(queue)
    beauty[index],indexa,indexb,indexc=queue[0]
    queue.pop(0)
    for da,db,dc in [(1,0,0),(0,1,0),(0,0,1)]:
        nexta,nextb,nextc=indexa+da,indexb+db,indexc+dc
        if nexta<x and nextb<y and nextc<z and (nexta+1)*(nextb+1)*(nextc+1)<=k:
            if canAdd[nexta][nextb][nextc]:
                queue.append((a[nexta]+b[nextb]+c[nextc],nexta,nextb,nextc))
                canAdd[nexta][nextb][nextc]=0
for i in range(k):
    print(beauty[i])


Fixed submission:

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(key=lambda x:-x)
b.sort(key=lambda x:-x)
c.sort(key=lambda x:-x)
beauty=[]
index=0
for i in range(x):
    for j in range(y):
        for l in range(z):
            if (i+1)*(j+1)*(l+1)<=k:
                beauty.append(a[i]+b[j]+c[l])
            else:
                break
beauty.sort(key=lambda x:-x)
for i in range(k):
    print(beauty[i])

Buggy python submission (verdict: Time Limit Exceeded):

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(key=lambda x:-x)
b.sort(key=lambda x:-x)
c.sort(key=lambda x:-x)
# queue=[beauty, indexa, indexb, indexc]
queue=[(a[0]+b[0]+c[0],0,0,0)]
canAdd=[[[1 for _ in range(z)]for _ in range(y)]for _ in range(x)]
beauty=[0 for _ in range(k)]
for index in range(k):
    queue.sort(key=lambda x:-x[0])
    # print(queue)
    beauty[index],indexa,indexb,indexc=queue[0]
    queue.pop(0)
    for da,db,dc in [(1,0,0),(0,1,0),(0,0,1)]:
        if indexa+da<x and indexb+db<y and indexc+dc<z:
            if canAdd[indexa+da][indexb+db][indexc+dc]:
                queue.append((a[indexa+da]+b[indexb+db]+c[indexc+dc],indexa+da,indexb+db,indexc+dc))
                canAdd[indexa+da][indexb+db][indexc+dc]=0
for i in range(k):
    print(beauty[i])


Fixed submission:

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(key=lambda x:-x)
b.sort(key=lambda x:-x)
c.sort(key=lambda x:-x)
beauty=[]
index=0
for i in range(x):
    for j in range(y):
        for l in range(z):
            if (i+1)*(j+1)*(l+1)<=k:
                beauty.append(a[i]+b[j]+c[l])
            else:
                break
beauty.sort(key=lambda x:-x)
for i in range(k):
    print(beauty[i])

Buggy python 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()))
a.sort(key=lambda x:-x)
b.sort(key=lambda x:-x)
c.sort(key=lambda x:-x)
# queue=[beauty, indexa, indexb, indexc]
queue=[(a[0]+b[0]+c[0],0,0,0)]
beauty=[0 for _ in range(k)]
index=0
indexq=0
while index<k:
    queue.sort(key=lambda x:-x[0])
    # print(queue)
    beauty[index],indexa,indexb,indexc=queue[indexq]
    index+=1
    indexq+=1
    for da,db,dc in [(1,0,0),(0,1,0),(0,0,1)]:
        # print(indexa+da,indexb+db,indexc+dc)
        if indexa+da<x and indexb+db<y and indexc+dc<z:
            queue.append((a[indexa+da]+b[indexb+db]+c[indexc+dc],indexa+da,indexb+db,indexc+dc))
    queue=list(set(queue))
for i in range(k):
    print(beauty[i])


Fixed submission:

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(key=lambda x:-x)
b.sort(key=lambda x:-x)
c.sort(key=lambda x:-x)
beauty=[]
index=0
for i in range(x):
    for j in range(y):
        for l in range(z):
            if (i+1)*(j+1)*(l+1)<=k:
                beauty.append(a[i]+b[j]+c[l])
            else:
                break
beauty.sort(key=lambda x:-x)
for i in range(k):
    print(beauty[i])

Buggy python submission (verdict: Time Limit Exceeded):

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(key=lambda x:-x)
b.sort(key=lambda x:-x)
c.sort(key=lambda x:-x)
sumAB=[0 for _ in range(x*y)]
index=0
imax=min(k,x)
jmax=min(k,y)
for i in range(imax):
    for j in range(jmax):
        sumAB[index]=a[i]+b[j]
        index+=1
sumAB.sort(key=lambda x:-x)
beauty=[0 for _ in range(k*k)]
index=0
imax=min(k,x*y)
jmax=min(k,z)
for i in range(imax):
    for j in range(jmax):
        beauty[index]=sumAB[i]+c[j]
        index+=1
beauty.sort(key=lambda x:-x)
for i in range(k):
    print(beauty[i])


Fixed submission:

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(key=lambda x:-x)
b.sort(key=lambda x:-x)
c.sort(key=lambda x:-x)
beauty=[]
index=0
for i in range(x):
    for j in range(y):
        for l in range(z):
            if (i+1)*(j+1)*(l+1)<=k:
                beauty.append(a[i]+b[j]+c[l])
            else:
                break
beauty.sort(key=lambda x:-x)
for i in range(k):
    print(beauty[i])

Buggy python submission (verdict: Time Limit Exceeded):

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()))
sumAB=[0 for _ in range(x*y)]
index=0
imax=min(k,x)
jmax=min(k,y)
for i in range(imax):
    for j in range(jmax):
        sumAB[index]=a[i]+b[j]
        index+=1
sumAB.sort(key=lambda x:-x)
c.sort(key=lambda x:-x)
beauty=[0 for _ in range(k*k)]
index=0
imax=min(k,x*y)
jmax=min(k,z)
for i in range(imax):
    for j in range(jmax):
        beauty[index]=sumAB[i]+c[j]
        index+=1
beauty.sort(key=lambda x:-x)
for i in range(k):
    print(beauty[i])

Fixed submission:

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(key=lambda x:-x)
b.sort(key=lambda x:-x)
c.sort(key=lambda x:-x)
beauty=[]
index=0
for i in range(x):
    for j in range(y):
        for l in range(z):
            if (i+1)*(j+1)*(l+1)<=k:
                beauty.append(a[i]+b[j]+c[l])
            else:
                break
beauty.sort(key=lambda x:-x)
for i in range(k):
    print(beauty[i])

Buggy python submission (verdict: Time Limit Exceeded):
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()))
beauty=[0 for _ in range(x*y*z)]
index=0
for i in range(x):
    for j in range(y):
        for l in range(z):
            beauty[index]=a[i]+b[j]+c[l]
            index+=1
beauty.sort(key=lambda x:-x)
# print(beauty)
for i in range(k):
    print(beauty[i])


Fixed submission:

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(key=lambda x:-x)
b.sort(key=lambda x:-x)
c.sort(key=lambda x:-x)
beauty=[]
index=0
for i in range(x):
    for j in range(y):
        for l in range(z):
            if (i+1)*(j+1)*(l+1)<=k:
                beauty.append(a[i]+b[j]+c[l])
            else:
                break
beauty.sort(key=lambda x:-x)
for i in range(k):
    print(beauty[i])