Problem:


Score: 400 points

Problem Statement

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.

Constraints

1 \leq X \leq 1 \ 000

1 \leq Y \leq 1 \ 000

1 \leq Z \leq 1 \ 000

1 \leq K \leq \min(3 \ 000, X \times Y \times Z)

1 \leq A_i \leq 10 \ 000 \ 000 \ 000

1 \leq B_i \leq 10 \ 000 \ 000 \ 000

1 \leq C_i \leq 10 \ 000 \ 000 \ 000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z

Output

Print K lines. The i-th line should contain the i-th value stated in the problem statement.

Sample Input 1

2 2 2 8
4 6
1 5
3 8

Sample Output 1

19
17
15
14
13
12
10
8

There are 2 \times 2 \times 2 = 8 ways to choose three cakes, as shown below in descending order of the sum of the deliciousness of the cakes:

(A_2, B_2, C_2): 6 + 5 + 8 = 19

(A_1, B_2, C_2): 4 + 5 + 8 = 17

(A_2, B_1, C_2): 6 + 1 + 8 = 15

(A_2, B_2, C_1): 6 + 5 + 3 = 14

(A_1, B_1, C_2): 4 + 1 + 8 = 13

(A_1, B_2, C_1): 4 + 5 + 3 = 12

(A_2, B_1, C_1): 6 + 1 + 3 = 10

(A_1, B_1, C_1): 4 + 1 + 3 = 8

Sample Input 2

3 3 3 5
1 10 100
2 20 200
1 10 100

Sample Output 2

400
310
310
301
301

There may be multiple combinations of cakes with the same sum of the deliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and the sum of A_3, B_3, C_1 are both 301.
However, they are different ways of choosing cakes, so 301 occurs twice in the output.

Sample Input 3

10 10 10 20
7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488
1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338
4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736

Sample Output 3

23379871545
22444657051
22302177772
22095691512
21667941469
21366963278
21287912315
21279176669
21160477018
21085311041
21059876163
21017997739
20703329561
20702387965
20590247696
20383761436
20343962175
20254073196
20210218542
20150096547

Note that the input or output may not fit into a 32-bit integer type.



Sample input:
2 2 2 8
4 6
1 5
3 8


Sample output:
19
17
15
14
13
12
10
8

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

ab = []
res = []
x, y, z, k = na()
a_li = na()
b_li = na()
c_li = na()
for a in a_li:
    for b in b_li:
        ab.append((a * b))
list.sort(ab, reverse=True)
list.sort(c_li, reverse=True)
for a_b in ab:
    for c in c_li:
        res.append(a_b * c)
for num in sorted(res,reverse=True)[:k]:
    print(num)

Submission status: Wrong Answer

Solution code:
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)

result = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i + 1) * (j + 1) * (k + 1) <= K:
                result.append(A[i] + B[j] + C[k])
            else:
                break
result.sort()
for rs in result[:K]:
    print(rs)

Submission status: Wrong Answer

Solution code:
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(map(int, input().split()))[::-1]

l=[]
u=0
for i in sorted([s+t for t in B for s in A])[::-1][:K]:
    for r in C:
        l.append(r+i)
for i in sorted(l)[::-1]:
    print(i)

Submission status: Wrong Answer

Solution code:
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()))

li = []
for i in range(X):
    for j in range(Y):
        li.append(A[i] + B[j])
C.reverse()
li.reverse()

for i in range(len(li)):
    if K < i:
        break
    else:
        for j in range(Z):
            print(li[i] + C[j])

Submission status: Wrong Answer

Solution code:
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()))
c.sort(reverse=True)

e = [a_i + b_j for b_j in b for a_i in a]
e.sort(reverse=True)

ans = [e_i + c_j for c_j in c[:k] for e_i in e[:k]]
ans.sort(reverse=True)

print(ans[:k])

Submission status: Wrong Answer

Solution code:
from functools import reduce

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]
    ans = []
    X, Y, Z, K = (int(_) for _ in input().split())
    A = list(int(_) for _ in input().split())
    A.sort()
    B = list(int(_) for _ in input().split())
    B.sort()
    C = list(int(_) for _ in input().split())
    C.sort()
    for a in A:
        for b in B:
            for c in range(3001):
                ans.append(a + b + c)
    ans.sort()
    ans = ans[::-1]
    ans = ans[:K]
    print('\n'.join(map(str,ans)))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#実験をしっかりとしよう
