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 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):
    for y in range(Y):
        for z in range(Z):
            if x*y*z > K:
                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: Time Limit Exceeded

Solution code:
X,Y,Z,K=map(int,input().split())
Ax=sorted(list(map(int,input().split())), reverse=True)
By=sorted(list(map(int,input().split())), reverse=True)
Cz=sorted(list(map(int,input().split())), reverse=True)

a=b=c=0
s = set([(a,b,c)])
t = set()
for k in range(K):
    best_value = 0
    best_tuple = None
    for x,y,z in s:
        if (x,y,z) not in t:
            m = Ax[x]+By[y]+Cz[z]
            if m > best_value:
                best_value = m
                best_tuple = (x,y,z)
    print(best_value)

    t.add(best_tuple)
    s.remove(best_tuple)
    x,y,z=best_tuple
    if x < X-1:
        if (x+1,y,z) not in s:
            s.add((x+1,y,z))
    if y < Y-1:
        if (x,y+1,z) not in s:
            s.add((x,y+1,z))
    if z < Z-1:
        if (x,y,z+1) not in s:
            s.add((x,y,z+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()))
XY=[]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
for a in A[:K]:
    for b in B[:K]:
        XY.append(a+b)
XY.sort(reverse=True)
XY_prime=XY[:K]
XYZ=[]
for xy in XY_prime:
    for c in C[:K]:
        XYZ.append(xy+c)
XYZ.sort(reverse=True)
for xyz in XYZ[:K]:
    print(xyz)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
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()))

v = []


d = [e1+e2 for e1 in a for e2 in b]
d.sort(reverse=True)
d = d[:k]

e = [e1+e2 for e1 in d for e2 in c]
e.sort(reverse=True)


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

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int, input().split())
m = []
for _ in range(3):
    m.append(sorted(list(map(int, input().split())), reverse=True))
 
def sorted_sum(list_a, list_b):
    s = []
    for x in list_a:
        for y in list_b:
            s.append(x + y)
    return sorted(s, reverse=True)
 
ans = sorted_sum(sorted_sum(m[0], m[1])[0:k], m[2])
for i in range(0, k):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
import copy
import numpy as np
import random
import bisect #bisect_left　これで二部探索の大小検索が行える

x,y,z,k = map(int,input().split())
A = [i for i in map(int,input().split())]
B = [i for i in map(int,input().split())]
C =[i for i in map(int,input().split())]

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

ab.sort()
ab.reverse()
if len(ab)>k:
    ab_sel = ab[0:k]
else:
    ab_sel = ab

anss = [0 for i in range(len(C)*len(ab_sel))]
count = 0
for i in ab_sel:
    for j in C:
        anss[count] = i+j
        count += 1


anss.sort()
anss.reverse()

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

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K = map(int,input().split())
l_a = [int(x) for x in input().split()]
l_b = [int(x) for x in input().split()]
l_c = [int(x) for x in input().split()]
l_a.sort(reverse = True)  
l_b.sort(reverse = True)  
l_c.sort(reverse = True)
l_d = [a + b for a in l_a for b in l_b]
l_d.sort(reverse = True)
l_d[:3000]
l_e = [ab + c for ab in l_d for c in l_c]
l_e.sort(reverse = True)
 
for i in range(K):
    print(l_e[i])

Submission status: Time Limit Exceeded

Solution code:
x, y, z, n = map(int, input().split())
e = []
f = []
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
for i in range(x) :
  for j in range(y) :
    e.append(a[i] + b[j])

for k in range(z) :
  for l in range(len(e)) :
    f.append(c[k] + e[l])
f = sorted(f)
f.reverse()
for i in range(n) :
  print(f[i])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
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()))

v = []


d = [e1+e2 for e1 in a for e2 in b]

d = sorted(d, reverse=True)
d = d[:k]

