TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cake has an integer value called _deliciousness_ , as follows:    * The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.   * The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.   * The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.  Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.   There are X \times Y \times Z such ways to choose three cakes.   We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.   Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Submission attempts (in order):
import heapq
hq=[]
X, Y, Z, K= map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
B=list(map(int,input().split()))
B.sort(reverse=True)
C=list(map(int,input().split()))
C.sort(reverse=True)
searched={(0,0,0)}
heapq.heappush(hq,(-(A[0]+B[0]+C[0]),0,0,0))
D=[[1,0,0],[0,1,0],[0,0,1]]

for _ in range(K):
    abc,x,y,z=heapq._heappop_max(hq)
    print(-abc)
    for dx,dy,dz in D:
        if x+dx<X and y+dy < Y and z+dz < Z and (x+dx,y+dy,z+dz) not in searched:
            heapq.heappush(hq,(-(A[x+dx]+B[y+dy]+C[z+dz]),x+dx,y+dy,z+dz))
            searched.add((x+dx,y+dy,z+dz))

X, Y, Z, K= map(int,input().split())
A=list(map(int,input().split())).sort(reverse=True)
B=list(map(int,input().split())).sort(reverse=True)
C=list(map(int,input().split())).sort(reverse=True)

ABC=[]
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i+1)*(j+1)*(k+1)>K:
                break
            else:
                ABC.append(X[i]+Y[j]+Z[k])
                
ABC.sort(reverse=True)

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

import queue
pq=queue.PriorityQueue()
X, Y, Z, K= map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
B=list(map(int,input().split()))
B.sort(reverse=True)
C=list(map(int,input().split()))
C.sort(reverse=True)
searched={(0,0,0)}
pq.put((-(A[0]+B[0]+C[0]),(0,0,0)))
D=[[1,0,0],[0,1,0],[0,0,1]]

for _ in range(K):
    value,index=pq.get()
    x,y,z=index
    print(-value)
    for dx,dy,dz in D:
        if x+dx<X and y+dy < Y and z+dz < Z and (x+dx,y+dy,z+dz) not in searched:
            pq.put((-(A[x+dx]+B[y+dy]+C[z+dz]),(x+dx,y+dy,z+dz)))
            searched.add((x+dx,y+dy,z+dz))

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cake has an integer value called _deliciousness_ , as follows:    * The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.   * The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.   * The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.  Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.   There are X \times Y \times Z such ways to choose three cakes.   We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.   Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Submission attempts (in order):
X, Y, Z, K = list(map(int, input().split()))
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 = []

for i in A:
	for j in B:
		for k in C:
			s.append(i+j+k)

s = sorted(s, reverse=True)

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

X, Y, Z, K = list(map(int, input().split()))
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 = []

for i in A:
    for j in B:
        for k in C:
            s.append(i+j+k)

s = sorted(s, reverse=True)

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

X, Y, Z, K = list(map(int, input().split()))
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)
e = []
s = []

for i in A:
    for j in B:
        e.append(i+j)
e = sorted(e, reverse=True)

if K<len(e):
    e = e[0:K]

for i in e:
    for j in C:
        s.append(i+j)

s = sorted(s, reverse=True)

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

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cake has an integer value called _deliciousness_ , as follows:    * The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.   * The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.   * The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.  Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.   There are X \times Y \times Z such ways to choose three cakes.   We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.   Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Submission attempts (in order):
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=sorted(s+t for t in B for s in A)[-1:K-1:-1]
print(*sorted(i+x for i in ab for x in C)[::-1][:K],sep="\n")

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()))
print(*sorted([i+g for i in sorted(s+t for t in B for s in A)[-1:K-1:-1]for g in C])[::-1][:K],sep='\n')

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=sorted(s+t for t in B for s in A)[-1:K-1:-1]
print(*sorted(i+x for i in ab for x in C)[-1:K-1:-1],sep="\n")

