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 itertools
import math

k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ab = []
for ax, bx in itertools.product(a, b):
    ab.append(ax+bx)
ab.sort(reverse=True)
s_ab = ab[0:min(math.ceil(3000//k[2]),len(ab))]

abc = []
for aby, cy in itertools.product(s_ab, c):
    abc.append(aby+cy)
abc.sort(reverse=True)
s_abc = abc[0:min(3000,len(abc))]

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

Submission status: Wrong Answer

Solution code:
import itertools

k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ab = []
for ax, bx in itertools.product(a, b):
    ab.append(ax+bx)
ab.sort(reverse=True)
s_ab = ab[0:min(3000//k[2],len(ab))]

abc = []
for aby, cy in itertools.product(s_ab, c):
    abc.append(aby+cy)
abc.sort(reverse=True)
s_abc = abc[0:min(3000,len(abc))]

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

Submission status: Wrong Answer

Solution code:
x, y, z, k = map(int,input().split())
*a, = map(int,input().split())
*b, = map(int,input().split())
*c, = map(int,input().split())
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

l1 = []
for i in a:
  for j in b:
    l1.append(i+j)
#print(l1)

l2 = []
l1.sort(reverse=True)
for l in range(len(l1[:k])):
  for m in c:
    print(l1[l]+m)

Submission status: Wrong Answer

Solution code:
def main():
    x,y,z,k = map(int,input().split())
    lia = sorted(list(map(int,input().split())))
    lib = sorted(list(map(int,input().split())))
    lic = sorted(list(map(int,input().split())))

    li2 = sorted(list(a+b for a in lia for b in lib),reverse = True)[:k]
    li3 = sorted(list(ab + c for ab in li2 for c in lic),reverse = True)

    print('\n'.join(map(str,li3)))

main()

Submission status: Wrong Answer

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

priority_queue = {}
priority_queue[(0, 0, 0)] = A[0] + B[0] + C[0]

for _ in range(K):
    # max を見つけて print + pop 
    max_value = 0
    max_key = None
    for k, v in priority_queue.items():
        if max_key is None or v > max_value:
            max_value = v
            max_key = k
    if len(priority_queue) > 0:
        print(priority_queue.pop(max_key))

    # 次の階層を追加
    try:
        priority_queue[(max_key[0]+1, max_key[1], max_key[2])] = A[max_key[0]+1] + B[max_key[1]] + C[max_key[2]]
    except IndexError:
        pass
    try:
        priority_queue[(max_key[0], max_key[1]+1, max_key[2])] = A[max_key[0]] + B[max_key[1]+1] + C[max_key[2]]
    except IndexError:
        pass
    try:
        priority_queue[(max_key[0], max_key[1], max_key[2]+1)] = A[max_key[0]] + B[max_key[1]] + C[max_key[2]+1]
    except IndexError:
        pass

Submission status: Wrong Answer

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

priority_queue = {}
priority_queue[(0, 0, 0)] = A[0] + B[0] + C[0]

for _ in range(K):
    # max を見つけて print + pop 
    max_value = 0
    max_key = None
    for k, v in priority_queue.items():
        if max_key is None or v > max_value:
            max_value = v
            max_key = k
    print(priority_queue.pop(max_key))

    # 次の階層を追加
    try:
        priority_queue[(max_key[0]+1, max_key[1], max_key[2])] = A[max_key[0]+1] + B[max_key[1]] + C[max_key[2]]
    except IndexError:
        pass
    try:
        priority_queue[(max_key[0], max_key[1]+1, max_key[2])] = A[max_key[0]] + B[max_key[1]+1] + C[max_key[2]]
    except IndexError:
        pass
    try:
        priority_queue[(max_key[0], max_key[1], max_key[2]+1)] = A[max_key[0]] + B[max_key[1]] + C[max_key[2]+1]
    except IndexError:
        pass

Submission status: Wrong Answer

Solution code:
import time
import math
xyzk=list(map(int,input().split()))
abc=[[],[],[]]
maxlist=[]
for a in range(len(abc)):
    abc[a]=list(map(int,input().split()))

for a in range(xyzk[0]):
    for b in range(xyzk[1]):
        for c in range(xyzk[2]):
            maxlist.append(abc[0][a]+abc[1][b]+abc[2][c])
maxlist.reverse()
for a in range(len(maxlist)-1-xyzk[3],xyzk[3]):
    print(maxlist[a])

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

ans = []
for x in range(X):
    for y in range(Y):
        ans.append(A[x]+B[y])

ans.sort(reverse=True)
C.sort(reverse=True)
ans2 = []
for k in range(min(K,X+Y)):
    for z in range(min(Z,K)):
        ans2.append(ans[k]+C[z])
ans2.sort(reverse=True)

for k in range(K):
    print(ans2[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()] 

ans = []
for x in range(X):
    for y in range(Y):
        ans.append(A[x]+B[y])
ans.sort(reverse=True)
C.sort(reverse=True)
for k in range(K):
    for z in range(min(Z,K)):
        ans.append(ans[k]+C[z])
ans.sort(reverse=True)

for k in range(K):
    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()] 

ans = []
for x in range(X):
    for y in range(Y):
        ans.append(A[x]+B[y])
ans.sort(reverse=True)

for k in range(K):
    for z in range(Z):
        ans.append(ans[k]+C[z])
ans.sort(reverse=True)

for k in range(K):
    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()))
#入力受け取り



AA = []
BB = []
CC = []

'''
for k in range(min(X, K)):
	maxA = max(A)
	AA = A.remove(maxA)
	AA.append(maxA)
for k in range(min(Y, K)):
	maxB = max(B)
	B.remove(maxB)
	BB.append(maxB)
for k in range(min(Z, K)):
	maxC = max(C)
	C.remove(maxC)
	CC.append(maxC)
'''

AA = sorted(A)
BB = sorted(B)
CC = sorted(C)
#list X から X に大きい順にポイントを格納。


point = []
for k in range(min(X, K)):
	for l in range(min(Y, K)):
		for m in range(min(Z, K)):
			if (k+1)*(l+1)*(m+1) <= K:
					point.append(AA[k] + BB[l] + CC[m])
#インデックスを参照することで大きい順にポイントの組を取得できるような「リストのリスト」を作成
#indexlist 引数の組を取り出し、対応するポイントを足し算して辞書に格納


for k in range(K):
	print(max(point))
	point.remove(max(point))

Submission status: Wrong Answer

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

ab = [i + j for (i, j) in list(itertools.product(a, b))]

del ab[min(3000,x*y):]

ab.sort(reverse=True)

abc = [ij + h for (ij, h) in list(itertools.product(ab[:min(3000,x*y*z)], c))]

del abc[min(3000,x*y*z):]

abc.sort(reverse=True)

for g in range(k):
  print(abc[g])

Submission status: Wrong Answer

Solution code:
import heapq
X, Y, Z, K = map(int, raw_input().split())
A = map(int, raw_input().split())
B = map(int, raw_input().split())
C = map(int, raw_input().split())

h1 = []
for a in A:
  for b in B:
    heapq.heappush(h1, -a - b)
print -heapq.heappop(h1)

Submission status: Wrong Answer

Solution code:
x,y,z,K=(int(x) for x in(input().split()))
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))
a=sorted(alist)
b=sorted(blist)
c=sorted(clist)
a.reverse()
b.reverse()
c.reverse()
azi=[i+j for i in a[0:x] for j in b[0:y]]
azi2=[ij+k for ij in azi[:K] for k in c[:K]]
azilist=sorted(azi2)
azilist.reverse()
for i in range(0,K):
    print(azilist[i])

Submission status: Wrong Answer

Solution code:
x,y,z,K=list(map(int,input().split()))
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))
a=sorted(alist)
b=sorted(blist)
c=sorted(clist)
a.reverse()
b.reverse()
c.reverse()
azi=[i+j for i in a[0:K] for j in b[0:K]]
azi2=[ij+k for ij in azi[:K] for k in c[:K]]
azilist=sorted(azi2)
azilist.reverse()
for i in range(0,K):
    print(azilist[i])