e = [e1+e2 for e1 in d for e2 in c]
e = sorted(e, reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
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 = [int(b+c) for c in C for b in B]
D.sort(reverse=True)
E = [int(a+d) for d in D[:k] for a in A]
E.sort(reverse=True)
for e in E[:k]:
    print(e)

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K = map(int,input().split())
l_a = list(map(int,input().split()))
l_b = list(map(int,input().split()))
l_c = list(map(int,input().split()))
l_a.sort(reverse = True)  
l_b.sort(reverse = True)  
l_c.sort(reverse = True)
l_d = [a + b for a in l_a for b in l_b]
l_d.sort(reverse = True)
l_d[:3000]
l_e = [ab + c for ab in l_d for c in l_c]
l_e.sort(reverse = True)
 
for i in range(K):
    print(l_e[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()]

AB = []
for a in range(x):
    for b in range(y):
        AB.append(A[a] + B[b])
        
ans = []
for i in AB:
    for c in range(z):
        ans.append(i + C[c])
for i in sorted(ans, reverse=True)[0:k]:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k = map(int,input().split())
a = [int(v) for v in input().split()]
b = [int(v) for v in input().split()]
c = [int(v) for v in input().split()]

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

ab = []

for v1 in a:
  for v2 in b:
    ab.append(v1+v2)
ab.sort(reverse=True)
ab = ab[:k]

ans = []

for v1 in ab:
  for v2 in c:
    ans.append(v1+v2)
ans.sort(reverse=True)

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

Submission status: Time Limit Exceeded

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_AB = []
k = 0
for x in range(X):
    for y in range(Y):
        sum_AB.append(A[x]+B[y])
sum_AB.sort(reverse=True) #10**6
sum_count = []
for z in range(Z):
    for xy in range(min(X*Y,K)):
        sum_count.append(C[z]+sum_AB[xy])


sum_count.sort(reverse=True)
for i in range(K):
    print(sum_count[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()))
XY=[]
for a in A:
    for b in B:
        XY.append(a+b)
XY.sort(reverse=True)
XY_prime=XY[:K]
XYZ=[]
for xy in XY_prime:
    for c in C:
        XYZ.append(xy+c)
XYZ.sort(reverse=True)
for xyz in XYZ[:K]:
    print(xyz)

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int, input().split())
a_s = list(map(int, input().split()))
bs = list(map(int, input().split()))
cs = list(map(int, input().split()))
a_s.sort(reverse=True)
bs.sort(reverse=True)
cs.sort(reverse=True)

list = []
i = -1
minlist = 0
flag = True
for a in a_s:
    if minlist > (a + bs[0] + cs[0]):
        break
    for b in bs:
        if minlist > (a + b + cs[0]):
            break
        for c in cs:
            list.append(a + b + c)
            i += 1
            if flag and i > k:
                minlist = min(list)
                flag = False
            if minlist > list[i]:
                break
list.sort(reverse=True)
for i in range(k):
    print(list[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()))

ansListab=[]
for i in range(x):
  for j in range(y):
    ansListab.append(a[i]+b[j])

ansListab.sort(reverse= True)

if len(ansListab)>k:
  ansListab=ansListab[0:k]

ansList=[]
tmp=len(ansListab)
for i in range(tmp):
  for j in range(z):
    ansList.append(ansListab[i]+c[j])

ansList.sort(reverse= True)

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

Submission status: Time Limit Exceeded

Solution code:
X, Y, Z, K = [int(s) for s in input().split()]

A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]

temp = []
for i in range(len(A)):
    for j in range(len(B)):
        temp.append(A[i]+B[j])
tempcalced = list(reversed(sorted(temp)))[:K]

anslist = []
for i in range(len(tempcalced)):
    for j in range(len(C)):
        anslist.append(tempcalced[i]+C[j])
ans = list(reversed(sorted(anslist)))[:K]

for e in ans:
    print(e)

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)

d = [e1+e2 for e1 in a for e2 in b]
d.sort(reverse=True)
d = d[:k]

e = [e1+e2 for e1 in d for e2 in c]    
e.sort(reverse=True)

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

import sys
sys.setrecursionlimit(3000)
Temp = []
for a in A:
    for b in B:
        Temp.append(a+b)
