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: Runtime Error

Solution code:
import numpy as np
import sys

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

A = map(int, input().split())
B = map(int, input().split())
C = map(int, input().split())

def get_good(a, v):
    if v is not None:
        return max(a[a < v])
    else:
        max(a)

value = 0
a = b = c = None
for i in range(K):
    print(get_good(A, a) + get_good(B, b), get_good(C, c))
    a = get_good(a)
    b = get_good(b)
    c = get_good(c)

Submission status: Runtime Error

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 = sorted(a)[::-1]
b = sorted(b)[::-1]
c = sorted(c)[::-1]


def search(a, b, c, x, y, z, a_index, b_index, c_index):
    value = -1
    ans = -1
    if(a_index != x-1):
        if(value < a[a_index+1]+b[b_index]+c[c_index]):
            value = a[a_index+1]+b[b_index]+c[c_index]
            ans = 0
    if(b_index != y-1):
        if(value < a[a_index]+b[b_index+1]+c[c_index]):
            value = a[a_index]+b[b_index+1]+c[c_index]
            ans = 1
    if(c_index != z-1):
        if(value < a[a_index]+b[b_index]+c[c_index+1]):
            value = a[a_index]+b[b_index]+c[c_index+1]
            ans = 2

    if(ans == 0): return (a_index+1, b_index, c_index)
    elif(ans == 1): return (a_index, b_index+1, c_index)
    elif(ans == 2): return (a_index, b_index, c_index+1)


a_index = 0
b_index = 0
c_index = 0
while(True):
    a_index, b_index, c_index = search(a, b, c, x, y, z, a_index, b_index, c_index)

    if((a_index+1)*(b_index+1)*(c_index+1) >= min(x*y*z, 1e6)): break


ans = []
for i in range(a_index+1):
    for j in range(b_index+1):
        for l in range(c_index+1):
            ans.append(a[i]+b[j]+c[l])

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

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

Submission status: Runtime Error

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()
B.sort()
C.sort()

Ad = [A[-1]-A[i] for i in range(X-1)]
Bd = [B[-1]-B[i] for i in range(X-1)]
Cd = [C[-1]-C[i] for i in range(X-1)]

d = Ad+Bd+Cd
d.sort()

base = A[-1]+B[-1]+C[-1]
print(base)
for i in range(K-1):
    print(base-d[i])

Submission status: Runtime Error

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

list = [0] * (x * y * z)
i = 0
for ix in range(x):
    for iy in range(y):
        for iz in range(z):
            list[i] = a[ix] + b[iy] + c[iz]
            i += 1

Submission status: Runtime Error

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

A = sorted(list(map(int,input().split())))
A.reverse()
B = sorted(list(map(int,input().split())))
B.reverse()
C = sorted(list(map(int,input().split())))
C.reverse()

a = [A[i] - A[i+1] for i in range(len(A)-1) ]
b = [B[i] - B[i+1] for i in range(len(B)-1) ]
c = [C[i] - C[i+1] for i in range(len(C)-1) ]

st = A[-1]+B[-1]+C[-1]

s_a,s_b,s_c = 1,1,1
for i in range(K-1):
    # どれを取るか選ぶ
    m = min(a[0] if len(a)>0 else 100000000001
            ,b[0] if len(b)>0 else 100000000001
            ,c[0] if len(c)>0 else 100000000001)
    #print(a[0],b[0],c[0])
    consider_list = [0]*3
    if len(a)>0 and a[0] == m:
        consider_list[0] = (s_a+1) * s_b * s_c

    if len(b)>0 and b[0] == m:
        consider_list[1] = (s_a) * (s_b+1) * s_c
    if len(c)>0 and c[0] == m:        
        consider_list[2] = (s_a) * (s_b) * (s_c+1)
    #print(consider_list.index(max(consider_list)))
    if consider_list.index(max(consider_list)) == 0:
        a.pop(0)
        s_a += 1
    elif consider_list.index(max(consider_list)) == 1:
        b.pop(0)
        s_b += 1
    else:
        c.pop(0)
        s_c += 1
    if (s_a-1) * (s_b-1)*(s_c-1) >= K:
        break