Submission status: Wrong Answer

Solution code:
x,y,z,K=list(map(int,input().split()))
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))
a=sorted(alist)
b=sorted(blist)
c=sorted(clist)
a.reverse()
b.reverse()
c.reverse()
azi=[i+j+k for i in a[0:K] for j in b[0:K] for k in c[0:K]]
azilist=sorted(azi)
azilist.reverse()
print(azilist[0:K])

Submission status: Wrong Answer

Solution code:
x,y,z,K=list(map(int,input().split()))
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))
azi=[i+j+k for i in alist for j in blist for k in clist]
azilist=sorted(azi)
azilist.reverse()
print(azilist[0: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()))
#入力受け取り



AA = []
BB = []
CC = []

for k in range(min(X, K)):
	maxA = max(A)
	A.remove(maxA)
	AA.append(maxA)
for k in range(min(Y, K)):
	maxB = max(B)
	B.remove(maxB)
	BB.append(maxB)
for k in range(min(Z, K)):
	maxC = max(C)
	C.remove(maxC)
	CC.append(maxC)
#list X から X に大きい順にポイントを格納。



indexlist  = []
for k in range(min(X, K)):
	for l in range(min(Y, K)):
		for m in range(min(Z, K)):
			if k*l*m <= K:
				indexlist.append([k, l, m])