Temp.sort(reverse = True)
Ans = []
for t in Temp[:k+1]:
    for c in C:
        Ans.append(c+t)
Ans.sort(reverse = True)
print(*Ans[:k],sep = "\n")

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K=map(int,input().split())
Ax=sorted(list(map(int,input().split())), reverse=True)
By=sorted(list(map(int,input().split())), reverse=True)
Cz=sorted(list(map(int,input().split())), reverse=True)

a=b=c=0
s = [(a,b,c)]
t = set()
for k in range(K):
    best_value = 0
    best_tuple = None
    for x,y,z in s:
        if (x,y,z) not in t:
            m = Ax[x]+By[y]+Cz[z]
            if m > best_value:
                best_value = m
                best_tuple = (x,y,z)
    print(best_value)

    t.add(best_tuple)
    s.remove(best_tuple)
    x,y,z=best_tuple
    if x < X-1:
        s.append((x+1,y,z))
    if y < Y-1:
        s.append((x,y+1,z))
    if z < Z-1:
        s.append((x,y,z+1))

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=list(A)
B=list(B)
C=list(C)
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
s=[]
ss=[]
for i in A:
    for j in B:
        s+=[i+j]
s.sort(reverse=True)
s=s[:K]


for i in C:
    for j in s:
        ss+=[i+j]

ss.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
def classify(a,b,c,T):
    if T[a][1]!=T[b][1] and T[b][1]!=T[c][1] and T[c][1]!=T[a][1]:
        return 1
    else:
        return 0
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()))
XY=[]
for a in A:
    for b in B:
        XY.append(a+b)
XY.sort(reverse=True)
XY_prime=XY[:K]
XYZ=[]
for xy in XY_prime:
    for c in C:
        XYZ.append(xy+c)
XYZ.sort(reverse=True)
for xyz in XYZ[:K]:
    print(xyz)

Submission status: Time Limit Exceeded

Solution code:
X, Y, Z, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), 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[:K]

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

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

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)

d = []

for e1 in a:
  for e2 in b:
    d.append(e1+e2)

d.sort(reverse=True)
d = d[:k]
e = []

for e1 in d:
  for e2 in c:
    e.append(e1+e2)
    
e.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

AB = []
for p in itertools.product(A, B):
    AB.append(sum(p))
AB = sorted(AB, reverse=True)[:K]

l = []
for p in itertools.product(AB, C):
    l.append(sum(p))
l = sorted(l, reverse=True)[:K]
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()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

"""
max_b = max(B)
max_c = max(C)
"""

summs_ab = []
summs = []
for a in A:
    for b in B:
        summs_ab.append(a+b)
summs_ab.sort(reverse=True)
summs_ab = summs_ab[:min(3001, X*Y*Z+1)]

for c in C:
    for sab in summs_ab:
        summs.append(sab+c)
summs.sort(reverse=True)
"""
for a in A[:K]:
    if len(summs) >= K and a + max_b + max_c < summs[K-1]:
        break

    for b in B[:K]:
        if len(summs) >= K and a + b + max_c < summs[K-1]:
            break

        for c in C[:K]:
            summ = a + b + c
            if len(summs) >= K:
                min_sum = summs[K-1]    
                if summ < min_sum:
                    break
            summs.append(summ)
        summs = merge_sort(summs)
        summs.reverse()
"""
for i in range(K):
    print(summs[i])

Submission status: Time Limit Exceeded

Solution code:
def classify(a,b,c,T):
    if T[a][1]!=T[b][1] and T[b][1]!=T[c][1] and T[c][1]!=T[a][1]:
        return 1
    else:
        return 0
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()))
XY=[]
for a in A:
    for b in B:
        XY.append(a+b)
XY.sort(reverse=True)
XY=XY[:K]
XYZ=[]
for xy in XY:
    for c in C:
        XYZ.append(xy+c)
XYZ.sort(reverse=True)
for xyz in XYZ[:K]:
    print(xyz)

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 s in a:
    for t in b:
        l.append(s+t)