import itertools
#print(list(itertools.product(A[:s_a], B[:s_b],C[:s_c])))
for idx,value in enumerate(sorted([sum(i) for i in  list(itertools.product(A[:s_a+1], B[:s_b+1],C[:s_c+1]))])[::-1]):
  if idx > K-1:
    break
  print(value)

Submission status: Runtime Error

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

# 降順sort
a = sorted(a, reverse=True)
b = sorted(b, reverse=True)
c = sorted(c, reverse=True)

nums = [0] * (x * y * z)

n = 0
for i in range(x):
    for j in range(y):
        for m in range(z):
            nums[n] = a[i] + b[j] + c[m]
            n += 1

for _ in range(k):
    max_i = 0
    for i in range(x * y * z):
        if nums[i] > nums[max_i]:
            max_i = i
    print(nums[max_i])
    nums[max_i] = -1

Submission status: Runtime Error

Solution code:
import heapq
X, Y, Z, K = map(int, input().split())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]
A.sort(reverse = True)
A.append(-100000)
B.sort(reverse = True)
B.append(-100000)
C.sort(reverse = True)
C.append(-100000)

Q = []
heapq.heapify(Q)
heapq.heappush(Q, (-(A[0]+B[0]+C[0]), 0, 0, 0))
count = 0
fin = {}
while count < K:
    value, a, b, c = heapq.heappop(Q)
    if (a, b, c) not in fin:
        fin[(a, b, c)] = 1
        print(-value)
        heapq.heappush(Q, (-(A[a+1]+B[b]+C[c]), a+1, b, c))
        heapq.heappush(Q, (-(A[a]+B[b+1]+C[c]), a, b+1, c))
        heapq.heappush(Q, (-(A[a]+B[b]+C[c+1]), a, b, c+1))
        count += 1

Submission status: Runtime Error

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

X, Y, Z, K = LI()
A = LI()
B = LI()
C = LI()

A = A[:min(100, X)]
B = B[:min(100, Y)]
C = C[:min(100, Z)]
# Aの中で最大の数字足すBの最大、Cの最大は全体の中で最大
# 3000個大きい順に求めれば良い

# iが決まれば、j,kのおおきさは分かる
BC = []
# 1000*1000 で10**6の計算量
for j in range(Y):
    for k in range(Z):
        BC.append(B[j] + C[k])

points = []
# 10**3 と 10** 6
for i in range(X):
    points += [bc + A[i] for bc in BC]
#  #  for i in range(len(A)):
#  #      for bc in BC:
#  #          points.append(A[i]+bc)
#  #      #  for j in range(len(B)):
#  #      #      for k in range(len(C)):
#  #      #          point = A[i] + B[j] + C[k]
#  #      #          points.append(point)
for i in sorted(points, reverse=True)[:K]:
    print(i)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

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

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

AX=[A[0]-a for a in A]
BX=[B[0]-b for b in B]
CX=[C[0]-c for c in C]

AX.append(float("inf"))
BX.append(float("inf"))
CX.append(float("inf"))


i=0
j=0
k=0

while (i+1)*(j+1)*(k+1)<K:
    MIN=min(AX[i+1],BX[j+1],CX[k+1])

    if MIN==AX[i+1]:
        i+=1
    if MIN==BX[j+1]:
        j+=1
    if MIN==CX[k+1]:
        k+=1

MAX=A[i]+B[i]+C[i]
MIN=A[0]+B[0]+C[0]-MAX

LIST=[]
for i in range(X):
    if A[0]-A[i]>MIN:
        break
    
    for j in range(Y):
        if A[0]+B[0]-A[i]-B[j]>MIN:
            break

        for k in range(Z):
            if A[i]+B[j]+C[k]>=MAX:
                LIST.append(A[i]+B[j]+C[k])
            else:
                break

