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
from heapq import *

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

L = []
heapify(L)
for a in A:
    for b in B:
        for c in C:
            heappush(L, -(a+b+c))
for i in range(K):
    n = heappop(L)
    print(-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(len(a)):
  for j in range(len(b)):
    l.append(a[i]+b[j])

l.sort(reverse=True)
if k <= len(l):
  l = l[:k]

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

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

Submission status: Time Limit Exceeded

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

A = sorted(list(map(int, input().split())), reverse=True)[:K]
B = sorted(list(map(int, input().split())), reverse=True)[:K]
C = sorted(list(map(int, input().split())), reverse=True)[:K]

R  = [sum([A[0], B[0], C[0]])]
Q  = {(0, 0, 1), (0, 1, 0), (1, 0, 0)}
D  = {(0, 0, 0), (0, 0, 1), (0, 1, 0), (1, 0, 0)}
iS = [((a, b, c), sum([A[a], B[b], C[c]])) for a, b, c in Q if (a < X) and (b < Y) and (c < Z)]

while len(R) < K:
    iS = sorted(iS, key=lambda x: [x[1], x[0]], reverse=True)
    R.append(iS[0][1])
    abc     = iS[0][0]
    a, b, c = abc[0], abc[1], abc[2]
    iS      = iS[1:]
    if a + 1 < X:
        if not (a + 1, b, c) in D:
            iS.append(((a + 1, b, c), sum([A[a + 1], B[b], C[c]])))
            D.add(     (a + 1, b, c))
    if b + 1 < Y:
        if not (a, b + 1, c) in D:
            iS.append(((a, b + 1, c), sum([A[a], B[b + 1], C[c]])))
            D.add(    (a, b + 1, c))
    if c + 1 < Z:
        if not (a, b, c + 1) in D:
            iS.append(((a, b, c + 1), sum([A[a], B[b], C[c + 1]])))
            D.add(     (a, b, c + 1))

for r in R:
    print(r)

Submission status: Time Limit Exceeded

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

A = sorted(list(map(int, input().split())), reverse=True)[:K]
B = sorted(list(map(int, input().split())), reverse=True)[:K]
C = sorted(list(map(int, input().split())), reverse=True)[:K]

R = [sum([A[0], B[0], C[0]])]
Q = {(0, 0, 1), (0, 1, 0), (1, 0, 0)}
D = {(0, 0, 0), (0, 0, 1), (0, 1, 0), (1, 0, 0)}
S = {}

while len(R) < K:
    iS = []
    for a, b, c in Q:
        if (a, b, c) in S:
            iS.append(((a, b, c), S[(a, b, c)]))
        else:
            abc = sum([A[a], B[b], C[c]])
            iS.append(((a, b, c), abc))
            S[(a, b, c)] = abc
    iS = sorted(iS, key=lambda x: [x[1], x[0]], reverse=True)
    R.append(iS[0][1])
    abc = iS[0][0]
    Q.remove(abc)
    if abc[0] + 1 < X:
        if not (   abc[0] + 1, abc[1]    , abc[2]) in D:
            Q.add((abc[0] + 1, abc[1]    , abc[2]))
            D.add((abc[0] + 1, abc[1]    , abc[2]))
    if abc[1] + 1 < Y:
        if not (   abc[0]    , abc[1] + 1, abc[2]) in D:
            Q.add((abc[0]    , abc[1] + 1, abc[2]))
            D.add((abc[0]    , abc[1] + 1, abc[2]))
    if abc[2] + 1 < Z:
        if not (   abc[0]    , abc[1]    , abc[2] + 1) in D:
            Q.add((abc[0]    , abc[1]    , abc[2] + 1))
            D.add((abc[0]    , abc[1]    , abc[2] + 1))

for r in R:
    print(r)

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

R = [sum([A[0], B[0], C[0]])]
Q = {(0, 0, 1), (0, 1, 0), (1, 0, 0)}
D = {(0, 0, 0), (0, 0, 1), (0, 1, 0), (1, 0, 0)}

while len(R) < K:
    iS = sorted([((a, b, c), sum([A[a], B[b], C[c]])) for a, b, c in Q], key=lambda x: [x[1], x[0]], reverse=True)
    R.append(iS[0][1])
    abc = iS[0][0]
    Q.remove(abc)
    if abc[0] + 1 < X:
        if not (   abc[0] + 1, abc[1]    , abc[2]) in D:
            Q.add((abc[0] + 1, abc[1]    , abc[2]))
            D.add((abc[0] + 1, abc[1]    , abc[2]))
    if abc[1] + 1 < Y:
        if not (   abc[0]    , abc[1] + 1, abc[2]) in D:
            Q.add((abc[0]    , abc[1] + 1, abc[2]))
            D.add((abc[0]    , abc[1] + 1, abc[2]))
    if abc[2] + 1 < Z:
        if not (   abc[0]    , abc[1]    , abc[2] + 1) in D:
            Q.add((abc[0]    , abc[1]    , abc[2] + 1))
            D.add((abc[0]    , abc[1]    , abc[2] + 1))

for r in R:
    print(r)

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

AB  = sorted([sum(ab)  for ab  in itertools.product(A,  B)], reverse=True)[:K]
ABC = sorted([sum(abc) for abc in itertools.product(AB, C)], reverse=True)[:K]

for abc in ABC:
    print(abc)

Submission status: Time Limit Exceeded

Solution code:
import heapq as hq

x,y,z,k = map(int,input().split())
a = list(map(lambda x:int(x) * (-1),input().split()))
b =list(map(lambda x:int(x) * (-1),input().split()))
c = list(map(lambda x:int(x) * (-1),input().split()))
a.sort()
b.sort()
c.sort()
possibles = [(a[0]+b[0]+c[0],0,0,0)]

done = [[[0 for _ in range(z)]for _ in range(y)] for _ in range(x)]
done[0][0][0] = 1
def neibor(ai,bi,ci,possibles,done):
    for aj,bj,cj in [(ai+1,bi,ci),(ai,bi+1,ci),(ai,bi,ci+1)]:
        if (aj<=x-1) and (bj<=y-1) and (cj<=z-1) and (not done[aj][bj][cj]):
            hq.heappush(possibles,(a[aj]+b[bj]+c[cj],aj,bj,cj))
            done[aj][bj][cj] = 1
    

def conf(possibles,done):
    yam,ai,bi,ci = hq.heappop(possibles)
    print(-1*yam)
    neibor(ai,bi,ci,possibles,done)

for i in range(k):
    yam,ai,bi,ci = hq.heappop(possibles)
    print(-1*yam)
    for aj,bj,cj in [(ai+1,bi,ci),(ai,bi+1,ci),(ai,bi,ci+1)]:
        if (aj<=x-1) and (bj<=y-1) and (cj<=z-1) and (not done[aj][bj][cj]):
            hq.heappush(possibles,(a[aj]+b[bj]+c[cj],aj,bj,cj))
            done[aj][bj][cj] = 1

Submission status: Time Limit Exceeded

Solution code:
import heapq as hq

x,y,z,k = map(int,input().split())
a = list(map(lambda x:int(x) * (-1),input().split()))
b =list(map(lambda x:int(x) * (-1),input().split()))
c = list(map(lambda x:int(x) * (-1),input().split()))
a.sort()
b.sort()
c.sort()
possibles = [(a[0]+b[0]+c[0],0,0,0)]

done = [[[0 for _ in range(z)]for _ in range(y)] for _ in range(x)]
done[0][0][0] = 1
def neibor(ai,bi,ci,possibles,done):
    for aj,bj,cj in [(ai+1,bi,ci),(ai,bi+1,ci),(ai,bi,ci+1)]:
        if (aj<=x-1) and (bj<=y-1) and (cj<=z-1) and (not done[aj][bj][cj]):
            hq.heappush(possibles,(a[aj]+b[bj]+c[cj],aj,bj,cj))
            done[aj][bj][cj] = 1
    

def conf(possibles,done):
    yam,ai,bi,ci = hq.heappop(possibles)
    print(-1*yam)
    neibor(ai,bi,ci,possibles,done)

for i in range(k):
    conf(possibles,done)

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)
AB=AB[:K]

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

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