X,Y,Z,K = (int(_) for _ in input().split())
A = (int(_) for _ in input().split())
B = (int(_) for _ in input().split())
C = (int(_) for _ in input().split())
#この手の問題はまずsortする(今回は大きい順の方がすっきり)
A = sorted(A)
B = sorted(B)
C = sorted(C)
#総和は変わらないので残ったやつの累積和で考えてみる。
#1000*1000なら全列挙できるそのうち3000個を取り除いて、3の1000個を
#それに組み合わせて全探索する。(2重forかな)
AB = []

for i in range(X):
    for j in range(Y):
        AB.append(A[i]+B[i])
AB = sorted(AB)
AB.reverse()
AB = AB[:3000]

ABC = []
for i in range(len(AB)):
    for j in range(Z):
        ABC.append(AB[i]+C[j])

ABC = sorted(ABC)
ABC.reverse()
for i in range(len(ABC)):
    print(ABC[i])

Submission status: Wrong Answer

Solution code:
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()))

e = [a_i + b_j for b_j in b for a_i in a]
e.sort(reverse=True)

ans = [e_i + c_j for c_j in c[:k] for e_i in e[:k]]
ans.sort(reverse=True)

print(ans[:k])

Submission status: Wrong Answer

Solution code:
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()))

import itertools
val_list = []


A_list = sorted(A_list, reverse=True)
B_list = sorted(B_list, reverse=True)
C_list = sorted(C_list, reverse=True)
for a, b, c in itertools.product(range(len(A_list)), range(len(B_list)), range(len(C_list))):
    if (a+1) * (b+1) * (c+1) > K:
        continue
    val_list.append(A_list[a] + B_list[b] + C_list[c])

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

Submission status: Wrong Answer

Solution code:
x, y, z, k = map(int, input().split())
A = list(int(i) for i in input().split())
B = list(int(i) for i in input().split())
C = list(int(i) for i in input().split())

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

ABC = []

for a in range(len(A)):
    for b in range(len(B)):
        if (a+1)*(b+1) > k:
            break
        for c in range(len(C)):
            if (a+1)*(b+1)*(c+1) > k:
                break
            ABC.append(A[a]+B[b]+C[c])

ABC.sort()
ABC = ABC[::-1]

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

Submission status: Wrong Answer

Solution code:
import math

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

Ai= sorted(A, reverse=True)
Bi= sorted(B, reverse=True)
Ci= sorted(C, reverse=True)

def su(a,b,c):
	return(Ai[a]+Bi[b]+Ci[c])

a=0
b=0
c=0

pq=[[su(a,b,c),a,b,c]]

dl=0
for i in range(k):
	dl=pq.index(max(pq))
	res=pq.pop(dl)
	print(res[0])
	#print(pq)
	
	a=res[1]
	b=res[2]
	c=res[3]
	if a+1<=x-1:
		pq.append([su(a+1,b,c),a+1,b,c])
	if b+1<=y-1:
		pq.append([su(a,b+1,c),a,b+1,c])
	if c+1<=z-1:
		pq.append([su(a,b,c+1),a,b,c+1])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

ABC = []

for x in range(X):
    for y in range(Y):
        if (x + 1) * (y + 1) > K:
            break
        for z in range(Z):
            if (x + 1) * (y + 1) + (z + 1) > K:
                break
            ABC.append(A[x] + B[y] + C[z])

ABC = sorted(ABC, reverse=True)

ABC = ABC[:K]
ABC = [str(abc) for abc in ABC]

print("\n".join(ABC))

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

ab = []
res = []
x, y, z, k = na()
a_li = na()
b_li = na()
c_li = na()
for a in a_li:
    for b in b_li:
        ab.append((a * b))
list.sort(ab, reverse=True)
list.sort(c_li, reverse=True)
for a_b in ab:
    for c in c_li:
        res.append(a_b * c)
for num in sorted(res,reverse=True)[-k:]:
    print(num)

Submission status: Wrong Answer

Solution code:
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()))

li = []
for i in range(X):
    for j in range(Y):
        li.append(A[i] + B[j])
C.reverse()
li.reverse()

for i in range(len(li)):
    for j in range(Z):
        print(li[i] + C[j])

Submission status: Wrong Answer

Solution code:
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()))

e = [a_i + b_j for b_j in b for a_i in a]
e = sorted(e, reverse=True)

ans = [e_i + c_j for c_j in c[:k] for e_i in e[:k]]
ans.sort(reverse=True)

print(ans[:k])

Submission status: Wrong Answer

Solution code:
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)

result = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i + 1) * (j + 1) * (k + 1) <= K:
                result.append(A[i] + B[j] + C[k])
            else:
                break
result.sort()
for rs in result:
    print(rs)

Submission status: Wrong Answer

