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.

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    s = IR(5)
    k = I()
    if max(s)-min(s) > k:
        print(":(")
    else:
        print("Yay!")
    return


def B():
    s = IR(5)
    s.sort(key = lambda x:-x%10)
    ans = 0
    i = 0
    k = 0
    while 1:
        if i%10 == 0:
            ans = i+s[k]
            i += s[k]-1
            k += 1
            if k == 5:break
        i += 1
    print(ans)
    return


def C():
    n = I()
    a = IR(5)
    ans = 5+n//min(a)
    if n%min(a) == 0:ans -= 1
    print(ans)
    return


def D():
    x,y,z,k = LI()
    a = LI()
    b = LI()
    c = LI()
    if k == x*y*z:
        l = []
        for i in a:
            for j in b:
                for m in c:
                    l.append(i+j+m)
        l.sort(reverse = True)
        for i in l:
            print(i)
        quit()
    l = []
    d = defaultdict(int)
    for i in b:
        for j in c:
            l.append(i+j)
            d[i+j] += 1
    l.sort(reverse = True)
    ans = []
    for i in range(x):
        for j in range(k):
            ans.append(a[i]+l[j])
    ans.sort(reverse = True)
    for i in ans[:k]:
        print(i)
    return


if __name__ == "__main__":
    D()

Solution (Python):
X, Y, Z, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())

S = []
for a in A:
    for b in B:
        S.append(a+b)
S.sort()
C.sort()
T = C

L = X*Y

left = 3; right = max(A)+max(B)+max(C)+1
while left+1 < right:
    mid = (left + right) >> 1
    cur = L
    cnt = 0
    for c in C:
        while cur > 0 and S[cur-1]+c > mid:
            cur -= 1
        cnt += L - cur
    if cnt < K:
        right = mid
    else:
        left = mid
ans = []
for c in C:
    cur = L
    while cur > 0 and S[cur-1]+c >= left:
        v = S[cur-1]+c
        if v == left and len(ans) >= K:
            break
        ans.append(v)
        cur -= 1
ans.sort(reverse=1)
print(*ans[:K], sep='\n')

Solution (Python):
from heapq import heapify, heappush, heappop, heappushpop

X, Y, Z, K = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Cs = list(map(int, input().split()))

sum12s = []
for A in As:
    for B in Bs:
        sum12s.append(A+B)
sum12s.sort(reverse=True)

PQ = [Cs[0]+sum12 for sum12 in sum12s[:K]]
heapify(PQ)
for C in Cs[1:]:
    for sum12 in sum12s[:K]:
        heappush(PQ, C+sum12)
    for _ in range(K, len(PQ)):
        heappop(PQ)

anss = []
for _ in range(K):
    anss.append(heappop(PQ))
print('\n'.join(map(str, anss[::-1])))

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

ab.sort(reverse=True)

q = 0
i = 0
j = 0
ans = [0]*(k*k)
l = 0
for i in range(min(k,x*y)):
    for j in range(min(k,z)):
        ans[l] = ab[i] + c[j]
        l += 1

ans.sort(reverse=True)

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

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    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 = [aa + bb for aa in a for bb in b]
    ab.sort(reverse=True)
    ab = ab[:3000]

    abc = [aabb + cc for aabb in ab for cc in c]
    abc.sort(reverse=True)

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


main()

Solution (Python):
x,y,z,k = map(int,input().split())
lisa = list(map(int,input().split()))
lisb = list(map(int,input().split()))
lisc = list(map(int,input().split()))
lisa.sort(reverse=True)
lisb.sort(reverse=True)
lisc.sort(reverse=True)
an = []
ans = []
for i in range(x):
    for j in range(y):
        an.append(lisa[i]+lisb[j])
an.sort(reverse=True)
an = an[:min(3001,x*y*z+1)]
for num in lisc:
    for nu in an:
        ans.append(num+nu)
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])

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

sumsofAandB = sorted([a+b for a in A for b in B], reverse=True)[:K]
sumsofAll = sorted([ab+c for ab in sumsofAandB for c in C], reverse=True)
for i in range(K):
    print(sumsofAll[i])

Solution (Python):

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

A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

AB_list = [0]*(X*Y)
for i in range(X):
    for j in range(Y):
        AB_list[i*Y+j] = A_list[i] + B_list[j]
AB_list_s = sorted(AB_list)
if len(AB_list_s) > 3000:
    AB_list_s = AB_list_s[-3000:]
W = len(AB_list_s)
ABC_list = [0]*(W*Z)
for i in range(W):
    for j in range(Z):
        ABC_list[i*Z+j] = AB_list_s[i] + C_list[j]
ABC_list_s = sorted(ABC_list)
for i in range(K):
    print(ABC_list_s[-(i+1)])

Solution (Python):
import heapq

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

class Delicious (object):
	def __init__(self, x, y, z):
		self.x = x
		self.y = y
		self.z = z
	
	def total(self):
		return A[self.x] + B[self.y] + C[self.z]
		
	def __lt__(self, other):
		return self.total() > other.total()
	
ds = [Delicious(X-1, Y-1, Z-1)]
check = {}

for k in range(K):
	d = heapq.heappop(ds)
	while (d.x, d.y, d.z) in check:
		d = heapq.heappop(ds)
	check[d.x, d.y, d.z] = True
	print(d.total())
	if 0 < d.x:
		heapq.heappush(ds, Delicious(d.x-1, d.y, d.z))
	if 0 < d.y:
		heapq.heappush(ds, Delicious(d.x, d.y-1, d.z))
	if 0 < d.z:
		heapq.heappush(ds, Delicious(d.x, d.y, d.z-1))

Solution (Python):
x,y,z,k = map(int,input().split())
lisa = list(map(int,input().split()))
lisb = list(map(int,input().split()))
lisc = list(map(int,input().split()))
lisa.sort(reverse=True)
lisb.sort(reverse=True)
lisc.sort(reverse=True)
an = []
ans = []
for num in lisb:
    for nu in lisa:
        an.append(num+nu)
an.sort(reverse=True)
an = an[:min(3001,x*y*z+1)]
for num in lisc:
    for nu in an:
        ans.append(num+nu)
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])

Solution (Python):
import sys,bisect
input = sys.stdin.readline

x,y,z,k = map(int,input().split())
a = tuple(map(int,input().split()))
b = tuple(map(int,input().split()))
c = list(map(int,input().split()))

ab = []
for e in a:
    for w in b:
        ab.append(e+w)
ab.sort()

ok = -1
ng = 10**12
while abs(ok-ng)>1:
    mid = (ok+ng)//2
    cnt = 0
    for e in c:
        cnt += len(ab)-bisect.bisect_left(ab,mid-e)
    if cnt >= k:
        ok = mid
    else:
        ng = mid

res = []
for e in c:
    ind = bisect.bisect_left(ab,ok-e)
    for i in range(ind,len(ab)):
        res.append(e+ab[i])
res.sort()
for i in range(1,k+1):
    print(res[-i])

Solution (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()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
from math import ceil
ans = []
for a in range(X):
    for b in range(min(Y,ceil(3000/(a+1)))):
        for c in range(min(Z,ceil(3000/(a+1)/(b+1)))):
            ans.append(A[a]+B[b]+C[c])
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])