s = sum

delecious = []
for prod in product(a, b, c):
    delecious.append(s(prod))

delecious.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

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

delecious = []
for prod in product(a, b, c):
    delecious.append(sum(prod))

delecious.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K = map(int,input().split())
A, B, C = [sorted(list(map(int,input().split())),reverse=True) for _ in range(3)]
ans_list = []
for i in range(X):
  for j in range(Y):
    for k in range(Z):
      if i*j*k > K: break
      else: ans_list.append(A[i]+B[j]+C[k])
[print(ans) for ans in sorted(ans_list,reverse=True)[:K]]

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K = map(int,input().split())
A, B, C = list(map(int,input().split())),  list(map(int,input().split())),  list(map(int,input().split()))
AB = sorted([a+b for a in A for b in B],reverse=True)
ABC = sorted([ab+c for ab in AB[:K] for c in sorted(C)[:K]],reverse=True)
[print(abc) for abc in sorted(ABC,reverse=True)[:K]]

Submission status: Time Limit Exceeded

Solution code:
import heapq

X,Y,Z,K = map(int,input().split())
A, B, C = [], [], []
[heapq.heappush(A, -a) for a in map(int,input().split())]
[heapq.heappush(B, -b) for b in map(int,input().split())]
[heapq.heappush(C, -c) for c in map(int,input().split())]

