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: Time Limit Exceeded

Solution code:
import numpy as np
k = int(input().split(" ")[-1])

a_ = np.array([int(i) for i in input().split(" ")])
b_ = np.array([int(i) for i in input().split(" ")])
c_ = np.array([int(i) for i in input().split(" ")])

res = []
for a in a_:
    for b in b_:
        for c in c_:
            if len(res) == k:
                i = res.index(min(res))
                res[i] = max(res[i], a+b+c)
            else:
                res.append(a+b+c)

res = sorted(res)[::-1]

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

Submission status: Time Limit Exceeded

Solution code:
import heapq
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
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()))


def solve1():
    que = []
    for a in A:
        for b in B:
            for c in C:
                heapq.heappush(que, -(a+b+c))
    for _ in range(k):
        print(-heapq.heappop(que))


solve1()

Submission status: Time Limit Exceeded

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,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: Time Limit Exceeded

Solution code:
k = int(input().split(" ")[-1])

a_ = [int(i) for i in input().split(" ")]
b_ = [int(i) for i in input().split(" ")]
c_ = [int(i) for i in input().split(" ")]

res = []
for a in a_:
    for b in b_:
        for c in c_:
            res.append(a+b+c)

res.sort()

res = res[::-1]
for i in range(k):
    print(res[i])

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int,input().split())
a,b,c = [list(map(int,input().split())) for _ in [0]*3]
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:
    l2.append(l1[l]+m)
#print(l2)

l2.sort(reverse=True)
for n in range(k):
  print(l2[n])

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int,input().split())
a,b,c = [list(map(int,input().split())) for _ in [0]*3]
#print(a)
#print(b)
#print(c)

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:
    l2.append(l1[l]+m)
#print(l2)

l2.sort(reverse=True)
for n in range(k):
  print(l2[n])

Submission status: Time Limit Exceeded

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)

anslist = []
flag = [[[False for _ in range(K)] for _ in range(K)] for _ in range(K)]

heapq.heappush(anslist, (-(A[0]+B[0]+C[0]), "000"))
count = 0

while count < K:
    p = heapq.heappop(anslist)
    print(p[0]*(-1))
    count += 1
    # push
    a, b, c = map(int, p[1])
    for i, j, k in [[1, 0, 0], [0, 1, 0], [0, 0, 1]]:
        if a+i >= X or b+j >= Y or c+k >= Z:
            continue
        if not flag[a+i][b+j][c+k]:
            flag[a+i][b+j][c+k] = True
            tmp = str(a+i)+str(b+j)+str(c+k)
            heapq.heappush(anslist, (-(A[a+i]+B[b+j]+C[c+k]), tmp))

Submission status: Time Limit Exceeded

Solution code:
X, Y, Z, K = list(map(int, input().split(" ")))
xs = list(map(int, input().split(" ")))
ys = list(map(int, input().split(" ")))
zs = list(map(int, input().split(" ")))

xy = sorted([x+y for x in xs for y in ys], reverse=True)[:K]
xyz = sorted([w+z for w in xy for z in zs], reverse=True)[:K]
for i in xyz:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
X, Y, Z, K = list(map(int, input().split(" ")))
xs = list(map(int, input().split(" ")))
ys = list(map(int, input().split(" ")))
zs = list(map(int, input().split(" ")))

xy = sorted([x+y for x in xs for y in ys], reverse=True)[:K]
xyz = sorted([w+z for w in xy for z in zs], reverse=True)
for i in range(K):
    print(xyz[i])

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k = map(int,input().split())
lia = sorted(list(map(int,input().split())),reverse = True)
lib = sorted(list(map(int,input().split())),reverse = True)
lic = sorted(list(map(int,input().split())),reverse = True)
li = []

for s in range(x):
    for t in range(y):
        for u in range(z):
            if s*t*u <= k:
                li.append(lia[s]+lib[t]+lic[u])
ans = sorted(li,reverse = True)[:k]

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

Submission status: Time Limit Exceeded

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()))
ABlist = []
ABClist = []

for x in A:
    for y in B:
        sumple = x + y
        ABlist.append(sumple)
        ABlist.sort(reverse=True)
        ABlist = ABlist[:K]