X, Y, Z, K = map(int, input().split())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
ab=sorted(s+t for t in B for s in A)[-1:-K-1:-1]
abc=sorted(i+x for i in ab for x in C)[-1:-K-1:-1]
print(*abc,sep="\n")

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cake has an integer value called _deliciousness_ , as follows:    * The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.   * The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.   * The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.  Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.   There are X \times Y \times Z such ways to choose three cakes.   We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.   Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Submission attempts (in order):
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_total_list = []
total_list = []

A.sort()
A.reverse()
if len(A) > K:
    A = A[0:K+1]

B.sort()
B.reverse()
if len(B) > K:
    B = B[0:K+1]

C.sort()
C.reverse()
if len(C) > K:
    C = C[0:K+1]

ab_total_list = []
for i in A:
    for j in B:
        ab_total_list.append(i+j)

ab_total_list.sort()
ab_total_list.reverse()
if len(ab_total_list) > K:
    ab_total_list = ab_total_list[0:K+1]

z = 0
min_total = 0
if K > len(ab_total_list):
    min_total = ab_total_list[-1]
else:
    min_total = ab_total_list[K]

for i in range(0, K):
    for j in range(0, int(K/(i+1))):
        if j >= len(C):
            break
        total = ab_total_list[i] + C[j]
        total_list.append(total)
        if (i*j) > K:
            break

total_list.sort()
total_list.reverse()
for i in range(0, K):
    print(total_list[i])

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_total_list = []
total_list = []

A.sort()
A.reverse()
if len(A) > K:
    A = A[0:K+1]

B.sort()
B.reverse()
if len(B) > K:
    B = B[0:K+1]

C.sort()
C.reverse()
if len(C) > K:
    C = C[0:K+1]

ab_total_list = []
for i in A:
    for j in B:
        ab_total_list.append(i+j)

ab_total_list.sort()
ab_total_list.reverse()
if len(ab_total_list) > K:
    ab_total_list = ab_total_list[0:K+1]

for i in range(0, K):
    for j in range(0, int(K/(i+1))):
        if j >= len(C) or i >= len(ab_total_list):
            break
        total = ab_total_list[i] + C[j]
        total_list.append(total)
        if (i*j) > K:
            break

total_list.sort()
total_list.reverse()
for i in range(0, K):
    print(total_list[i])

Verdicts: Runtime Error

Accepted
Problem: The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cake has an integer value called _deliciousness_ , as follows:    * The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.   * The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.   * The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.  Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.   There are X \times Y \times Z such ways to choose three cakes.   We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.   Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Submission attempts (in order):
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)
tem=[]
ans=[]

for i in a:
  for j in b:
    tem.append(i+j)
    
tem=tem[:min(3001,x*y*z+1)]

for k in c:
  for l in tem:
    ans.append(k+l)
    
ans.sort()

for m in range(k):
  print(ans[m])

x,y,z,k = map(int,input().split())
lisa = list(map(int,input().split()))
lisb = list(map(int,input().split()))
lisc = list(map(int,input().split()))
lisa.sort(reverse=True)
lisb.sort(reverse=True)
lisc.sort(reverse=True)
an = []
ans = []
for num in lisb:
    for nu in lisa:
        an.append(num+nu)
an.sort(reverse=True)
an = an[:min(3001,x*y*z+1)]
for num in lisc:
    for nu in an:
        ans.append(num+nu)
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])
#sample code.

Verdicts: Runtime Error

Accepted
Problem: The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cake has an integer value called _deliciousness_ , as follows:    * The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.   * The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.   * The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.  Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.   There are X \times Y \times Z such ways to choose three cakes.   We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.   Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Submission attempts (in order):
from itertools import product
import sys
input = sys.stdin.readline

X, Y, Z, K = map(int, input().split())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]
A = sorted(A)[::-1]
B = sorted(B)[::-1]
C = sorted(C)[::-1]

List = [-1]*(X*Y)
Listcnt = 0
for i, j in product(A, B):
    List[Listcnt] = i+j
    Listcnt += 1

List = sorted(List)[-1:-K-1:-1]
ans = [-1]*(len(List)*Z)
anscnt = 0
for i, j in product(List, C):
    ans[anscnt] = i+j
    anscnt += 1
ans = sorted(ans)[-1:-K-1:-1]

print(ans)