LIST.sort(reverse=True)

for j in range(K):
    print(LIST[j])

Submission status: Runtime Error

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()))
r = [0] * (x * y * z)
for i in range(x):
  for j in range(y):
    for l in range(z):
      r[l+j*y+i*x*y] = a[i] + b[j] + c[l]
r.sort()
for i in range(k):
  print(r[-(i+1)])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(A, B, C, K):
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)

    def s(i, j, k):
        return A[i] + B[j] + C[k]
    used = set()
    
    cand = []
    heapq.heappush(cand, (-s(1, 0, 0), (1, 0, 0)))
    used.add((1, 0, 0))
    heapq.heappush(cand, (-s(0, 1, 0), (0, 1, 0)))
    used.add((0, 1, 0))
    heapq.heappush(cand, (-s(0, 0, 1), (0, 0, 1)))
    used.add((0, 0, 1))
    print(s(0, 0, 0))
    for _ in range(K-1):
        v, i = heapq.heappop(cand)
        print(-v)
        
        ti = (i[0]+1, i[1], i[2])
        if ti[0] < len(A) and ti not in used:
            heapq.heappush(cand, (-s(*ti), ti))
            used.add(ti)
        
        ti = (i[0], i[1]+1, i[2])
        if ti[1] < len(B) and ti not in used:
            heapq.heappush(cand, (-s(*ti), ti))
            used.add(ti)
        
        ti = (i[0], i[1], i[2]+1)
        if ti[2] < len(C) and ti not in used:
            heapq.heappush(cand, (-s(*ti), ti))
            used.add(ti)


    # q = []
    # for a in A:
    #     for b in B:
    #         for c in C:
    #             if len(q) == K:
    #                 heapq.heappushpop(q, a+b+c)
    #             else:
    #                 heapq.heappush(q, a+b+c)
    
    # a = [ heapq.heappop(q) for _ in range(K) ]
    # for v in reversed(a):
    #     print(v)
    


def main():
    # N = read_int()
    X, Y, Z, K = read_int_n()
    A = read_int_n()
    B = read_int_n()
    C = read_int_n()
    (slv(A, B, C, K))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

list = [0] * (x * y * z)
i = 0
for ix in range(x):
    for iy in range(y):
        for iz in range(z):
            list[i] = a[ix] + b[iy] + c[iz]
            i += 1

list.sort(reverse=True)

if i >= k:
    for m in range(k):
        print(list[m])
else:
    for m in range(i):
        print(list[m])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 16 20:52:46 2019

@author: Owner
"""


"""
import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy
import bisect
"""

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

"""

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

A = [0]*X
A[:] = map(int, input().split())
B = [0]*Y
B[:] = map(int, input().split())
C = [0]*Z
C[:] = map(int, input().split())

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

ABC = [0]*X*Y*Z
cnt=0 
for x in range(X):
    for y in range(Y):
        for z in range(Z):
            ABC[cnt]=A[x]+B[y]+C[z]
            cnt+=1
ABC.sort(reverse=True)
for k in range(K):
    print(ABC[k])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
import heapq
# import numpy as np

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()

X, Y, Z, K = ds_in()
A_list = ds_in()
B_list = ds_in()
C_list = ds_in()

A_list.sort(reverse=True)
B_list.sort(reverse=True)
C_list.sort(reverse=True)