max_A = [-heapq.heappop(A) for _ in range(min(K,X))]
max_B = [-heapq.heappop(B) for _ in range(min(K,Y))]
max_C = [-heapq.heappop(C) for _ in range(min(K,Z))]

ans_list = []
for max_a in max_A:
  for max_b in max_B:
    for max_c in max_C:
      heapq.heappush(ans_list, -sum([max_a,max_b,max_c]))
[print(-heapq.heappop(ans_list)) for _ in range(K)]

Submission status: Time Limit Exceeded

Solution code:
import heapq

X,Y,Z,K = map(int,input().split())
A, B, C = [], [], []
[heapq.heappush(A, -a) for a in map(int,input().split())]
[heapq.heappush(B, -b) for b in map(int,input().split())]
[heapq.heappush(C, -c) for c in map(int,input().split())]

max_A = [-heapq.heappop(A) for _ in range(X)]
max_B = [-heapq.heappop(B) for _ in range(Y)]
max_C = [-heapq.heappop(C) for _ in range(Z)]

ans_list = []
for max_a in max_A:
  for max_b in max_B:
    for max_c in max_C:
      heapq.heappush(ans_list, -sum([max_a,max_b,max_c]))
[print(-heapq.heappop(ans_list)) for _ in range(K)]

Submission status: Time Limit Exceeded

Solution code:
import heapq

x, y, z, k = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(3)]
for i in range(3):
    ls[i].sort(reverse=True)
q = [(-sum([ls[i][0] for i in range(3)]), 0, 0, 0)]
res = []
used = [[[False] * z for _ in range(y)] for _ in range(x)]
used[0][0][0] = True
while len(res) < k:
    s, i, j, l = heapq.heappop(q)
    res.append(-s)
    if i + 1 < x:
        if not used[i + 1][j][l]:
            heapq.heappush(
                q, (-(ls[0][i + 1] + ls[1][j] + ls[2][l]), i + 1, j, l))
            used[i + 1][j][l] = True
    if j + 1 < y:
        if not used[i][j + 1][l]:
            heapq.heappush(
                q, (-(ls[0][i] + ls[1][j + 1] + ls[2][l]), i, j + 1, l))
            used[i][j + 1][l] = True
    if l + 1 < z:
        if not used[i][j][l + 1]:
            heapq.heappush(
                q, (-(ls[0][i] + ls[1][j] + ls[2][l + 1]), i, j, l + 1))
            used[i][j][l + 1] = True
print(*res, sep='\n')

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(3)]
ps = sorted([a + b for a in ls[0] for b in ls[1]], reverse=True)[:k]
res = sorted([ab + c for ab in ps for c in ls[2]], reverse=True)[:k]
print(*res, sep='\n')

Submission status: Time Limit Exceeded

Solution code:
s=list(map(int,input().split()))
t=list(map(int,input().split()))
u=list(map(int,input().split()))
v=list(map(int,input().split()))
list=[0 for i in range(s[0]*s[1]*s[2])]
a=0
for i in range(s[0]):
  for j in range(s[1]):
    for k in range(s[2]):
      list[a]=t[i]+u[j]+v[k]
      a+=1
list.sort(reverse=True)
for l in range(s[3]):
  print(list[l])

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)
ans = []
BC_ans = []
for eb in B:
    for ec in C:
        BC_ans.append(eb+ec)