from itertools import product
import sys
input = sys.stdin.readline

X, Y, Z, K = map(int, input().split())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]
A = sorted(A)[::-1]
B = sorted(B)[::-1]
C = sorted(C)[::-1]

List = []
for i, j in product(A, B):
    List.append(i+j)

List = sorted(List)[-1:-K-1:-1]
ans = []

for i, j in product(List, C):
    ans.append(i+j)
ans = sorted(ans)[::-1]

print(ans[:K])

X, Y, Z, K = map(int, input().split())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]
A = sorted(A)[::-1]
B = sorted(B)[::-1]
C = sorted(C)[::-1]

List = []

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

List = sorted(List)[-1:-K-1:-1]
for i in range(K):
    print(List[i])

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cake has an integer value called _deliciousness_ , as follows:    * The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.   * The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.   * The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.  Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.   There are X \times Y \times Z such ways to choose three cakes.   We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.   Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Submission attempts (in order):
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)
i = 0
j = 0
k = 0
while i+j+k < min(3000,X*Y*Z):
  ans = A[i]+B[j]+C[k]
  deltaA = 10**16
  deltaB = 10**16
  deltaC = 10**16
  if i+j+k == min(3000,X*Y*Z)-1:
    break
  if i+1<X:
    deltaA=A[i]-A[i+1]
  if j+1<Y:
    deltaB=B[j]-B[j+1]
  if k+1<Z:
    deltaC=C[k]-C[k+1]
  L = 10**16
  index = -1
  w = [deltaA,deltaB,deltaC]
  for mm in range(3):
    if w[i] < L:
      L = w[mm]
      index = mm
  if index==0:
    i+=1
  elif index==1:
    j+=1
  else:
    k+=1
I=i+1
J=j+1
M=k+1
answers =[]
for i in range(I):
  for j in range(J):
    for k in range(M):
      answers.append(A[i]+B[j]+C[k])
answers.sort(reverse=True)
for i in range(min(3000,X*Y*Z)):
  print(answers[i])


import heapq
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)

i=j=k=0
HQ = []
heapq.heapify(HQ)
heapq.heappush(HQ,(-(A[i]+B[j]+C[k]),(i,j,k)))
alreadyAdded = set()
alreadyAdded.add((i,j,k))
for _ in range(K):
    valueNeg,index = heapq.heappop(HQ)
    print(-valueNeg)
    l,m,n = index
    nextIndex = []
    if l+1 < X:
        nextIndex.append((l+1,m,n))
    if m+1 < Y:
        nextIndex.append((l,m+1,n))
    if n+1 < Z:
        nextIndex.append((l,m,n+1))
    for l,m,n in nextIndex:
        if (l,m,n) not in alreadyAdded:
            heapq.heappush(HQ,(-(A[l]+B[m]+C[n]),(l,m,n)))
            alreadyAdded.add((l,m,n))

Verdicts: Runtime Error

Accepted
Problem: The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cake has an integer value called _deliciousness_ , as follows:    * The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.   * The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.   * The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.  Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.   There are X \times Y \times Z such ways to choose three cakes.   We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.   Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Submission attempts (in order):
X,Y,Z,K = map(int,input().split())
AList = list(map(int,input().split()))
BList = list(map(int,input().split()))
CList = list(map(int,input().split()))
AList.sort(reverse=True)
BList.sort(reverse=True)
CList.sort(reverse=True)
print(AList)
print(BList)
print(CList)
ans = []
for x in range(X):
    for y in range(Y):
        if (x+1)*(y+1) > min(K,X*Y):
            break
        for z in range(Z):
            if (x+1)*(y+1)*(z+1) > min(K,X*Y*Z):
                break
            ans.append( AList[x] + BList[y] + CList[z])

ans.sort(reverse=True)
for i in range(K):
    print(ans[i])


X,Y,Z,K = map(int,input().split())
AList = list(map(int,input().split()))
BList = list(map(int,input().split()))
CList = list(map(int,input().split()))
AList.sort(reverse=True)
BList.sort(reverse=True)
CList.sort(reverse=True)
ans = []
for x in range(X):
    for y in range(Y):
        if (x+1)*(y+1) > min(K,X*Y):
            break
        for z in range(Z):
            if (x+1)*(y+1)*(z+1) > min(K,X*Y*Z):
                break
            ans.append( AList[x] + BList[y] + CList[z])