#インデックスを参照することで大きい順にポイントの組を取得できるような「リストのリスト」を作成


dictionary = {}
for P in indexlist:
	p = AA[P[0]] + BB[P[1]] + CC[P[2]]
	dictionary.update({str(P[0]) +" , " + str(P[1]) +" , " + str(P[2]): p})
#indexlist 引数の組を取り出し、対応するポイントを足し算して辞書に格納


print(dictionary)
Ans = list(dictionary.values())
print(Ans)
for k in range(K):
	print(max(Ans))
	Ans.remove(max(Ans))

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()))
#入力受け取り



AA = []
BB = []
CC = []

for k in range(min(X, K)):
	maxA = max(A)
	A.remove(maxA)
	AA.append(maxA)
for k in range(min(Y, K)):
	maxB = max(B)
	B.remove(max(B))
	BB.append(maxB)
for k in range(min(Z, K)):
	maxC = max(C)
	C.remove(maxC)
	CC.append(maxC)
#list X から X に大きい順にポイントを格納。



indexlist  = []
for k in range(min(X, K)):
	for l in range(min(Y, K)):
		for m in range(min(Z, K)):
			if k*l*m <= K:
				indexlist.append([k, l, m])
#インデックスを参照することで大きい順にポイントの組を取得できるような「リストのリスト」を作成


dictionary = {}
for P in indexlist:
	p = AA[P[0]] + BB[P[1]] + CC[P[2]]
	dictionary.update({str(P[0]) +" , " + str(P[1]) +" , " + str(P[2]): p})
#indexlist 引数の組を取り出し、対応するポイントを足し算して辞書に格納


print(dictionary)
Ans = list(dictionary.values())
print(Ans)
for k in range(K):
	print(max(Ans))
	Ans.remove(max(Ans))

Submission status: Wrong Answer

Solution code:
x,y,z,k = map(int,input().split())
num = []
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
for i in A:
    num.append((i,'A'))
for i in B:
    num.append((i,'B'))
for i in C:
    num.append((i,'C'))
num.sort(reverse = True)
A = []
B = []
C = []
po = 0
while(po < x+y+z and len(A)*len(B)*len(C) < 2022222):
    if(num[po][1] == 'A'):
        A.append(num[po][0])
    elif (num[po][1] == 'B'):
        B.append(num[po][0])
    else:
        C.append(num[po][0])
    po+=1
ans = []
#print(A,B,C)
for a in A:
    for b in B:
        for c in C:
            ans.append(a+b+c)