Solution code:
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)


while True:
    if len(A) * len(B) * len(C) < 6000:
        break

    if len(A) == 1:
        if B[-1] <= C[-1]:
            B.pop()
            continue
        else:
            C.pop()
            continue
    if len(B) == 1:
        if A[-1] <= C[-1]:
            A.pop()
            continue
        else:
            C.pop()
            continue
    if len(C) == 1:
        if A[-1] <= B[-1]:
            A.pop()
            continue
        else:
            B.pop()
            continue
    if A[-1] <= B[-1] and A[-1] <= C[-1]:
        A.pop()
        continue
    if B[-1] <= A[-1] and B[-1] <= C[-1]:
        B.pop()
        continue
    if C[-1] <= A[-1] and C[-1] <= B[-1]:
        C.pop()
        continue
    

r = []

for a in A:
    for b in B:
        for c in C:
            r.append(a + b + c)

r.sort(reverse=True)

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

Submission status: Wrong Answer

Solution code:
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])

Submission status: Wrong Answer

Solution code:
import math

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

Ai= sorted(A, reverse=True)
Bi= sorted(B, reverse=True)
Ci= sorted(C, reverse=True)

def su(a,b,c):
	return(Ai[a]+Bi[b]+Ci[c])

a=0
b=0
c=0

pq=[[su(a,b,c),a,b,c]]

dl=0
for i in range(k):
	dl=pq.index(max(pq))
	res=pq.pop(dl)
	print(res[0])
	print(pq)
	
	a=res[1]
	b=res[2]
	c=res[3]
	if a+1<=x-1:
		pq.append([su(a+1,b,c),a+1,b,c])
	if b+1<=y-1:
		pq.append([su(a,b+1,c),a,b+1,c])
	if c+1<=z-1:
		pq.append([su(a,b,c+1),a,b,c+1])

Submission status: Wrong Answer

Solution code:
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()]

a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)

finish = [[a[0]+b[0]+c[0],0,0,0]]

for i in range(k):
  finish.sort(reverse = True)
  print(finish[0][0])
  a_i = finish[0][1]
  b_i = finish[0][2]
  c_i = finish[0][3]
  if a_i != x-1:
    tmp = [a[a_i+1]+b[b_i]+c[c_i],a_i+1,b_i,c_i]
    if tmp not in finish:
      finish.append(tmp)
  if b_i != y-1:
    tmp = [a[a_i]+b[b_i+1]+c[c_i],a_i,b_i+1,c_i]
    if tmp not in finish:
      finish.append(tmp)
  if c_i != z-1:
    tmp = [a[a_i]+b[b_i]+c[c_i+1],a_i,b_i,c_i+1]
    if tmp not in finish:
      finish.append(tmp)
  del finish[0]

Submission status: Wrong Answer

Solution code:
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)


while True:
    if len(A) * len(B) * len(C) < 6000:
        break

    if len(A) == 1:
        if B[-1] <= C[-1]:
            B.pop()
            continue
        else:
            C.pop()
            continue
    if len(B) == 1:
        if A[-1] <= C[-1]:
            A.pop()
            continue
        else:
            C.pop()
            continue
    if len(C) == 1:
        if A[-1] <= B[-1]:
            A.pop()
            continue
        else:
            B.pop()
            continue
    if A[-1] <= B[-1] and A[-1] <= C[-1]:
        A.pop()
        continue
    if B[-1] <= A[-1] and B[-1] <= C[-1]:
        B.pop()
        continue
    if C[-1] <= A[-1] and C[-1] <= B[-1]:
        B.pop()
        continue

r = []

for a in A:
    for b in B:
        for c in C:
            r.append(a + b + c)

r.sort(reverse=True)

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

Submission status: Wrong Answer

Solution code:
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()))

import itertools
val_list = []

a_max = min(len(A_list), K)
b_max = min(len(B_list), K)
c_max = min(len(C_list), K)

A_list = sorted(A_list, reverse=True)
B_list = sorted(B_list, reverse=True)
C_list = sorted(C_list, reverse=True)
for a, b, c in itertools.product(range(len(A_list[:a_max])), range(len(B_list[:b_max])), range(len(C_list[:c_max]))):
    if (a+1) * (b+1) * (c+1) > K:
        continue
    val_list.append(A_list[a] + B_list[b] + C_list[c])

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

Submission status: Wrong Answer

Solution code:
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()))

e = [a_i + b_j for b_j in b for a_i in a]
e = sorted(e, reverse=True)[:k]

ans = [e_i + c_j for c_j in c for e_i in e]
ans.sort(reverse=True)