ans.sort(reverse=True)
for i in range(K):
    print(ans[i])


Verdicts: Wrong Answer

Accepted
Problem: The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cake has an integer value called _deliciousness_ , as follows:    * The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.   * The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.   * The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.  Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.   There are X \times Y \times Z such ways to choose three cakes.   We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.   Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Submission attempts (in order):


x, y, z, k = map(int, input().split())

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


total = [0]*k
count = 0


def sum_all(a, b, change):
	for i in range(len(change)):
		try:
			total[count] = change[i]
			count += 1
		except IndexError:
			sort_total = sorted(total)
			for i in total:
				print(i)

			quit()

i, j, k = x-1, y-1, z-1
start = 0
while i > 0 or j > 0 or k > 0:
	possible = sorted([A[i], B[j], C[k]])
	now = possible[start]
	
	if A[i] == now:
		sum_all(B[j], C[k], A[:i+1])
	elif B[i] == now:
		sum_all(A[i], C[k], B[:j+1])
	else:
		sum_all(A[i], B[j], C[:k+1])

	start += 1
	if start == 2:
		i -= 1
		j -= 1
		k -= 1




x, y, z, K = map(int, input().split())

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)

temp = []
for a in A:
	for b in B:
		temp.append(a+b)

temp = sorted(temp, reverse=True)
temp = temp[:K]

ans = []
for c in C:
	for num in temp:
		ans.append(num+c)

ans = sorted(ans, reverse=True)
for i in range(K):
	print(ans[i])

Verdicts: Runtime Error

Accepted
Problem: The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cake has an integer value called _deliciousness_ , as follows:    * The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.   * The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.   * The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.  Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.   There are X \times Y \times Z such ways to choose three cakes.   We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.   Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Submission attempts (in order):
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 = []
ans = []
for a in A:
    for b in B:
        AB.append(a + b)
AB.sort(reverse=True)
AB = AB[:min(3001,X*Y*Z+1)]
for c in C:
    for ab in AB:
        ans.append(c + ab)
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])


import sys
X, Y, Z, K = map(int, input().split())
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))
C = list(map(int, sys.stdin.readline().split()))
A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
AB = []
ans = []
for a in A:
    for b in B:
        AB.append(a + b)
AB.sort(reverse=True)
AB = AB[:min(3001, X*Y*Z+1)]
for c in C:
    for ab in AB:
        ans.append(c + ab)
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])


Verdicts: Runtime Error

Accepted
Problem: The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cake has an integer value called _deliciousness_ , as follows:    * The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.   * The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.   * The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.  Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.   There are X \times Y \times Z such ways to choose three cakes.   We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.   Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Submission attempts (in order):
Anum, Bnum, Cnum, K = map(int, input().split())
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)

iA = 0
iB = 0
iC = 0
while((iA + 1) * (iB + 1) * (iC + 1) < K):
    nextA = A[min(iA + 1, Anum - 1)] + B[iB] + C[iC]
    if(iA == Anum - 1): nextA = 0
    nextB = A[iA] + B[min(iB + 1, Bnum - 1)] + C[iC]
    if(iB == Bnum - 1): nextB = 0
    nextC = A[iA] + B[iB] + C[min(iC + 1, Cnum - 1)]
    if(iC == Cnum - 1): nextC = 0

    yummax = max(nextA, nextB, nextC)
    if(yummax == nextA):
        iA += 1
    if(yummax == nextB):
        iB += 1
    if(yummax == nextC):
        iC += 1
    if(iA == Anum - 1) and (iB == Bnum - 1) and (iC == Cnum - 1):
        break

yum = []
for ia in range(min(iA + 3, Anum)):
    for ib in range(min(iB + 4, Bnum)):
        for ic in range(min(iC + 5, Cnum)):
            print("ia={},ib={},ic={},yum={}".format(ia,ib,ic,A[ia]+B[ib]+C[ic]))
            yum.append(A[ia] + B[ib] + C[ic])