for x in ABlist:
    for z in C:
        test = x + z
        ABClist.append(test)
        ABClist.sort(reverse=True)
        ABClist = ABClist[:K]

for x in ABClist:
    print(x)

Submission status: Time Limit Exceeded

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)

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

main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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()))
list=[]
for i in range(x):
    for j in range(y):
        for l in range(z):
            list+=[a[i]+b[j]+c[l]]
list.sort(reverse=True)
for i in range(len(list)):
    if i<k:
        print(list[i])

Submission status: Time Limit Exceeded

Solution code:
def solve():
  x,y,z,k = (int(i) for i in 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 = sorted(a,reverse=True)
  b = sorted(b,reverse=True)
  c = sorted(c,reverse=True)
  ab = []
  abc = []
  
  for i in range(x):
    for j in range(y):
      ab.append(a[i]+b[j])
  ab = sorted(ab,reverse = True)
  for t in range(min(k,len(ab))):
    for l in range(z):
      abc.append(ab[t]+c[l])
      
  abc = sorted(abc,reverse = True)
  for i in range(k):
    print(abc[i])

solve()

Submission status: Time Limit Exceeded

Solution code:
def solve():
  x,y,z,k = (int(i) for i in 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())
  ab = []
  abc = []
  
  for i in range(x):
    for j in range(y):
      ab.append(a[i]+b[j])
  ab = sorted(ab,reverse = True)
  for t in range(min(k,len(ab))):
    for l in range(z):
      abc.append(ab[t]+c[l])
      
  abc = sorted(abc,reverse = True)
  for i in range(k):
    print(abc[i])

solve()

Submission status: Time Limit Exceeded

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

ls = [0]*(len(A)*len(B))
for i in range(len(A)):
    for j in range(len(B)):
        ls[(i*len(B))+j] = A[i] + B[j]
ls.sort(reverse = True)
ls = ls[:k]
check_ls = []
for i in range(len(C)):
    for j in range(len(ls)):
        check_ls.append(C[i] + ls[j])
check_ls.sort(reverse = True)
for i in range(k):
    print(check_ls[i])

Submission status: Time Limit Exceeded

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:
    l2.append(l1[l]+m)
#print(l2)

l2.sort(reverse=True)
for n in range(k):
  print(l2[n])

Submission status: Time Limit Exceeded

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 l1:
  for m in c:
    l2.append(l+m)
#print(l2)

l2.sort(reverse=True)
for n in range(k):
  print(l2[n])

Submission status: Time Limit Exceeded

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)
xyzlist = []
i,Ai,Bi,Ci = 0,1,1,1

while i < K:
    maxtest = 0
    for x in range(0,Ai):
        for y in range(0,Bi):
            for z in range(0,Ci):
                if [x,y,z] in xyzlist:
                    continue
                test = A[x] + B[y] + C[z]
                if test > maxtest:
                    maxtest = test
                    xtest = x
                    ytest = y
                    ztest = z
    print(maxtest)
    xyzlist.append([xtest,ytest,ztest])
    Ai = min(X,max(xtest+2,Ai))
    Bi = min(Y,max(ytest+2,Bi))
    Ci = min(Z,max(ztest+2,Ci))
    i += 1

Submission status: Time Limit Exceeded

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()))
ABlist = []
ABClist = []

for x in A:
    for y in B:
        sumple = x + y
        ABlist.append(sumple)

ABlist.sort(reverse=True)
ABlist = ABlist[0:min(K,X*Y)]

for x in ABlist:
    for z in C:
        test = x + z
        ABClist.append(test)

ABClist.sort(reverse=True)

for x in range(0,K):
    print(ABClist[x])

Submission status: Time Limit Exceeded

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)

def solve(P):
    cnt = 0
    for x in range(X):
        for y in range(Y):
            for z in range(Z):
                if A[x]+B[y]+C[z] >= P:
                    cnt+=1
                if cnt >= K:
                    return False
    return True

t = True
P = A[0]+B[0]+C[0]
while t:
    t = solve(P)
    P -= 1


ans = []
cnt = 0
for x in range(X):
        for y in range(Y):
            for z in range(Z):
                if A[x]+B[y]+C[z] >= P+1:
                    ans.append(A[x]+B[y]+C[z])
                    cnt+=1
                if cnt >= K:
                    ans.sort(reverse=True)
                    for k in range(K):
                        print(ans[k])
                    exit()