l.sort(reverse=True)
n=[]
for s in l[:k+1]:
    for t in c:
        n.append(s+t)
n.sort(reverse=True)
for i in range(k):
    print(n[i])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
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()))

v = []
for i in range(x):
    for j in range(y):
        v.append(a[i]+b[j])

v = sorted(v, reverse=True)
c = sorted(c, reverse=True)

vv = []
l = len(v)
#if k < l: l=k
if z > k: z=k
for i in range(l):
    for j in range(z):
        vv.append(v[i]+c[j])
vv = sorted(vv, reverse=True)
for ii in vv[0:k]:
    print(ii)

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()))
AB = []
for i in range(X):
    for j in range(Y):
        AB.append(A[i] + B[j])
AB.sort(reverse = True)
ans = []
for i in range(min(X * Y, K)):
    for j in range(Z):
        ans.append(AB[i] + C[j])
ans.sort(reverse = True)
for i in range(K):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
import itertools

X, Y, Z, K = map(int, input().split(' '))
As = [int(c) for c in input().split(' ')]
Bs = [int(c) for c in input().split(' ')]
Cs = [int(c) for c in input().split(' ')]

sums_AB = map(sum, itertools.product(As, Bs))
sums_AB = sorted(sums_AB, reverse=True)[:K]

sums = map(sum, itertools.product(sums_AB, Cs))
sums = sorted(sums, reverse=True)

for s in sums[:K]:
  print(s)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
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とBのわのうちでかい順にK個
ABsum=[]
for i in A:
    for j in B:
        ABsum.append(i+j)
ABsum=sorted(list(ABsum),reverse=True)
sumu=[]
for i in range(min(K,X*Y)):
    for j in C:
        sumu.append(ABsum[i]+j)
sumu=sorted(list(sumu),reverse=True)
for i in range(K):
    print(sumu[i])

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc123_d
import itertools
import math

# input
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()))
# getans
arr = itertools.product(A, B)
arr = map(sum, arr)
arr = sorted(arr, reverse=True)[:K]
arr = itertools.product(arr, C)
arr = map(sum, arr)
arr = sorted(arr, reverse=True)[:K]
# output
for a in arr:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
#D問題
X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
B=list(map(int,input().split()))
B.sort(reverse=True)
C=list(map(int,input().split()))
C.sort(reverse=True)

AB=[]
for b in range(Y):
    for a in range(X):
        ab=A[a]+B[b]
        AB.append(ab)
AB.sort(reverse=True)
ABC=[]
for k in range(min(K,X*Y)):
    for c in range(min(K,Z)):
        abc=AB[k]+C[c]
        ABC.append(abc)
ABC.sort(reverse=True)
for i in range(K):
    print(ABC[i])

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K=map(int,input().split())
A=[int(x) for x in input().split()]
A.sort(reverse=True)
B=[int(x) for x in input().split()]
B.sort(reverse=True)
C=[int(x) for x in input().split()]
C.sort(reverse=True)
D=[a+b for a in A for b in B]
D.sort(reverse=True)
D=D[:3000]
E=[ab+c for ab in D for c in C]
E.sort(reverse=True)
for i in range(K):
  print(E[i])

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

d = [e1+e2 for e1 in a for e2 in b]
d.sort(reverse=True)
d = d[:k]

e = [e1+e2 for e1 in d for e2 in c]
e.sort(reverse=True)

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

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

d = [e1+e2 for e1 in a for e2 in b]
d.sort(reverse=True)
d = d[:k]

e = [e1+e2 for e1 in d for e2 in c]
e.sort(reverse=True)

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

C.sort(reverse=True)
tmp = []
ans = []

for i in range(X):
	for j in range(Y):
		tmp.append(A[i]+B[j])
tmp.sort(reverse=True)

for i in range(min(X*Y, K)):
	for j in range(min(Z, K)):
		ans.append(tmp[i]+C[j])

ans.sort(reverse=True)