ans.sort(reverse = True)
for i in range(k):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
x,y,z,k = map(int,input().split())
num = []
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
for i in A:
    num.append((i,'A'))
for i in B:
    num.append((i,'B'))
for i in C:
    num.append((i,'C'))
num.sort(reverse = True)
A = []
B = []
C = []
po = 0
while(po < x+y+z and len(A)*len(B)*len(C) < 1022222):
    if(num[po][1] == 'A'):
        A.append(num[po][0])
    elif (num[po][1] == 'B'):
        B.append(num[po][0])
    else:
        C.append(num[po][0])
    po+=1
ans = []
#print(A,B,C)
for a in A:
    for b in B:
        for c in C:
            ans.append(a+b+c)
ans.sort(reverse = True)
for i in range(k):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
x,y,z,k = map(int,input().split())
num = []
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
for i in A:
    num.append((i,'A'))
for i in B:
    num.append((i,'B'))
for i in C:
    num.append((i,'C'))
num.sort(reverse = True)
A = []
B = []
C = []
po = 0
while(po < x+y+z and len(A)*len(B)*len(C) < 522222):
    if(num[po][1] == 'A'):
        A.append(num[po][0])
    elif (num[po][1] == 'B'):
        B.append(num[po][0])
    else:
        C.append(num[po][0])
    po+=1
ans = []
#print(A,B,C)
for a in A:
    for b in B:
        for c in C:
            ans.append(a+b+c)
ans.sort(reverse = True)
for i in range(k):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
x,y,z,k = map(int,input().split())
num = []
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
for i in A:
    num.append((i,'A'))
for i in B:
    num.append((i,'B'))
for i in C:
    num.append((i,'C'))
num.sort(reverse = True)
A = []
B = []
C = []
po = 0
while(po < x+y+z and len(A)*len(B)*len(C) < 555555):
    if(num[po][1] == 'A'):
        A.append(num[po][0])
    elif (num[po][1] == 'B'):
        B.append(num[po][0])
    else:
        C.append(num[po][0])
    po+=1
ans = []
#print(A,B,C)
for a in A:
    for b in B:
        for c in C:
            ans.append(a+b+c)
ans.sort(reverse = True)
for i in range(k):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
x,y,z,k = map(int,input().split())
num = []
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
for i in A:
    num.append((i,'A'))
for i in B:
    num.append((i,'B'))
for i in C:
    num.append((i,'C'))
num.sort(reverse = True)
A = []
B = []
C = []
po = 0
while(po < x+y+z and len(A)*len(B)*len(C) < 222222):
    if(num[po][1] == 'A'):
        A.append(num[po][0])
    elif (num[po][1] == 'B'):
        B.append(num[po][0])
    else:
        C.append(num[po][0])
    po+=1
ans = []
#print(A,B,C)
for a in A:
    for b in B:
        for c in C:
            ans.append(a+b+c)
ans.sort(reverse = True)
for i in range(k):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
import itertools

x,y,z,k=(int(i) for i in input().split())
#print(x,y,z,k)
a=list(int(i) for i in input().split())
a.sort(reverse=True)
b=list(int(i) for i in input().split())
b.sort(reverse=True)
c=list(int(i) for i in input().split())
c.sort(reverse=True)
#print(a,b,c)

#a=[int(i) for i in range(1000,-1,-1)]
#b=[int(i) for i in range(1000,-1,-1)]
#c=[int(i) for i in range(1000,-1,-1)]
x=list(itertools.product(a,b))
for i in range(len(x)):
  x[i]=x[i][0]+x[i][1]
x.sort(reverse=True)
y=[]
length=min(len(x),1500)
for i in range(length):
  y+=[x[i]]
#print(len(y))
y=list(itertools.product(y,c))
#print(y)
for i in range(len(y)):
  y[i]=y[i][0]+y[i][1]
y.sort(reverse=True)

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

Submission status: Wrong Answer

Solution code:
import heapq,sys