Submission status: Time Limit Exceeded

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()))
l = []

for i in range(min(X, K)):
    for j in range(min(Y, K)):
        l.append(a[i] + b[j])
l.sort(reverse = True)
l = l[:K]

L = []
c.sort(reverse = True)

for i in range(len(l)):
    for j in range(min(Z, K)):
        L.append(l[i] + c[j])

L.sort(reverse = True)
print(*L[:K], sep = "\n")

Submission status: Time Limit Exceeded

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()))
l = []

for i in range(X):
    for j in range(Y):
        l.append(a[i] + b[j])
l.sort(reverse = True)
l = l[:K]

L = []
c.sort(reverse = True)

for i in range(len(l)):
    for j in range(min(Z, K)):
        L.append(l[i] + c[j])

L.sort(reverse = True)
print(*L[:K], sep = "\n")

Submission status: Time Limit Exceeded

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()))
l = []

for i in range(X):
    for j in range(Y):
        l += [a[i] + b[j]]
l.sort(reverse = True)
l = l[:K]

L = []
c.sort(reverse = True)

for i in range(len(l)):
    for j in range(min(Z, K)):
        L += [l[i] + c[j]]

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

Submission status: Time Limit Exceeded

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):
        for z in range(Z):
            ans.append(A[x]+B[y]+C[z])
ans.sort(reverse=True)
for k in range(K):
    print(ans[k])

Submission status: Time Limit Exceeded

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()))
l = []

for i in range(X):
    for j in range(Y):
        l.append(a[i] + b[j])
l.sort(reverse = True)
l = l[:K]

L = []
c.sort(reverse = True)

for i in range(len(l)):
    for j in range(min(Z, K)):
        L.append(l[i] + c[j])

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

Submission status: Time Limit Exceeded

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()))
l = []

for i in range(X):
    for j in range(Y):
        l.append(a[i] + b[j])
l.sort(reverse = True)
l = l[:K]

L = []
for i in range(len(l)):
    for j in range(Z):
        L.append(l[i] + c[j])

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

Submission status: Time Limit Exceeded

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

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
del a[min(k,x):]
del b[min(k,y):]
del c[min(k,z):]

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

ab.sort(reverse=True)
del ab[min(k,x*y):]

abc = [ij + h for (ij, h) in list(itertools.product(ab, c))]

abc.sort(reverse=True)

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

Submission status: Time Limit Exceeded

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

ab.sort(reverse=True)

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

abc.sort(reverse=True)

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

Submission status: Time Limit Exceeded

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 に大きい順にポイントを格納。


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: Time Limit Exceeded

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 に大きい順にポイントを格納。



dictionary = {}
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:
					p = AA[k] + BB[l] + CC[m]
					dictionary.update({str(k) +" , " + str(l) +" , " + str(m): p})
#インデックスを参照することで大きい順にポイントの組を取得できるような「リストのリスト」を作成
#indexlist 引数の組を取り出し、対応するポイントを足し算して辞書に格納


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

Submission status: Time Limit Exceeded

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

ab.sort(reverse=True)
del ab[min(k,x*y):]

abc = [ij + h for (ij, h) in list(itertools.product(ab, c))]

abc.sort(reverse=True)

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

Submission status: Time Limit Exceeded

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 に大きい順にポイントを格納。



dictionary = {}
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:
					p = AA[k] + BB[l] + CC[m]
					dictionary.update({str(k) +" , " + str(l) +" , " + str(m): p})
#インデックスを参照することで大きい順にポイントの組を取得できるような「リストのリスト」を作成
#indexlist 引数の組を取り出し、対応するポイントを足し算して辞書に格納


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

Submission status: Time Limit Exceeded

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

ab.sort(reverse=True)

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

abc = [ij + h for (ij, h) in list(itertools.product(ab, c))]

abc.sort(reverse=True)

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

Submission status: Time Limit Exceeded

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)

h2 = []
for _ in range(min(K, X * Y)):
  ab = -heapq.heappop(h1)
  for c in C:
    heapq.heappush(h2, -ab - c)