yum.sort(reverse=True)

for k in range(K):
    print(yum[k])


Anum, Bnum, Cnum, K = map(int, input().split())
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)

yum = []
for ia in range(Anum):
    if(ia > K):
        break
    for ib in range(Bnum):
        if(ia * ib > K):
            break
        for ic in range(Cnum):
            if(ia * ib * ic > K):
                break
            yum.append(A[ia] + B[ib] + C[ic])
yum.sort(reverse=True)
for k in range(K):
    print(yum[k])


Verdicts: Wrong Answer

Accepted
Problem: The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cake has an integer value called _deliciousness_ , as follows:    * The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.   * The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.   * The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.  Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.   There are X \times Y \times Z such ways to choose three cakes.   We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.   Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Submission attempts (in order):
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()]
C.sort(reverse=True)
A_B=[]
SUM=[]
for i in range(X):
  for j in range(Y):
    A_B.append(A[i]+B[j])
A_B.sort(reverse=True)
for i in range(K):
  for j in range(min(K,Z)):
    SUM.append(A_B[i]+C[j])
SUM.sort(reverse=True)
for i in range(K):
  print(SUM[i])

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_B=[]
SUM=[]
for i in range(min(K,X)):
  for j in range(min(K,Y)):
    A_B.append(A[i]+B[j])
A_B.sort(reverse=True)
for i in range(min(K,X,Y)):
  for j in range(min(K,Z)):
    SUM.append(A_B[i]+C[j])
SUM.sort(reverse=True)
for i in range(K):
  print(SUM[i])

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_B=[]
SUM=[]
for i in range(X):
  for j in range(Y):
    A_B.append(A[i]+B[j])
A_B.sort(reverse=True)
for i in range(K):
  for j in range(Z):
    SUM.append(A_B[i]+C[j])
SUM.sort(reverse=True)
for i in range(K):
  print(SUM[i])

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)
SUM=[]
for i in range(X):
  for j in range(Y):
    for k in range(Z):
      if (i+1)*(j+1)*(k+1)<=K:
        SUM.append(A[i]+B[j]+C[k])
      else:
        break
SUM.sort(reverse=True)
for i in range(K):
  print(SUM[i])

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cake has an integer value called _deliciousness_ , as follows:    * The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.   * The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.   * The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.  Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.   There are X \times Y \times Z such ways to choose three cakes.   We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.   Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Submission attempts (in order):
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])

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)

Verdicts: Runtime Error

Accepted
Problem: The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cake has an integer value called _deliciousness_ , as follows:    * The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.   * The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.   * The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.  Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.   There are X \times Y \times Z such ways to choose three cakes.   We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.   Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Submission attempts (in order):
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()))

for cakes in A, B, C:
    cakes.sort(reverse=True)

cake_values = []
for i in range(len(A)):
    if i + 1 > K:
        break
    for j in range(len(B)):
        if (i + 1) * (j + 1) > K:
            break
        for k in range(len(C)):
            if (i + 1) * (j + 1) * (k + 1) > K:
                break
            cake_values.append(A[i] + B[j] + C[k])
cake_values.sort(reverse=True)
print(cake_values[:K])


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 = sorted(A, reverse=True)[:K]
B = sorted(B, reverse=True)[:K]
C = sorted(C, reverse=True)[:K]

ab_cake_values = sorted([a + b for a in A for b in B], reverse=True)
cake_values = sorted([ab + c for ab in ab_cake_values for c in C], reverse=True)
print(cake_values[:K])


from heapq import heappush, heappop

X, Y, Z, K = map(int, input().split())
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)

