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):
line = input().split(sep=" ")
x = int(line[0])
y = int(line[1])
z = int(line[2])
in_k = int(line[3])


in_x = sorted(list(map(int,input().split(sep=" "))),reverse=True)
in_y = sorted(list(map(int,input().split(sep=" "))),reverse=True)
in_z = sorted(list(map(int,input().split(sep=" "))),reverse=True)

ans_arr = []

if(x > in_k ): x =in_k
if(y > in_k ): y =in_k
if(z > in_k ): z =in_k

print(x)
for i in range(x):
	for j in range(y):
		if((i+1) * (j+1) > in_k) break
		for k in range(z):
			ans_arr.append(in_x[i] + in_y[j] + in_z[k])
			if((i+1) * (j+1) * (k+1) > in_k) break

ans_arr = sorted(ans_arr,reverse=True)

for i in range(in_k):
	print(ans_arr[i])


line = input().split(sep=" ")
x = int(line[0])
y = int(line[1])
z = int(line[2])
in_k = int(line[3])


in_x = sorted(list(map(int,input().split(sep=" "))),reverse=True)
in_y = sorted(list(map(int,input().split(sep=" "))),reverse=True)
in_z = sorted(list(map(int,input().split(sep=" "))),reverse=True)

ans_arr = []

if(x > in_k ): x =in_k
if(y > in_k ): y =in_k
if(z > in_k ): z =in_k

print(x)
for i in range(x):
	for j in range(y):
		for k in range(z):
			ans_arr.append(in_x[i] + in_y[j] + in_z[k])

ans_arr = sorted(ans_arr,reverse=True)

for i in range(in_k):
	print(ans_arr[i])


line = input().split(sep=" ")
x = int(line[0])
y = int(line[1])
z = int(line[2])
in_k = int(line[3])


in_x = sorted(list(map(int,input().split(sep=" "))),reverse=True)
in_y = sorted(list(map(int,input().split(sep=" "))),reverse=True)
in_z = sorted(list(map(int,input().split(sep=" "))),reverse=True)

ans_arr = []

if(x > in_k ): x =in_k
if(y > in_k ): y =in_k
if(z > in_k ): z =in_k

print(x)
for i in range(x):
	for j in range(y):
		if((i+1) * (j+1) > in_k): break
		for k in range(z):
			ans_arr.append(in_x[i] + in_y[j] + in_z[k])
			if((i+1) * (j+1) * (k+1) > in_k): break

ans_arr = sorted(ans_arr,reverse=True)

for i in range(in_k):
	print(ans_arr[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())) 


A = sorted(A, key = lambda x:-x)
B = sorted(B, key = lambda x:-x)
C = sorted(C, key = lambda x:-x)

AB = [0] * (X * Y)

ABC = []

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
            ABC.append(A[i] + B[j] + C[k])

ABC = sorted(ABC, key = lambda x:-x)
for i in range(0, K):
    print(ABC[i])

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted