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):
k = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
z = [int(i) for i in input().split()]

x.sort(reverse=True)
if len(x)>k[3]:
  x = x[0:k[3]+1]

y.sort(reverse=True)
if len(y)>k[3]:
  y = y[0:k[3]+1]

z.sort(reverse=True)
if len(z)>k[3]:
  z = z[0:k[3]+1]

e = []

for i in x:
  for j in y:
    e.append(i+j)

e.sort()
g = []
for i in range(k[3]):
  g.append(e[len(e)-i-1])

f = []

for i in g:
  for j in z:
    f.append(i+j)

f.sort()

for i in range(k[3]):
  print(f[len(f)-i-1])


k = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
z = [int(i) for i in input().split()]

x.sort(reverse=True)
y.sort(reverse=True)
z.sort(reverse=True)

for i in len(x)
  for j in len(y)
    for l in len(z)
      if x*y*z =< k[3]:
        SUM.append(x[i+1]+y[j+1]+z[l+1])
      else:
        break

SUM.sort(reverse=True)

for i in range(k[3])
  print(SUM[i])


k = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
z = [int(i) for i in input().split()]

x.sort(reverse=True)
if len(x)>k[3]:
  x = x[0:k[3]+1]

y.sort(reverse=True)
if len(y)>k[3]:
  y = y[0:k[3]+1]

z.sort(reverse=True)
if len(z)>k[3]:
  z = z[0:k[3]+1]

e = []

for i in x:
  for j in y:
    e.append(i+j)

g = []
for i in range(k[3]):
  g.append(e[i])

f = []

for i in g:
  for j in z:
    f.append(i+j)

f.sort(reverse=True)

for i in range(k[3]):
  print(f[i])


k = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
z = [int(i) for i in input().split()]

e = []

for i in x:
  for j in y:
    e.append(i+j)

e.sort()
e.reverse()
print(e)
g = []
for i in range(k[3]):
  g.append(e[i])


f = []

for i in g:
  for j in z:
    f.append(i+j)

f.sort()
f.reverse()

for i in range(k[3]):
  print(f[i])


k = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
z = [int(i) for i in input().split()]

x.sort(reverse=True)
if len(x)>k[3]:
  x = x[0:k[3]]

y.sort(reverse=True)
if len(y)>k[3]:
  y = y[0:k[3]]

z.sort(reverse=True)
if len(z)>k[3]:
  z = z[0:k[3]]

e = []

for i in x:
  for j in y:
    e.append(i+j)

g = []
for i in range(k[3]):
  g.append(e[i])

f = []

for i in g:
  for j in z:
    f.append(i+j)

f.sort(reverse=True)

for i in range(k[3]):
  print(f[i])


k = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
z = [int(i) for i in input().split()]

e = []

for i in x:
  for j in y:
    e.append(i+j)

e.sort()
g = []
for i in range(k[3]):
  g.append(e[len(e)-i-1])

f = []

for i in g:
  for j in z:
    f.append(i+j)

f.sort()

for i in range(k[3]):
  print(f[len(f)-i-1])

k = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
z = [int(i) for i in input().split()]

x.sort(reverse=True)
y.sort(reverse=True)
z.sort(reverse=True)

for i in len(x)
  for j in len(y)
    for l in len(z)
      if x*y*z =< k[3]:
        SUM.append(x[i]+y[j]+z[l])
      else:
        break

SUM.sort(reverse=True)

for i in range(k[3])
  print(SUM[i])


k = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
z = [int(i) for i in input().split()]

x.sort(reverse=True)
y.sort(reverse=True)
z.sort(reverse=True)

for i in len(x):
  for j in len(y):
    for l in len(z):
      if (x+1)*(y+1)*(z+1) <= k[3]:
        SUM.append(x[i]+y[j]+z[l])
      else:
        break

SUM.sort(reverse=True)

for i in range(k[3]):
  print(SUM[i])


k = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
z = [int(i) for i in input().split()]

x.sort(reverse=True)
y.sort(reverse=True)
z.sort(reverse=True)

SUM = []

for i in range(len(x)):
  for j in range(len(y)):
    for l in range(len(z)):
      if (i+1)*(j+1)*(l+1) <= k[3]:
        SUM.append(x[i]+y[j]+z[l])
      else:
        break

SUM.sort(reverse=True)

for i in range(k[3]):
  print(SUM[i])


Verdicts: Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Accepted