h = []
minus_value = -(A[0] + B[0] + C[0])
heappush(h, (minus_value, 0, 0, 0))
searched = set()
cnt = 0
while cnt < K:
    minus_value, ia, ib, ic = heappop(h)
    if (ia, ib, ic) in searched:
        continue
    cnt += 1
    searched.add((ia, ib, ic))
    print(-minus_value)
    if ia < X - 1:
        heappush(h, (minus_value + A[ia] - A[ia + 1], ia + 1, ib, ic))
    if ib < Y - 1:
        heappush(h, (minus_value + B[ib] - B[ib + 1], ia, ib + 1, ic))
    if ic < Z - 1:
        heappush(h, (minus_value + C[ic] - C[ic + 1], ia, ib, ic + 1))


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cake has an integer value called _deliciousness_ , as follows:    * The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.   * The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.   * The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.  Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.   There are X \times Y \times Z such ways to choose three cakes.   We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.   Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Submission attempts (in order):
X, Y, Z, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

A_list.sort(reverse=True)
B_list.sort(reverse=True)
C_list.sort(reverse=True)

F_list = []
for i in range(1, X+1):
  if i > K:
    break
  for j in range(1, Y+1):
    if i*j > K:
      break
    for k in range(1, Z+1):
      if i*j*k > K:
        break
      F_list.append(A_list[i]+B_list[j]+C_list[k])

F_list.sort(reverse=True)

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

X, Y, Z, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

A_list.sort(reverse=True)
B_list.sort(reverse=True)
C_list.sort(reverse=True)

F_list = []
for i in range(1, X+1):
  if i > K:
    break
  for j in range(1, Y+1):
    if i*j > K:
      break
    for k in range(1, Z+1):
      if i*j*k > K:
        break
      F_list.append(A_list[i-1]+B_list[j-1]+C_list[k-1])

F_list.sort(reverse=True)

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

Verdicts: Runtime Error

Accepted
Problem: The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cake has an integer value called _deliciousness_ , as follows:    * The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.   * The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.   * The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.  Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.   There are X \times Y \times Z such ways to choose three cakes.   We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.   Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Submission attempts (in order):
x,y,z,k=map(int,input().split())
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)
l=[]
for i in range(x):
  if i+1>k:
    break
  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
      l.append(a[i]+b[j]+c[k])
l.sort(reverse=True)
for i in l[:k]:
  print(i)

x,y,z,k=map(int,input().split())
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)
l=[]
for i in range(x):
  if i+1>k:
    break
  for j in range(y):
    if (i+1)*(j+1)>k:
      break
    for h in range(z):
      if (i+1)*(j+1)*(h+1)>k:
        break
      l.append(a[i]+b[j]+c[h])
l=sorted(l,reverse=True)
for i in l[:k]:
  print(i)

Verdicts: Wrong Answer

Accepted
Problem: The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cake has an integer value called _deliciousness_ , as follows:    * The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.   * The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.   * The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.  Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.   There are X \times Y \times Z such ways to choose three cakes.   We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.   Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Submission attempts (in order):
 

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    # N = int(input())
    X, Y, Z, K = 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()] 
    
    
    # x = [0] * N
    
    
    #   t[i], x[i], y[i] = map(int, input().split())
  else:
    A = [1,10,100]
    B = [2,20,200]
    C = [1,10,100]
    X = len(A)
    Y = len(B)
    Z = len(C)
    K = 5

  ans = []
  # Processing
  A.sort(reverse=True)
  B.sort(reverse=True)
  C.sort(reverse=True)
      
  for i in A:
    if i >= A[min(K,X)-1]:
      for j in B:
        if j >= B[min(K,Y)-1] :
          for k in C:
            if k >= C[min(K,Z)-1]:
              ans.append(i+j+k)
            else:
              break
        else:
          break
    else:
      break
    
  ans.sort(reverse=True)
  if 'get_ipython' in globals(): 
    print(ans)

  for i in range(0,K):
    print(ans[i])      

main()

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    X, Y, Z, K = (int(i) for i in 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()] 
  else:
    A = [1,10,100]
    B = [2,20,200]
    C = [1,10,100]
    #A = [4,6]
    #B = [1,5]
    #C = [3,8]
    X = len(A)
    Y = len(B)
    Z = len(C)
    K = 5
    #K = 8

  # Processing
  AB = []
  A.sort(reverse=True)
  B.sort(reverse=True)
  for i in A[0:K]:
    for j in B[0:K]:
      AB.append(i+j)
  
  AB.sort(reverse=True)
  
  ABC = []
  C.sort(reverse=True)
  
  for i in AB[0:K]:
    for j in C[0:K]:
      ABC.append(i+j)  
  
  ABC.sort(reverse=True)

  for i in ABC[0:K]:
    print(i)      