BC_ans.sort(reverse=True)
BC_ans = BC_ans[:K]
for ea in A[:K]:
    for ebc in BC_ans:
        ans.append(ea+ebc)
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
class Heap:
    def __init__(self):
        self.sz = 0
        self.heap = []
    def push(self,x):
        cost = x[3]
        self.heap.append(x)
        i = self.sz
        self.sz += 1
        while i > 0 :
            p = int((i-1)/2)
            if p >= 0 and self.heap[p][3] <= cost:
                self.heap[i] = self.heap[p]
                i = p
            else :
                break
        self.heap[i] = x
    def pop2(self):
        ret = self.heap[0]
        cost = self.heap[-1]
        self.heap.pop(-1)
        self.sz -= 1
        i = 0
        while 2*i+1 < self.sz :
            a = 2 * i + 1
            b = 2 * i + 2
            if b < self.sz and self.heap[a][3] < self.heap[b][3] :
                a = b
            if self.heap[a][3] <= cost[3]:
                break
            self.heap[i] = self.heap[a]
            i = a
        self.heap[i] = cost
        return ret[3]



def main():
    X,Y,Z,K = map(int,input().split())
    size = max(X,Y,Z)
    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)
    i = Heap()
    i.heap = [[0,0,0,A[0]+B[0]+C[0]],[0,0,0,0]]
    i.sz = 2
    count = [[[0 for i in range(Z+1)] for j in range(Y+1)] for k in range(X+1)]
    for p in range(K):
        x = i.heap[0]
        if x[0] + 1 < X  and count[x[0]+1][x[1]][x[2]] == 0 :
            i.push([x[0]+1, x[1] , x[2], A[x[0] + 1] + B[x[1]] + C[x[2]]])
            count[x[0] + 1][x[1]][x[2]] = 1
        if x[1] + 1 < Y  and count[x[0]][x[1]+1][x[2]] == 0:
            i.push([x[0], x[1] + 1, x[2], A[x[0]] + B[x[1] + 1 ] + C[x[2]]])
            count[x[0]][x[1] + 1][x[2]] = 1
        if x[2] + 1 < Z and count[x[0]][x[1]][x[2]+1] == 0:
            i.push([x[0] , x[1], x[2] + 1 , A[x[0]] + B[x[1]] + C[x[2] + 1 ]])
            count[x[0]][x[1]][x[2] + 1] = 1
        print(i.pop2())

if __name__ ==  "__main__":
    main()

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

BC_ans = []

for eb in B:
    for ec in C:
        BC_ans.append(eb+ec)
BC_ans.sort(reverse=True)
BC_ans = BC_ans[:K]
for ea in A[:K]:
    for ebc in BC_ans:
        ans.append(ea+ebc)
ans.sort(reverse=True)
for i in range(K):
    print(ans[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)
ans = []

BC_ans = []

for eb in B:
    for ec in C:
        BC_ans.append(eb+ec)
max_BC = max(BC_ans)
for ea in A:
    if len(ans):
        if max_BC+ea < min(ans):
            break
    for ebc in BC_ans:
        ans.append(ea+ebc)
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k = map(int,input().split())
x = list(map(int,input().split()))
x.sort(reverse=True)
y = list(map(int,input().split()))
y.sort(reverse=True)
z = list(map(int,input().split()))
z.sort(reverse=True)
xy = []
for xx in x:
  for yy in y:
    xy.append(xx+yy)
xy.sort(reverse=True)
xy = xy[:k]
xyz = []
for yx in xy:
  for zz in z:
    xyz.append(yx+zz)
xyz.sort(reverse=True)
for i in range(k):
  print(xyz[i])

Submission status: Time Limit Exceeded

Solution code:
import heapq


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

sum =[]
heapq.heapify(sum)

for i in range(0,X):
    for j in range(0,Y):
        for k in range(0,Z):
            heapq.heappush(sum,(Alist[i]+Blist[j]+Clist[k])*(-1))

for i in range(0,K):
    print(-1*heapq.heappop(sum))

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = [int(elem) for elem in input().split()]
a_lst = [int(elem) for elem in input().split()]
b_lst = [int(elem) for elem in input().split()]
c_lst = [int(elem) for elem in input().split()]

ab_lst = []
for a in a_lst:
  for b in b_lst:
    ab_lst.append(a + b)

ab_lst = sorted(ab_lst, reverse=True)
    
res = []
for ab in ab_lst[:k]:
  for c in c_lst:
    res.append(ab + c)

res = sorted(res, reverse=True)
for elem in res[:k]:
  print(elem)

Submission status: Time Limit Exceeded

Solution code:
import heapq

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 A:
  for j in B:
    heapq.heappush(AB,-i-j)
#print(AB)

ABC=[]
for i in AB:
  for j in C:
    heapq.heappush(ABC,i-j)

for i in range(min(K,X*Y*Z)):
  print(-heapq.heappop(ABC))

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 A:
  for j in B:
    AB.append(i+j)
AB=sorted(AB,key=lambda x: -x)
AB=AB[:min(K,len(A)*len(B))]
#print(AB)

ABC=[]
for i in AB:
  for j in C:
    ABC.append(i+j)
ABC=sorted(ABC,key=lambda x: -x)
#print(ABC)

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

Submission status: Time Limit Exceeded

Solution code:
#15:38
x,y,z,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse = True)
a = a[:k]
b = list(map(int,input().split()))
b.sort(reverse = True)
b = b[:k]
c = list(map(int,input().split()))
c.sort(reverse = True)
c = c[:k]
ab = []
for l in a:
  for m in b:
    ab.append(l+m)