def search(cand, searched):
    if len(searched) > K-1:
        exit()
    current = searched[-1][1]
    cand1 = (current[0]+1, current[1], current[2])
    cand2 = (current[0], current[1]+1, current[2])
    cand3 = (current[0], current[1], current[2]+1)
    if cand1[0] < len(A_list):
        val = A_list[cand1[0]] + B_list[cand1[1]] + C_list[cand1[2]]
        if (-val, cand1) not in cand:
            heapq.heappush(cand, (-val, cand1))
    if cand2[1] < len(B_list):
        val = A_list[cand2[0]] + B_list[cand2[1]] + C_list[cand2[2]]
        if (-val, cand2) not in cand:
            heapq.heappush(cand, (-val, cand2))
    if cand3[2] < len(C_list):
        val = A_list[cand3[0]] + B_list[cand3[1]] + C_list[cand3[2]]
        if (-val, cand3) not in cand:
            heapq.heappush(cand, (-val, cand3))
    next_ = heapq.heappop(cand)
    print(-next_[0])
    searched.append(next_)
    search(cand=cand, searched=searched)


searched = [(-(A_list[0] + B_list[0] + C_list[0]), (0, 0, 0))]
cand = []
print(-searched[0][0])
search(cand=cand, searched=searched)

Submission status: Runtime Error

Solution code:
def main():
    X,Y,Z,K=[int(x) for x in input().split()]
    AL=[int(x) for x in input().split()]
    BL=[int(x) for x in input().split()]
    CL=[int(x) for x in input().split()]

    L=[0]*(X*Y*Z)
    o=0
    for a in AL:
        for b in BL:
            for c in CL:
                L[o]=a+b+c
                o+=1
    L.sort()
    L.reverse()
                
    for i in range(K):
        print(L[i])
main()

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
X,Y,Z,K = map(int,input().split())
Alist = list(map(int,input().split()))
Blist = list(map(int,input().split()))
Clist = list(map(int,input().split()))
Alllist = []
for a in Alist:
    for b in Blist:
        for c in Clist:
            Alllist.append(a+b+c)
Alllist.sort(reverse=True)

print(Alllist[:K].join("\n"))

Submission status: Runtime Error

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()))
r = [0] * (x * y * z)
for i in range(x):
  for j in range(y):
    for l in range(z):
      r[l+j*y+i*x*y] = a[i] + b[j] + c[l]
r = sorted(r)
for i in range(k):
  print(r[-(i+1)])

Submission status: Runtime Error

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()))
import heapq
q = []
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
def val(i, j, k):
  return -(A[i] + B[j] + C[k])
heapq.heappush(q, (val(0,0,0), 0,0,0))
for _ in range(k):
  v, aa, bb, cc = heapq.heappop(q)
  print(-v)
  heapq.heappush(q, (val(aa+1, bb, cc), aa+1, bb, cc))
  heapq.heappush(q, (val(aa, bb+1, cc), aa, bb+1, cc))
  heapq.heappush(q, (val(aa, bb, cc+1), aa, bb, cc+1))

Submission status: Runtime Error

Solution code:
import itertools
x, y , z, k = map(int, input().split())
a = map(int, input().split())
b = map(int, input().split())
c = map(int, input().split())
result = []
for i, j, k in itertools.product(a, b, c):
    result.append(i + j + k)

result_sorted = sorted(result, reverse=True)
for x in range(k):
    print(result_sorted[x])

Submission status: Runtime Error

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

list = [0] * (x * y * z)
i = 0
for ix in range(x):
    for iy in range(y):
        for iz in range(z):
            list[i] = a[ix] + b[iy] + c[iz]
            i += 1

list.sort(reverse=True)

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 16 20:52:46 2019

@author: Owner
"""


import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy
import bisect

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

"""

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

A = [0]*X
A[:] = map(int, input().split())
B = [0]*Y
B[:] = map(int, input().split())
C = [0]*Z
C[:] = map(int, input().split())

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

ABC = [0]*X*Y*Z
cnt=0 
for x in range(X):
    for y in range(Y):
        for z in range(Z):
            ABC[cnt]=A[x]+B[y]+C[z]
            cnt+=1
ABC.sort(reverse=True)
for k in range(K):
    print(ABC[k])