main()

Verdicts: Runtime Error

Accepted
Problem: The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cake has an integer value called _deliciousness_ , as follows:    * The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.   * The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.   * The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.  Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.   There are X \times Y \times Z such ways to choose three cakes.   We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.   Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Submission attempts (in order):
x, y, z, k = map(int, input().split())

cakes_x = list(map(int, input().split()))
cakes_y = list(map(int, input().split()))
cakes_z = list(map(int, input().split()))

cakes_x.sort(reverse=True)
cakes_y.sort(reverse=True)
cakes_z.sort(reverse=True)

print(cakes_x)
print(cakes_y)
print(cakes_z)

scores = []
for cake_x in cakes_x:
    for cake_y in cakes_y:
        for cake_z in cakes_z:
            scores.append(cake_x + cake_y + cake_z)

scores.sort(reverse=True)

for i in range(k):
    print(scores[i])

import heapq

X, Y, Z, K = map(int, input().split())
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)

Q = []
heapq.heappush(Q, (-1*(A[0]+B[0]+C[0]), 0, 0, 0))
registered = set()
registered.add((0, 0, 0))
for _ in range(K):
    s, ai, bi, ci = heapq.heappop(Q)
    print(-s)

    if ai+1 < X and (ai+1, bi, ci) not in registered:
        heapq.heappush(Q, (-1*(A[ai+1]+B[bi]+C[ci]), ai+1, bi, ci))
        registered.add((ai+1, bi, ci))
    if bi+1 < Y and (ai, bi+1, ci) not in registered:
        heapq.heappush(Q, (-1*(A[ai]+B[bi+1]+C[ci]), ai, bi+1, ci))
        registered.add((ai, bi+1, ci))
    if ci+1 < Z and (ai, bi, ci+1) not in registered:
        heapq.heappush(Q, (-1*(A[ai]+B[bi]+C[ci+1]), ai, bi, ci+1))
        registered.add((ai, bi, ci+1))


Verdicts: Wrong Answer

Accepted
Problem: The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cake has an integer value called _deliciousness_ , as follows:    * The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.   * The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.   * The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.  Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.   There are X \times Y \times Z such ways to choose three cakes.   We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.   Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Submission attempts (in order):
from heapq import heappush, heappop
X, Y, Z, K, *L = map(int, open('0').read().split())
A = L[:X]
B = L[X:X+Y]
C = L[X+Y:]
ab = []
for i in range(X):
  for j in range(Y):
    ab += [A[i]+B[j]]
ab.sort(reverse=True)
ls = []
for i in range(Z):
  heappush(ls,(-ab[0]-C[i],j,0))
for i in range(K):
  m, j, cnt = heappop(ls)
  print(-m)
  if cnt<X*Y:
    heappush(ls,(-ab[cnt+1]-C[j],j,cnt+1))

import numpy as np
X, Y, Z, K, *L = map(int, open('0').read().split())
A = L[:X]
B = L[X:X+Y]
C = L[X+Y:]
ab = []
for i in range(X):
  for j in range(Y):
    ab += [A[i]+B[j]]
ab.sort()
ab = np.array(ab)
c = np.array(C)
l = -1
r = 10**30+1
M = X*Y*Z
for k in range(K):
  l = -1
  r = 10**30+1
  M = X*Y*Z
  while l+1<r:
    n = (l+r)//2
    d = n-c
    m = np.searchsorted(ab,d).sum()
    if M-m>k:
      l = n
    else:
      r = n
  print(l)

from heapq import heappush, heappop
X, Y, Z, K, *L = map(int, open(0).read().split())
A = L[:X]
B = L[X:X+Y]
C = L[X+Y:]
ab = []
for i in range(X):
  for j in range(Y):
    ab += [A[i]+B[j]]
ab.sort(reverse=True)
ls = []
for i in range(Z):
  heappush(ls,(-ab[0]-C[i],j,0))