def main():
    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()))
    
    #A+Bでのベスト枠K個求めるO(XYlogK)
    AandB = []
    for i in range(X):
        for j in range(Y):
            heapq.heappush(AandB, A[i] + B[j])
            #要素がK+1個以上なら一々はじく！！！ことでO(logK)
            if len(AandB) > K:
                heapq.heappop(AandB)
    print(AandB)
    #上のとCでのベスト枠K個を求める(ZKlogK)
    heap_queue = []
    for p in range(Z):
        for h in range(len(AandB)):
            heapq.heappush(heap_queue,C[p] + AandB[h])
            if len(heap_queue) > K:
                heapq.heappop(heap_queue)
    heap_queue.sort(reverse = True)
    for e in heap_queue:
        print(e)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

X,Y,Z,K = map(int, input().split())
cakes = [list(map(int, input().split())) for _ in range(3)]

cakes = list(map(lambda x : sorted(x, reverse=True), cakes))
ans = list()
for i in range(X):
    for j in range(Y):
        if i*j > K:
            break
        for k in range(Z):
            if i*j*k > K:
                break
            ans.append(cakes[0][i] + cakes[1][j] + cakes[2][k])
ans.sort(reverse=True)
print("/n".join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

X,Y,Z,K = map(int, input().split())
cakes = [list(map(int, input().split())) for _ in range(3)]

cakes = list(map(lambda x : sorted(x, reverse=True), cakes))
ans = list()
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if i*j*k > K:
                break
            ans.append(cakes[0][i] + cakes[1][j] + cakes[2][k])
ans.sort(reverse=True)
print("/n".join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
import itertools

x,y,z,k=(int(i) for i in input().split())
#print(x,y,z,k)
a=list(int(i) for i in input().split())
a.sort(reverse=True)
b=list(int(i) for i in input().split())
b.sort(reverse=True)
c=list(int(i) for i in input().split())
c.sort(reverse=True)
#print(a,b,c)

ab=list(itertools.product(a,b))
sumab=[0 for i in range(3000)]
#print(ab)

mynum=min(len(ab),3000)
for i in range(mynum):
  sumab[i]=ab[i][0]+ab[i][1]
  
abc=list(itertools.product(sumab,c))
abc.sort(reverse=True)
sumabc=[0 for i in range(len(abc))]
for i in range(len(abc)):
  sumabc[i]=abc[i][0]+abc[i][1]
  
sumabc.sort(reverse=True)

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

Submission status: Wrong Answer

Solution code:
import itertools
import heapq
import copy

def inv(l):
    return list(map(lambda x: x*-1, l))

def solve(A,B,C, K):
    A,B,C = inv(A), inv(B), inv(C)
    A = sorted(A)
    B = sorted(B)
    C = sorted(C)
    ind = set([(0,0,0)])

    h = [(A[0]+ B[0]+ C[0], (0,0,0))]
    res = []

    for _ in range(K):
        h2 = copy.copy(h)
        print(ind)
        val, (i,j,k) = heapq.heappop(h)
        res += [-val]
        if i+1 < len(A) and (i+1,j,k) not in ind:
            heapq.heappush(h, (A[i+1]+B[j]+C[k], (i+1, j, k)))
            ind |= set([(i+1,j,k)])
        if j+1 < len(B) and (i,j+1, k) not in ind:
            heapq.heappush(h, (A[i]+B[j+1]+C[k], (i, j+1, k)))
            ind |= set([(i,j+1,k)])
        if k+1 < len(C) and (i,j, k+1) not in ind:
            heapq.heappush(h, (A[i]+B[j]+C[k+1], (i, j, k+1)))
            ind |= set([(i,j,k+1)])
    for r in res:
        print(r)

la,lb,lc,K = list(map(int, input().split(' ')))
A = list(map(int, input().split(' ')))
B = list(map(int, input().split(' ')))
C = list(map(int, input().split(' ')))

solve(A,B,C,K)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
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()))
D=[]
for i in range(X):
	for j in range(Y):
		for k in range(Z):
			if (i+1)*(j*1)*(k+1)<=K:
				D.append(A[i]+B[j]+C[k])
			else:
				break