print(ans[:k])

Submission status: Wrong Answer

Solution code:
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)
ab = []
for i in range(x):
  for j in range(y):
    ab.append(a[i]+b[j])
ab.sort(reverse=True)
ab = ab[0:k+1]
abc = []
for i in ab:
  for j in c:
    abc.append(i+j)
abc.sort(reverse=True)
abc = abc[0:k+1]
for i in abc:
  print(i)

Submission status: Wrong Answer

Solution code:
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(map(int, input().split()))[::-1]

l=[]
u=0
for i in sorted([s+t for t in B for s in A])[::-1]:
    for r in C:
        l.append(r+i)
        u+=1
        if u==K:
            for y in sorted(l)[::-1]:
                print(y)
            exit()

Submission status: Wrong Answer

Solution code:
import collections

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

a.sort()
b.sort()
c.sort()

a15 = a[-15:]
b15 = b[-15:]
c15 = c[-15:]

oisi = []
for aa in a15:
    for bb in b15:
        for cc in c:
#            print(aa,bb,cc)
            oisi.append(aa+bb+cc)

for bb in b15:
    for cc in c15:
        for aa in a[:-15]:
            oisi.append(aa+bb+cc)

for cc in c15:
    for aa in a15:
        for bb in b[:-15]:
            oisi.append(aa+bb+cc)

#print(len(oisi))
#print(oisi)
oisi.sort(reverse=True)

for j in oisi[:k]:
    print(j)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import sys
input = sys.stdin.readline

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

bimi = []
for a in range(X):
        for b in range(Y):
                bimi.append(A[a] + B[b])

bimi = sorted(bimi, reverse=True)[:K]
ans = []
for x in bimi:
        for c in range(Z):
                ans.append(x + C[c])

ans.sort(reverse=True)

for _ in range(K):
        print(ans)

Submission status: Wrong Answer

Solution code:
23379871545
22444657051
22302177772
22095691512
21667941469
21366963278
21287912315
21279176669
21160477018
21085311041
21059876163
21017997739
20703329561
20702387965
20590247696
20383761436
20343962175
20254073196
20210218542
20150096547

Submission status: Wrong Answer

Solution code:
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()))

e = [a_i + b_j for b_j in b for a_i in a]
e = sorted(e, reverse=True)

ans = [e_i + c_j for c_j in c for e_i in e]
ans.sort(reverse=True)

print(ans[:k])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

AB = []

for a in A:
    for b in B:
        AB.append(a + b)

AB = sorted(AB, reverse=True)

K = K if K < len(AB) else len(AB)
AB = AB[:K]

ABC = []
for ab in AB:
    for c in C:
        ABC.append(ab + c)

ABC = sorted(ABC, reverse=True)
ABC = ABC[:K]
ABC = [str(abc) for abc in ABC]

print("\n".join(ABC))

Submission status: Wrong Answer

Solution code:
x, y, z, k = map(int, input().split())
a, b, c = [list(map(int, input().split())) for _ in range(3)]
deli = []
for i in range(min(x, k)):
    for j in range(min(y, k)):
        for l in range(min(z, k)):
            if i*j*l <= k:
                deli.append(a[i]+b[j]+c[l])
deli.sort(reverse = True)
for i, elem in enumerate(deli):
    if i == k:
        break
    print(elem)

Submission status: Wrong Answer

Solution code:
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])

Submission status: Wrong Answer

Solution code:
import math

listX = []
listY = []
listZ = []
x,y,z,k=input().split()
x=int(x)
y=int(y)
z=int(z)
k=int(k)

listX =map(int,input().split())
listX = [int(i) for i in listX]
#listX.sort()

listY =map(int,input().split())
listY = [int(i) for i in listY]
#listY.sort()

listZ =map(int,input().split())
listZ = [int(i) for i in listZ]
#listZ.sort()

#ak=pow(k,1/3)
#ak=math.ceil(ak)
listN=[]
for i in range(x):
    for j in range(y):
        for l in range(z):
            listN.append(listX[i]*listY[j]*listZ[l])

Submission status: Wrong Answer

Solution code:
import collections

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

a.sort()
b.sort()
c.sort()

a15 = a[-15:]
b15 = b[-15:]
c15 = c[-15:]

oisi = []
for aa in a15:
    for bb in b15:
        for cc in c:
#            print(aa,bb,cc)
            oisi.append(aa+bb+cc)
for bb in b15:
    for cc in c15:
        if len(a)> 15:
            for aa in a[:-15]:
                oisi.append(aa+bb+cc)
        else:
            break
        