for i in range(min(K, X*Y*Z)):
	print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
import itertools

X, Y, Z, K = map(int, input().split(' '))
As = [int(c) for c in input().split(' ')]
Bs = [int(c) for c in input().split(' ')]
Cs = [int(c) for c in input().split(' ')]

sums_AB = map(sum, itertools.product(As, Bs))
sums_AB = sorted(sums_AB, reverse=True)

sums = map(sum, itertools.product(sums_AB, Cs))
sums = sorted(sums, reverse=True)

for s in sums[:K]:
  print(s)

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

ansListab=[]
for i in range(x):
  for j in range(y):
    ansListab.append(a[i]+b[j])

ansListab.sort(reverse= True)

if len(ansListab)>k:
  ansListab=ansListab[0:k]

ansList=[]
for i in range(len(ansListab)):
  for j in range(z):
    ansList.append(ansListab[i]+c[j])

ansList.sort(reverse= True)

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
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とBのわのうちでかい順にK個
ABsum=deque()
for i in A:
    for j in B:
        ABsum.append(i+j)
ABsum=sorted(list(ABsum),reverse=True)
sumu=deque()
for i in range(min(K,X*Y)):
    for j in C:
        sumu.append(ABsum[i]+j)
sumu=sorted(list(sumu),reverse=True)
for i in range(K):
    print(sumu[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())
 
def merge_sort(array):
    if len(array) <= 1:
        return array
    cnt=len(array)//2
    left=array[:cnt]
    right=array[cnt:]
    left = merge_sort(left)
    right = merge_sort(right)
    return merge(left, right)

def merge(left, right):
    array = [0]*3000
    l,r,ind=0,0,0
    while l < len(left) and r < len(right):
        if left[l] >= right[r]:
            array[ind]=left[l]
            l+=1
            ind+=1
        else:
            array[ind]=right[r]
            r+=1
            ind+=1
        if ind>=3000:
            return array
    if l < len(left):
        return array[:ind]+left[l:3000-ind+l]
    if r < len(right):
        return array[:ind]+right[r:3000-ind+r]

a=merge_sort(a)
b=merge_sort(b)
c=merge_sort(c)
l,r=[],[]
for i in a:
    for j in b:
        l.append(i+j)
l=merge_sort(l)
for i in l:
    for j in c:
        r.append(i+j)
r=merge_sort(r)
for i in range(k):
    print(r[i])

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
x, y, z, k = map(int, input().split())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))
zs = list(map(int, input().split()))

xy_list = []
for i,xy in enumerate(list(product(xs,ys))):
    xy_list.append(sum(xy))

xy_list.sort(reverse=True)
xy_list = xy_list[:k]

ans_list = []
for i,xyz in enumerate(list(product(xy_list,zs[:k]))):
    ans_list.append(sum(xyz))
    
ans_list.sort(reverse=True)
ans_list = ans_list[:k]

for ans in ans_list:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import OrderedDict
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)

"""
max_b = max(B)
max_c = max(C)
"""

summs_ab = []
summs = []
for a in A:
    for b in B:
        summs_ab.append(a+b)
summs_ab.sort(reverse=True)
summs_ab = summs_ab[0:min(3001, X*Y*Z+1)]

for c in C:
    for sab in summs_ab:
        summs.append(sab+c)
summs.sort(reverse=True)
"""
for a in A[:K]:
    if len(summs) >= K and a + max_b + max_c < summs[K-1]:
        break

    for b in B[:K]:
        if len(summs) >= K and a + b + max_c < summs[K-1]:
            break

        for c in C[:K]:
            summ = a + b + c
            if len(summs) >= K:
                min_sum = summs[K-1]    
                if summ < min_sum:
                    break
            summs.append(summ)
        summs = merge_sort(summs)
        summs.reverse()
"""
for i in range(K):
    print(summs[i])

Submission status: Time Limit Exceeded

Solution code:
import bisect

x,y,z,k = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
cc = list(map(int, input().split()))