D.sort()
D.reverse()

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

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop

X, Y, Z, K = map(int, input().split())

A = sorted([int(e) for e in input().split()], reverse=True)
B = sorted([int(e) for e in input().split()], reverse=True)
C = sorted([int(e) for e in input().split()], reverse=True)


def get_value(ai, bi, ci):
    return -(A[ai] + B[bi] + C[ci])


heap = []
heappush(heap, (get_value(0, 0, 0), 0, 0, 0))
used = {(0, 0, 0)}

for k in range(K):
    v, ia, ib, ic = heappop(heap)
    print(-v)

    if ia < X - 1 and (ia + 1, ib, ic) not in used:
        heappush(heap, (get_value(ia + 1, ib, ic), ia + 1, ib, ic))
        used.add((ia + 1, ib, ic))
    if ib < Y - 1 and (ia, ib + 1, ic) not in used:
        heappush(heap, (get_value(ia, ib + 1, ic), ia, ib + 1, ic))
        used.add((ia, ib + 1, ic))
    if ic < Z - 1:
        heappush(heap, (get_value(ia, ib, ic + 1), ia, ib, ic + 1))
        used.add((ia, ib, ic + 1))

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop

X, Y, Z, K = map(int, input().split())

A = sorted([int(e) for e in input().split()], reverse=True)
B = sorted([int(e) for e in input().split()], reverse=True)
C = sorted([int(e) for e in input().split()], reverse=True)


def get_value(ai, bi, ci):
    return -(A[ai] + B[bi] + C[ci])


heap = []
ans = []
heappush(heap, (get_value(0, 0, 0), 0, 0, 0))
use = {(0, 0, 0)}

for k in range(K):
    v, ia, ib, ic = heappop(heap)
    print(-v)
    ans.append(v)

    if ia < X - 1 and (ia + 1, ib, ic) not in use:
        heappush(heap, (get_value(ia + 1, ib, ic), ia + 1, ib, ic))
        use.add((ia + 1, ib, ic))
    if ib < Y - 1 and (ia, ib + 1, ic) not in use:
        heappush(heap, (get_value(ia, ib + 1, ic), ia, ib + 1, ic))
        use.add((ia, ib + 1, ic))
    if ic < Z - 1:
        heappush(heap, (get_value(ia, ib, ic + 1), ia, ib, ic + 1))
        use.add((ia, ib, ic + 1))

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop

X, Y, Z, K = map(int, input().split())

A = sorted([int(e) for e in input().split()], reverse=True)
B = sorted([int(e) for e in input().split()], reverse=True)
C = sorted([int(e) for e in input().split()], reverse=True)


def get_value(ia, ib, ic):
    return -(A[ia] + B[ib] + C[ic])


heap = []
use = {(0, 0, 0)}
ans = []
heappush(heap, (get_value(0, 0, 0), 0, 0, 0))

for k in range(K):
    v, ia, ib, ic = heappop(heap)
    print(-v)
    ans.append(v)

    if ia < X - 1 and (ia + 1, ib, ic) not in use:
        heappush(heap, (get_value(ia + 1, ib, ic), ia + 1, ib, ic))
        use.add((ia + 1, ib, ic))
    if ib < Y - 1 and (ia, ib + 1, ic) not in use:
        heappush(heap, (get_value(ia, ib + 1, ic), ia, ib + 1, ic))
        use.add((ia, ib + 1, ic))
    if ic < Z - 1:
        heappush(heap, (get_value(ia, ib, ic + 1), ia, ib, ic + 1))
        use.add((ia, ib, ic + 1))

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop

X, Y, Z, K = map(int, input().split())

A = sorted([int(e) for e in input().split()], reverse=True)
B = sorted([int(e) for e in input().split()], reverse=True)
C = sorted([int(e) for e in input().split()], reverse=True)