for i in range(K):
  m, j, cnt = heappop(ls)
  print(-m)
  if cnt<X*Y:
    heappush(ls,(-ab[cnt+1]-C[j],j,cnt+1))

import numpy as np
X, Y, Z, K, *L = map(int, open('0').read().split())
A = L[:X]
B = L[X:X+Y]
C = L[X+Y:]
ab = []
for i in range(X):
  for j in range(Y):
    ab += [A[i]+B[j]]
ab.sort()
ab = np.array(ab)
c = np.array(C)
l = -1
r = 3*10**10+1
M = X*Y*Z
for k in range(K):
  l = -1
  M = X*Y*Z
  while l+1<r:
    n = (l+r)//2
    d = n-c
    m = np.searchsorted(ab,d).sum()
    if M-m>k:
      l = n
    else:
      r = n
  print(l)
  r = l+1


from heapq import heappush, heappop
X, Y, Z, K, *L = map(int, open(0).read().split())
A = L[:X]
B = L[X:X+Y]
C = L[X+Y:]
ab = []
for i in range(X):
  for j in range(Y):
    ab += [A[i]+B[j]]
ab.sort(reverse=True)
ls = []
for i in range(Z):
  heappush(ls,(-ab[0]-C[i],i,0))
for i in range(K):
  m, j, cnt = heappop(ls)
  print(-m)
  if cnt+1<X*Y:
    heappush(ls,(-ab[cnt+1]-C[j],j,cnt+1))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cake has an integer value called _deliciousness_ , as follows:    * The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.   * The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.   * The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.  Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.   There are X \times Y \times Z such ways to choose three cakes.   We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.   Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Submission attempts (in order):
X, Y, Z, K = list(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)

candidates = []
for i in range(len(A)-1):
    for j in range(len(B)-1):
        for k in range(len(C)-1):
            if (i+1) * (j+1) * (k+1) <= K:
                candidates.append(A[i] + B[j] + C[k])
            else:
                break
candidates.sort(reverse=True)

for c in candidates[:K]:
    print(c)

from itertools import product
 
X, Y, Z, K = list(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)
 
candidates = []
for i, j, k in product(range(len(A)-1), range(len(B)-1), range(len(C)-1)):
    if (i+1) * (j+1) * (k+1) <= K:
        candidates.append(A[i] + B[j] + C[k])
candidates.sort(reverse=True)
 
for c in candidates[:K]:
    print(c)

import heapq
 
X, Y, Z, K = list(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)
 
q = []
heapq.heapify(q)
heapq.heappush(q, (-(A[0] + B[0] + C[0]), 0, 0, 0))  
 
for _ in range(K):
    m, i, j, k = heapq.heappop(q)
    print(-m)
    if i + 1 < X:
        s = (-(A[i+1] + B[j] + C[k]), i+1, j, k) 
        if s not in q:
            heapq.heappush(q, s)
    if j + 1 < Y:
        s = (-(A[i] + B[j+1] + C[k]), i, j+1, k) 
        if s not in q:
            heapq.heappush(q, s)
    if k + 1 < Z:
        s = (-(A[i] + B[j] + C[k+1]), i, j, k+1) 
        if s not in q:
            heapq.heappush(q, s)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cake has an integer value called _deliciousness_ , as follows:    * The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.   * The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.   * The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.  Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.   There are X \times Y \times Z such ways to choose three cakes.   We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.   Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Submission attempts (in order):
X, Y, Z, K  = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

l = []
for a in A:
    for b in B:
        l.append(a+b)
l = sorted(l, reverse = True)[:K]

ans = []
for c in C:
    for k in l:
        ans.append(c + k)
        
ans = sorted(ans, reverse = True)
print(*ans[:K], seq="\n")

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

l = []
for a in A:
    for b in B:
        l.append(a+b)
l = sorted(l, reverse = True)[:K]

ans = []
for c in C:
    for k in l:
        ans.append(c + k)
        
ans = sorted(ans, reverse = True)
print(*ans[:K], sep="\n")

Verdicts: Runtime Error

Accepted