# A,Bでソート
score_ab = []
for a in aa:
    for b in bb:
        bisect.insort_right(score_ab, a+b)
# print(score_ab[::-1])
# A,B合計値の上位K個とCでソート
score = []
for s in score_ab[::-1][:k]:
    for c in cc:
        bisect.insort_right(score, s+c)
for s in score[::-1][:k]:
    print(s)

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

p = [0 for _ in range(x * y)]
t = 0
for ai in a:
    for bi in b:
        p[t] = ai + bi
        t += 1
p.sort(reverse=True)
q = [0 for _ in range(k * z)]
t = 0
for pi in p[:k]:
    for ci in c[:k]:
        q[t] = pi + ci
        t += 1
q.sort(reverse=True)
for qi in q[:k]:
    print(qi)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc123_d
import itertools
import math

# input
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()))
# getans
arr = itertools.product(A, B)
arr = map(sum, arr)
arr = sorted(arr, reverse=True)[:K]
C = sorted(C, reverse=True)[:K]
arr = itertools.product(arr, C)
arr = map(sum, arr)
arr = sorted(arr, reverse=True)[:K]
# output
for a in arr:
    print(a)

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

AB=[]
for i in range(X):
    for j in range(Y):
        AB.append(A[i]+B[j])
        
AB.sort(reverse=True)
tmp=AB[0:min(K,len(AB))]

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

ABC.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

X, Y, Z, K = map(int, input().split(' '))
As = [int(c) for c in input().split(' ')]
Bs = [int(c) for c in input().split(' ')]
Cs = [int(c) for c in input().split(' ')]

sums = map(sum, itertools.product(As, Bs, Cs))
sums = sorted(sums, reverse=True)
for s in sums[:K]:
  print(s)

Submission status: Time Limit Exceeded

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

L = []
for i in range(X) :
    for j in range(Y) :
        L.append(A[i]+B[j])
L = sorted(L)[::-1][:K]

L2 = []
for i in range(len(L)) :
    for j in range(Z) :
        L2.append(L[i]+C[j])
L2 = sorted(L2)[::-1][:K]
print(*L2,sep="\n")

Submission status: Time Limit Exceeded

Solution code:
XYZK=list(map(int, input().split()))
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))
X=XYZK[0]
Y=XYZK[1]
Z=XYZK[2]
K=XYZK[3]

#2段階でソート
AB=[]
for i in range(X):
  for j in range(Y):
    AB.append(A[i]+B[j])
AB.sort(reverse=True)
AB=AB[0:min(K,len(AB))]

ABC=[]
for i in range(min(K,len(AB))):
  for j in range(Z):
    ABC.append(AB[i]+C[j])
ABC.sort(reverse=True)
for i in range(K):
  print(int(ABC[i]))

Submission status: Time Limit Exceeded

Solution code:
X, Y, Z, K = [int(_) for _ in input().split()]
As = [int(_) for _ in input().split()]
Bs = [int(_) for _ in input().split()]
Cs = [int(_) for _ in input().split()]

As.sort()
Bs.sort()
Cs.sort()

choice_stack = [(len(As) - 1, len(Bs) - 1, len(Cs) - 1)]
choice_stack_next = []
choice_log = set()
sums = []

j = 0
while True:
    for Ai, Bi, Ci in choice_stack:
        sums.append(As[Ai] + Bs[Bi] + Cs[Ci])
        cA = (max(0, Ai - 1), Bi, Ci)
        cB = (Ai, max(0, Bi - 1), Ci)
        cC = (Ai, Bi, max(0, Ci - 1))
        if not (cA in choice_log):
            choice_stack_next.append(cA)
            choice_log.add(cA)
        if not (cB in choice_log):
            choice_stack_next.append(cB)
            choice_log.add(cB)
        if not (cC in choice_log):
            choice_stack_next.append(cC)
            choice_log.add(cC)

    sums.sort()
    print(sums.pop())
    choice_stack = [_ for _ in choice_stack_next]
    choice_stack_next.clear()
    j += 1
    if j >= K:
        break