def get_value(ia, ib, ic):
    return -(A[ia] + B[ib] + C[ic])


heap = []
use = {(0, 0, 0)}
ans = []
heappush(heap, (get_value(0, 0, 0), 0, 0, 0))

for k in range(K):
    v, ia, ib, ic = heappop(heap)
    ans.append(v)

    if ia < X - 1 and (ia + 1, ib, ic) not in use:
        heappush(heap, (get_value(ia + 1, ib, ic), ia + 1, ib, ic))
        use.add((ia + 1, ib, ic))
    if ib < Y - 1 and (ia, ib + 1, ic) not in use:
        heappush(heap, (get_value(ia, ib + 1, ic), ia, ib + 1, ic))
        use.add((ia, ib + 1, ic))
    if ic < Z - 1:
        heappush(heap, (get_value(ia, ib, ic + 1), ia, ib, ic + 1))
        use.add((ia, ib, ic + 1))

for each in ans:
    print(-each)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
from operator import itemgetter

X, Y, Z, K = map(int, input().split())

A = sorted([int(e) for e in input().split()], reverse=True)
B = sorted([int(e) for e in input().split()], reverse=True)
C = sorted([int(e) for e in input().split()], reverse=True)


def get_value(ia, ib, ic):
    return -(A[ia] + B[ib] + C[ic])


def get_next(ia, ib, ic):
    s = []
    if ia < X - 1:
        s.append((get_value(ia + 1, ib, ic), ia + 1, ib, ic))
    if ib < Y - 1:
        s.append((get_value(ia, ib + 1, ic), ia, ib + 1, ic))
    if ic < Z - 1:
        s.append((get_value(ia, ib, ic + 1), ia, ib, ic + 1))
    return s


heap = []
values = []
heappush(heap, (get_value(0, 0, 0), 0, 0, 0))

for k in range(K):
    # vs = sorted(candidate, reverse=True, key=itemgetter(3))
    v = heappop(heap)
    values.append(v)
    for each in get_next(v[1], v[2], v[3]):
        heappush(heap, each)

for each in values:
    print(-each[0])

Submission status: Wrong Answer

Solution code:
import bisect

X,Y,Z,K = list(map(int,input().split()))
AA = list(map(int,input().split()))
BB = list(map(int,input().split()))
CC = list(map(int,input().split()))
MAX = max(max(AA),max(BB),max(CC))

AB = []
for a in AA:
  for b in BB:
    AB.append(a+b)
    
AB.sort()
XY = len(AB)

def check(n):
  cnt = 0
  for c in CC:
    cnt += (XY - bisect.bisect_left(AB,n-c))
  return cnt >= K

OK = 0
NG = MAX*3+100
while NG - OK >1:
  mid = (OK+NG)//2
  if check(mid):
    OK = mid
  else:
    NG = mid
    
    
ans = []
for c in CC:
    n = bisect.bisect_left(AB,OK-c)
    for i in range(n,XY):
      ans.append(c+AB[i])
      
ans.sort(reverse=True)
for YUI in range(K):
  print(YUI)

Submission status: Wrong Answer

Solution code:
import bisect

X,Y,Z,K = list(map(int,input().split()))
AA = list(map(int,input().split()))
BB = list(map(int,input().split()))
CC = list(map(int,input().split()))
MAX = max(max(AA),max(BB),max(CC))

AB = []
for a in AA:
  for b in BB:
    AB.append(a+b)
    
AB.sort()
XY = len(AB)

def check(n):
  cnt = 0
  for c in CC:
    cnt += (XY - bisect.bisect_left(AB,n-c))
  return cnt >= K

OK = 0
NG = MAX*3+100
while NG - OK >1:
  mid = (OK+NG)//2
  if check(mid):
    OK = mid
  else:
    NG = mid
    
    
ans = []
for c in CC:
    n = bisect.bisect_left(AB,OK-c)
    for i in range(n,XY):
      ans.append(c+AB[i])
      
ans.sort(reverse=True)
for YUI in ans:
  print(YUI)