Submission status: Runtime Error

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()
a.reverse()
b.sort()
b.reverse()
c.sort()
c.reverse()
ans=[]
if x*y*z<=3000:
  for i in range(x):
    for j in range(y):
      for h in range(z):
        ans.append(a[i]+b[j]+c[h])
  ans.sort()
  ans.reverse()
  for i in range(k):
    print(ans[i])
  exit()
p=0
q=0
r=0
for i in range(k):
  ans.append(a[p]+[q]+[r])
  if p+1<len(a):
    a1=a[p]-a[p+1]
  else:
    a1=10**18
  if q+1<len(b):
    b1=b[q]-b[q+1]
  else:
    b1=10**18
  if r+1<len(c):
    c1=c[r]-c[r+1]
  else:
    c1=10**18
  if a1==min(a1,b1,c1):
    p+=1
  elif b1==min(a1,b1,c1):
    q+=1
  elif c1==min(a1,b1,c1):
    r+=1
for i in range(k):
  print(ans[i])

Submission status: Runtime Error

Solution code:
import itertools
x, y , z, k = map(int, input().split())
a = map(int, input().split())
b = map(int, input().split())
c = map(int, input().split())
result = []
for i, j, k in itertools.product(a, b, c):
    result.append(i * j * k)

result_sorted = sorted(result, reverse=True)
for x in range(k):
    print(result_sorted[x])

Submission status: Runtime Error

Solution code:
import itertools
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 = list(itertools.product(a, b, c))
m = list(map(lambda x: sum(x), l)).sort(reverse=True)[:k]
for i in range(k):
  print(m[i])

Submission status: Runtime Error

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

list = [] * (x * y * z)
c = 0
for ix in range(x):
    for iy in range(y):
        for iz in range(z):
            list[c] = a[ix] + b[iy] + c[iz]
            c += 1

list.sort(reverse=True)

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

Submission status: Runtime Error

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()
b.sort()
c.sort()

if x * y * z <= 3000:
    ans = []
    for ai in a:
        for bi in b:
            for ci in c:
                ans.append(ai + bi+ ci)
    ans.sort(reverse=True)
    for i in range(k):
        print(ans[i])
else:
    ia = 0
    ib = 0
    ic = 0
    len_a = len(a)
    len_b = len(b)
    len_c = len(c)

    while (ia+1) * (ib+1) * (ic+1) < 3000:
        if ia + 1 == len_a:
            diff_a = float('inf')
        else:
            diff_a = a[0] - a[ia+1]
        if ib + 1 == len_b:
            diff_b = float('inf')
        else:
            diff_b = b[0] - b[ib+1]
        if ic + 1 == len_c:
            diff_c = float('inf')
        else:
            diff_c = c[0] - c[ic+1]

        if diff_a <= diff_b and diff_a <= diff_c:
            ia += 1
        elif diff_b <= diff_a and diff_b <= diff_c:
            ib += 1
        elif diff_c <= diff_a and diff_c <= diff_b:
            ib += 1

    a = a[:ia+1]
    b = b[:ib+1]
    c = c[:ic+1]

    ans = []
    for ai in a:
        for bi in b:
            for ci in c:
                ans.append(ai + bi + ci)
    ans.sort(reverse=True)
    for i in range(k):
        print(ans[i])

Submission status: Runtime Error

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()]
flav = [sum(i) for i in itertools.product(A,B,C)]
flav.sort(reverse=True)
for i in range(K):
    print(flav[i])

Submission status: Runtime Error

Solution code:
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 i in range(z):
    for j in range(min(3000,x*y*z)):
        ans.append(lisc[i]+an[j])
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])

Submission status: Runtime Error

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

result = []
for x in a:
    for y in b:
        for z in c:
            result.append(x * y * z)

result = sorted(result, reverse=True)[k]
for x in range(k):
    print(result[x])

Submission status: Runtime Error

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())
li=[]
for h in a:
    for i in b:
        for j in c:li+=[h+i+j]
li=sorted(li)[::-1]
for i in range(k):
    print(li[i])