for cc in c15:
    for aa in a15:
        if len(b)> 15:
            for bb in b[:-15]:
                oisi.append(aa+bb+cc)
        else:
            break


#print(oisi)
oisi.sort(reverse=True)

for j in oisi[:k]:
    print(j)

Submission status: Wrong Answer

Solution code:
import bisect

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)
sum_count = []
k = 0
for x in range(X):
    if k==1:
        break
    for y in range(Y):
        if k==1:
            break
        for z in range(Z):
            if (x+1)*(y+1)*(z+1) > K:
                k=1
                break
            sum_count.append(A[x]+B[y]+C[z])

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

Submission status: Wrong Answer

Solution code:
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])

Submission status: Wrong Answer

Solution code:
import sys
# import bisect
# import math
# import itertools
# import numpy as np
# import collections

"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e, p = range, enumerate, print
    ip = IP()
    id = Idea()
    mod = 10 ** 9 + 7

    """この下から書いてね"""
    x, y, z, k = ip.IL()
    a = ip.IL()
    b = ip.IL()
    c = ip.IL()

    id.S(a, 1)
    id.S(b, 1)
    id.S(c, 1)

    ans = []

    for i in r(x):
        if i > k:
            break
        for j in r(y):
            if i * j > k:
                break
            for o in r(z):
                if i * j * o > k:
                    break
                ans += [a[i] + b[i] + c[i]]

    id.S(ans, 1)
    for ans_p in ans:
        p(ans_p)


main()

Submission status: Wrong Answer

Solution code:
import heapq
X, Y, Z, K = map(int, input().split())
A = sorted(map(int, input().split()), reverse=True)
B = sorted(map(int, input().split()), reverse=True)
C = sorted(map(int, input().split()), reverse=True)
que = [(-A[0] - B[0] - C[0], 0, 0, 0)]
r = -1
while K:
    s, i, j, k = heapq.heappop(que)
    if i + 1 < X:
        heapq.heappush(que, (-A[i + 1] - B[j] - C[k], i + 1, j, k))
    if j + 1 < Y:
        heapq.heappush(que, (-A[i] - B[j + 1] - C[k], i, j + 1, k))
    if k + 1 < Z:
        heapq.heappush(que, (-A[i] - B[j] - C[k + 1], i, j, k + 1))
    s = -s
    if r != s:
        print(s)
        r = s
        K -= 1

Submission status: Wrong Answer

Solution code:
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)
nA = A[0]
nB = B[0]
nC = C[0]
a, b, c = [], [], []
for i in A:
    a.append(nA-i)
for i in B:
    b.append(nB-i)
for i in C:
    c.append(nC-i)
if K == 1:
    print(nA+nB+nC)
else:
    ls = []
    d, e, f = 0, 0, 0
    while (d+1)*(e+1)*(f+1) < K:
        if d+1 == len(a):
            na = float('inf')
        else:
            na = a[d]
        if e+1 == len(b):
            nb = float('inf')
        else:
            nb = b[e]
        if f+1 == len(c):
            nc = float('inf')
        else:
            nc = c[f]
        if min(na, nb, nc) == na:
            d += 1
        if min(na, nb, nc) == nb:
            e += 1
        if min(na, nb, nc) == nc:
            f += 1
    for i in a[:min(X,d+5)]:
        for j in b[:min(Y, e+5)]:
            for k in c[:min(Z, f+5)]:
                ls.append(i+j+k)
    ls.sort()
    for i in range(K):
        print(nA+nB+nC-ls[i])

Submission status: Wrong Answer

Solution code:
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])

Submission status: Wrong Answer

Solution code:
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)
nA = A[0]
nB = B[0]
nC = C[0]
a, b, c = [], [], []
for i in A:
    a.append(nA-i)
for i in B:
    b.append(nB-i)
for i in C:
    c.append(nC-i)
ls = []
d, e, f = 0, 0, 0
while (d+1)*(e+1)*(f+1) < K:
    if d+1 == len(a):
        na = float('inf')
    else:
        na = a[d]
    if e+1 == len(b):
        nb = float('inf')
    else:
        nb = b[e]
    if f+1 == len(c):
        nc = float('inf')
    else:
        nc = c[f]
    if min(na, nb, nc) == na:
        d += 1
    if min(na, nb, nc) == nb:
        e += 1
    if min(na, nb, nc) == nc:
        f += 1
for i in a[:min(X,d+5)]:
    for j in b[:min(Y, e+5)]:
        for k in c[:min(Z, f+5)]:
            ls.append(i+j+k)
ls.sort()
for i in range(K):
    print(nA+nB+nC-ls[i])