for _ in range(K):
  print -heapq.heappop(h2)

Submission status: Time Limit Exceeded

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)
A += [-1e10]
B += [-1e10]
C += [-1e10]

memo = [A[i] + B[0] + C[0] for i in range(X + 1)]
L = [[0 for i in range(Y + 1)] for j in range(X + 1)]

for i in range(K):
  ma = 0
  for j in range(X):
    if memo[ma] < memo[j]:
      ma = j
  print(memo[ma])
  mb = 0
  mn = 0
  for j in range(Y):
    x = B[j] + C[L[ma][j]]
    if mb < x:
      mb = x
      mn = j
  L[ma][mn] += 1
  n = 0
  for j in range(Y):
    n = max(n, B[j] + C[L[ma][j]])
  memo[ma] = A[ma] + n

Submission status: Time Limit Exceeded

Solution code:
def main():
  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 = []
  for i in A:
    for j in B:
      ab.append(i + j)

  ab.sort(reverse = True)

  abc = []
  for i in ab[:3000]:
    for j in C:
      abc.append(i + j)

  abc.sort(reverse = True)

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

main()

Submission status: Time Limit Exceeded

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)


h2 = []
for _ in range(min(3000, X * Y)):
  ab = -heapq.heappop(h1)
  for c in C:
    heapq.heappush(h2, -ab - c)

for _ in range(K):
  print -heapq.heappop(h2)

Submission status: Time Limit Exceeded

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

ab.sort(reverse=True)

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

abc.sort(reverse=True)

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

Submission status: Time Limit Exceeded

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)


h2 = []
for _ in range(X * Y):
  ab = -heapq.heappop(h1)
  for c in C:
    heapq.heappush(h2, -ab - c)

for _ in range(K):
  print -heapq.heappop(h2)

Submission status: Time Limit Exceeded

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

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

ab.sort(reverse = True)

abc = []
for i in ab[:3000]:
  for j in C:
    abc.append(i + j)

abc.sort(reverse = True)

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

Submission status: Time Limit Exceeded

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 for k in c]
azilist=sorted(azi2)
azilist.reverse()
for i in range(0,K):
    print(azilist[i])

Submission status: Time Limit Exceeded

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()
for i in range(0,K):
    print(azilist[i])

Submission status: Time Limit Exceeded

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)
num = []
for a in A:
    for b in B:
        num.append(a+b)
num.sort(reverse = True)
num2 = []
for i in range(min(len(num),k)):
    for j in C:
        num2.append(num[i]+j)
num2.sort(reverse = True)
for i in range(k):
    print(num2[i])

Submission status: Time Limit Exceeded

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)

#k=3000
#a=[int(i) for i in range(1000)]
#b=[int(i) for i in range(1000)]
#c=[int(i) for i in range(1000)]
x=[]
for h in range(len(a)):
    for i in range(len(b)):
            for j in range(len(c)):
                if (h+1)*(i+1)*(j+1) <=k:
                    x.append(a[h]+b[i]+c[j])

x.sort(reverse=True)
for i in range(k):
  print(x[i])

Submission status: Time Limit Exceeded

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 引数の組を取り出し、対応するポイントを足し算して辞書に格納


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

Submission status: Time Limit Exceeded

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)

#k=3000
#a=[int(i) for i in range(1000)]
#b=[int(i) for i in range(1000)]
#c=[int(i) for i in range(1000)]
x=[]
for h in range(len(a)):
    for i in range(len(b)):
        if (h+1)*(i+1) <=k:
            for j in range(len(c)):
                if (h+1)*(i+1)*(j+1) <=k:
                    x.append(a[h]+b[i]+c[j])

x.sort(reverse=True)
for i in range(k):
  print(x[i])

Submission status: Time Limit Exceeded

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),1600)
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: Time Limit Exceeded

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)):
			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 引数の組を取り出し、対応するポイントを足し算して辞書に格納



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

Submission status: Time Limit Exceeded

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)
if len(x) > 3000:
  x=x[:3000]
#print(len(x))
x=list(itertools.product(x,c))
#print(x)
for i in range(len(x)):
  x[i]=x[i][0]+x[i][1]
x.sort(reverse=True)

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