ab.sort(reverse = True)
ab = ab[:k]
abc = []
for n in ab:
  for o in c:
    abc.append(n+o)
abc.sort(reverse = True)
abc = abc[:k]
for p in abc:
  print(p)

Submission status: Time Limit Exceeded

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

while len(a) * len(b) * len(c) > 10000000:
    if a[0] <= b[0] and a[0] <= c[0]:
        a.pop(0)
    elif b[0] <= a[0] and b[0] <= c[0]:
        b.pop(0)
    else:
        c.pop(0)

answers = sorted([i + j + k for i in a for j in b for k in c], reverse=True)

print(*answers[:k], sep="\n")

Submission status: Time Limit Exceeded

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

aa = sorted([i + j + k for i in a for j in b for k in c], reverse=True)

print(*aa[:k], sep="\n")

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)

p = []
for i in range(x):
  for j in range(y):
    for l in range(z):
      if (i+1) * (j+1) * (l+1) <= k:
        p.append(a[i]+b[j]+c[l])

p.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left as bl
from collections import deque as dq
X, Y, Z, K = map(int, input().split())
ABC = [sorted(list(map(int, input().split()))) for _ in range(3)]
AB = []
for i in range(X):
  for j in range(Y):
    AB.append(ABC[0][i] + ABC[1][j])
AB.sort(reverse = True)
res = []
for i in range(min(K, X * Y)):
  for j in range(Z):
    res.append(AB[i] + ABC[2][j])
res.sort(reverse = True)
for i in range(K):
  print(res[i])

Submission status: Time Limit Exceeded

Solution code:
# input
X,Y,Z,K = map(int, 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()]

# list top K of a+b
a_plus_b_list = []
for a in a_list:
    for b in b_list:
        a_plus_b_list.append(a+b)
a_plus_b_list.sort(reverse = True)

# list top K of a+b+c
d_list = []
for a_b in a_plus_b_list:
    for c in c_list:
        d_list.append(a_b + c)
d_list.sort(reverse = True)
for i in range(K):
    print(d_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(' ')))
ab = []
for i in a:
    for j in b:
        ab.append(i+j)
ab.sort(reverse = True)
abc = []
ab = ab[:k+1]
k_1 = min([len(ab), k])
for i in ab:
    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 = 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 = []
k_1 = min([len(ab), k])
for i in ab:
    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 = 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(len(a)):
    for j in range(len(b)):
        ab.append(a[i]+b[j])
ab.sort(reverse = True)
abc = []
k_1 = min([len(ab), k])
for i in ab:
    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 = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
res = []
for i in range(X):
  for j in range(Y):
    for k in range(Z):
      res.append(A[i] + B[j] + C[k])
res.sort()
for _ in range(K):
  print(res.pop())

Submission status: Time Limit Exceeded

Solution code:

def resolve():
    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()))
    ans = []
    for a in A:
        for b in B:
            for c in C:
                ans.append(a + b + c)
    ans.sort(reverse=True)
    for i in range(k):
        print(ans[i])


if __name__ == "__main__":
    resolve()

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(len(a)):
    for j in range(len(b)):
        ab.append(a[i]+b[j])
ab.sort(reverse = True)
abc = []
k_1 = min([len(ab), k])
for i in range(k_1):
    for j in range(len(c)):
        abc.append(ab[i]+c[j])
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 = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))
ab = []
for i in range(len(a)):
    for j in range(len(b)):
        ab.append(a[i]+b[j])
ab.sort(reverse = True)
c.sort(reverse = True)
abc = []
k_1 = min([len(ab), k])
for i in range(k_1):
    for j in range(len(c)):
        abc.append(ab[i]+c[j])
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 = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))
ab = []
for i in range(len(a)):
    for j in range(len(b)):
        ab.append(a[i]+b[j])
ab.sort(reverse = True)
c.sort(reverse = True)
abc = []
k_1 = min([len(ab), k])
k_2 = min([len(c), k])
for i in range(k_1):
    for j in range(k_2):
        abc.append(ab[i]+c[j])
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 = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

tmpList = []
for i in range(X):
    for j in range(Y):
        tmpList.append(a[i] + b[j])

tmpList.sort(reverse=True)
ansLst = []
for i in range(min(K, len(tmpList))):
    for j in c:
        ansLst.append(tmpList[i] + j)

ansLst.sort(reverse=True)

for i in range(K):
    print(ansLst[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()))
ab=[]
for i in a:
    for j in b:
        ab.append(i+j)
ab=sorted(ab,reverse=True)
ans=[]
for i in ab:
    for j in c:
        ans.append(i+j)
ans=sorted(ans,reverse=True)
for i in range(k):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
import heapq

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

V = [[[0] * x for i in range(y)] for j in range(z)]

Q = []
i = 0
j = 0
l = 0
heapq.heappush(Q, (-(A[0]+B[0]+C[0]), i, j, l))
V[i][j][l] = 1
ans = heapq.heappop(Q)
print(-ans[0])
i = ans[1]
j = ans[2]
l = ans[3]

for ii in range(k-1):
    if i+1 < x and V[i+1][j][l] == 0:
        V[i+1][j][l] = 1
        heapq.heappush(Q, (-(A[i+1]+B[j]+C[l]), i+1, j, l))
    if j+1 < y and V[i][j+1][l] == 0:
        V[i][j+1][l] = 1
        heapq.heappush(Q, (-(A[i]+B[j+1]+C[l]), i, j+1, l))
    if l+1 < z and V[i][j][l+1] == 0:
        V[i][j][l+1] = 1
        heapq.heappush(Q, (-(A[i]+B[j]+C[l+1]), i, j, l+1))
    ans = heapq.heappop(Q)
    print(-ans[0])
    i = ans[1]
    j = ans[2]
    l = ans[3]

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

D = [0] * (min(k, x) * min(k, y))

for i in range(min(k, x)):
    for j in range(min(k, y)):
        D.append(A[i] + B[j])

D.sort(reverse=1)
E = [0] * (min(k, len(D)) * min(k, z))

for i in range(min(k, len(D))):
    for j in range(min(k, z)):
        E.append(D[i] + C[j])

E.sort(reverse=1)

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

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

D = []

for i in range(min(k, x)):
    for j in range(min(k, y)):
        D.append(A[i] + B[j])

D.sort(reverse=1)
E = []

for i in range(min(k, len(D))):
    for j in range(min(k, z)):
        E.append(D[i] + C[j])

E.sort(reverse=1)

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

Submission status: Time Limit Exceeded

Solution code:
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

X,Y,Z,K = IL()
a = IL()
b = IL()
c = IL()

ab = []
for i in itertools.product(a,b):
  ab.append(sum(i))
ab.sort(reverse=True)

ans = []
for i in itertools.product(ab[:3000],c):
  ans.append(sum(i))
ans.sort(reverse=True)

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

AB = []
ABC = []

for i in A:
    for j in B:
        AB.append(i+j)

AB.sort(reverse=True)
AB_max = AB[:K]

for j in AB_max:
    for h in C:
        ABC.append(j+h)

ABC.sort(reverse=True)

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