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:
x,y,z,k=map(int,input().split())
a=sorted(map(int,input().split()))[::-1]
b=sorted(map(int,input().split()))[::-1]
c=sorted(map(int,input().split()))[::-1]

ab=sorted([i+j for i in a for j in b])[::-1]
abc=sorted([i+j for i in ab[:k] for j in c[:k]])[::-1]

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

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

l_1=[];l_2=[]
l_1+=l[:k];l_2+=c[:k]

l_3=[]
for i in range(len(l_1)):
    for j in range(len(l_2)):
        l_3+=[l_1[i]+l_2[j]]
l_3.sort(reverse=True)
        
for i in range(k):
    print(l_3[i])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr  7 00:03:49 2019

@author: Yamazaki Kenichi
"""
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=True)
B.sort(reverse=True)
C.sort(reverse=True)
Q = []
T = [[[-1 for i in range(Z+1)] for i in range(Y+1)] for i in range(X+1)]
T[0][0][0] = 1
heapq.heappush(Q,[-(A[0]+B[0]+C[0]),0,0,0])
for i in range(K-1):
    k = heapq.heappop(Q)
    s1,s2,s3 = k[1],k[2],k[3]
    if s1 + 1 != X and T[s1+1][s2][s3] == -1:
        heapq.heappush(Q,[-(A[s1+1]+B[s2]+C[s3]),s1+1,s2,s3])
        T[s1+1][s2][s3] = 1
    if s2 + 1 != Y and T[s1][s2+1][s3] == -1:
        heapq.heappush(Q,[-(A[s1]+B[s2+1]+C[s3]),s1,s2+1,s3])
        T[s1][s2+1][s3] = 1
    if s3 + 1 != Z and T[s1][s2][s3+1] == -1:
        heapq.heappush(Q,[-(A[s1]+B[s2]+C[s3+1]),s1,s2,s3+1])
        T[s1][s2][s3+1] = 1
    print(-k[0])
k = heapq.heappop(Q)
print(-k[0])

Submission status: Time Limit Exceeded

Solution code:
import itertools
x,y,z,k = list(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)

del a[min(k,x):]
del b[min(k,y):]
del c[min(k,z):]

ab = sorted([i + j for (i, j) in list(itertools.product(a, b))],reverse=True)
del ab[min(k,x*y):]

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

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

Submission status: Time Limit Exceeded

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

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

li=[]
for i in a:
  for j in b:
    li.append(i+j)
li.sort(reverse=True)
 
ansli=[]
for i in c:
  for j in range(min(k,len(li))):
    ansli.append(i+li[j])
ansli.sort(reverse=True)
 
for i in range(k):
  print(ansli[i])

Submission status: Time Limit Exceeded

Solution code:
import itertools
x,y,z,k = list(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)

del a[min(k,x):]
del b[min(k,y):]
del c[min(k,z):]

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

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

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

abc.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

# Input
X, Y, Z, K = list(map(int, input().split()))
As = sorted(list(map(int, input().split())), reverse=True)
Bs = sorted(list(map(int, input().split())), reverse=True)
Cs = sorted(list(map(int, input().split())), reverse=True)

# Main
As = As[:K]
Bs = Bs[:K]
Cs = Cs[:K]
th = max(As[-1], Bs[-1], Cs[-1])

# if len(As) * len(Bs) * len(Cs) > K:
#   _As = [v for v in As if v >= th]
#   _Bs = [v for v in Bs if v >= th]
#   _Cs = [v for v in Cs if v >= th]
#   if len(_As) * len(_Bs) * len(_Cs) > K:
#     As, Bs, Cs = _As, _Bs, _Cs

from itertools import product
res = []
for a, b, c in product(As, Bs, Cs):
  res.append(a+b+c)
res = sorted(res, reverse=True)
for l in range(K):
  print(res[l])

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_list = []

for i in range(X):
    for j in range(Y):
        ab_list.append(A[i]+B[j])

ab_list2 = sorted(ab_list,reverse = True)[:min(X*Y,K)]
abc_list = []

count = 0
count2 = 0

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


abc_list2 = sorted(abc_list,reverse = True)[:K]

for i in range(K):
    print(abc_list2[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()
A.reverse()
B.sort()
B.reverse()
C.sort()
C.reverse()

ab_list = []

for i in range(X):
    for j in range(Y):
        ab_list.append(A[i]+B[j])

ab_list2 = sorted(ab_list,reverse = True)[:min(X*Y,K)]
abc_list = []

count = 0
count2 = 0

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


abc_list2 = sorted(abc_list,reverse = True)[:K]

for i in range(K):
    print(abc_list2[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()
A.reverse()
B.sort()
B.reverse()
C.sort()
C.reverse()

ab_list = []

for i in range(X):
    for j in range(Y):
        ab_list.append(A[i]+B[j])

ab_list.sort()
ab_list.reverse()
ab_list2 = ab_list[:K]
abc_list = []

count = 0
count2 = 0

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

abc_list.sort()
abc_list.reverse()

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


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

ab_list = []

for i in range(X):
    for j in range(Y):
        ab_list.append(A[i]+B[j])

ab_list.sort()
ab_list.reverse()
abc_list = []

count = 0
count2 = 0

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

abc_list.sort()
abc_list.reverse()

for i in range(K):
    print(abc_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 = list()
for i in A:
    for j in B:
        AB.append(i+j)

AB.sort(reverse=True)
ABC = list()

for i in AB[:K]:
    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:
import numpy as np

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

E_list = []
for i in A_list:
    for j in B_list:
        # print(i+j)
        E_list.append(i+j)

E_list = np.array(E_list)
E_list = np.sort(E_list)[::-1]

sum_list = []
for i in E_list[:K]:
    for j in C_list:
        sum_list.append(i+j)

sum_list = np.array(sum_list)
sum_list = np.sort(sum_list)[::-1]

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
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()))
DD = [i+j for i in A for j in B]
DD.sort()
F = [(i+j)
     for i in DD[max(len(DD)-3001,0):]
     for j in C
]
F.sort()
for i in range(K):
    print(F[-1-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()))

d = []
for i in range(len(a)):
    for j in range(len(b)):
        d.append(a[i]+b[j])
tmp = sorted(d, reverse=True)
if len(tmp) < k:
    use_tmp = tmp
else:
    use_tmp = tmp[0:k]
    
ans = []
for i in range(len(use_tmp)):
    for j in range(len(c)):
        ans.append(use_tmp[i]+c[j])
final_ans = sorted(ans, reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
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()))
DD = [i+j for i in A for j in B]
DD.sort()
F = [(i+j)
     for i in DD[max(len(DD)-3002,0):]
     for j in C
]
F.sort()
for i in range(K):
    print(F[-1-i])

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
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()))
DD = []
A.sort()
B.sort()
C.sort()
DD = [i+j for i in A for j in B]
DD.sort()
F = [(i+j)
     for i in DD[max(len(DD)-3010,0):]
     for j in C
]
F.sort()
for i in range(K):
    print(F[-1-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()))
DD = []
A.sort()
B.sort()
C.sort()
for i in A:
    for j in B:
       DD.append(i+j)
DD.sort()
F = [(i+j)
     for i in DD[max(len(DD)-3010,0):]
     for j in C
]
F.sort()
for i in range(K):
    print(F[-1-i])

Submission status: Time Limit Exceeded

Solution code:
x,y,z,n = 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)
d = []
for i,i1 in enumerate(a):
  for j,j1 in enumerate(b[:n // (i+1)]):
    for k,k1 in enumerate(c[:n // (i+1) * (j+1)]):
        d.append(i1 + j1 + k1)

d.sort(reverse = True)
for i in d[:n]:
  print(i)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
X, Y, Z, K = [int(i) for i in input().split()]

A = sorted([int(i) for i in input().split()], reverse=True)
B = sorted([int(i) for i in input().split()], reverse=True)
C = sorted([int(i) for i in input().split()], reverse=True)

Anum = 0
Bnum = 0
Cnum = 0

AB=np.zeros(X*Y)
for i in range(X):
    for j in range(Y):
        AB[Y*i+j] = A[i]+B[j]

AB = np.sort(AB)[::-1]
AB = AB[:min(X*Y,K)]

ABC=np.zeros(len(AB)*Z)
for i in range(len(AB)):
    for j in range(Z):
        ABC[Z*i+j]=AB[i]+C[j]

ABC = np.sort(ABC)[::-1]

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
X, Y, Z, K = [int(i) for i in input().split()]

A = sorted([int(i) for i in input().split()], reverse=True)
B = sorted([int(i) for i in input().split()], reverse=True)
C = sorted([int(i) for i in input().split()], reverse=True)

Anum = 0
Bnum = 0
Cnum = 0

AB=np.zeros(X*Y)
for i in range(X):
    for j in range(Y):
        AB[Y*i+j] = A[i]+B[j]

AB = sorted(AB, reverse=True)
AB = AB[:min(X*Y,K)]

ABC=np.zeros(len(AB)*Z)
for i in range(len(AB)):
    for j in range(Z):
        ABC[Z*i+j]=AB[i]+C[j]

ABC = sorted(ABC, reverse=True)

for i in range(K):
    print(int(ABC[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()))
DD = []
A.sort()
B.sort()
C.sort()
for i in A:
    for j in B:
       DD.append(i+j)
DD.sort()
F = []
for i in DD[max(len(DD)-3010,0):]:
    for j in C:
        F.append(i+j)
F.sort()
for i in range(K):
    print(F[-1-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()))
DD = []
A.sort()
B.sort()
C.sort()
for i in A:
    for j in B:
       DD.append(i+j)
DD.sort()
F = []
for i in DD[min(len(DD)-3010,0):]:
    for j in C:
        F.append(i+j)
F.sort()
for i in range(K):
    print(F[-1-i])

Submission status: Time Limit Exceeded

Solution code:
x,y,z,n = 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)
d = []
for i,i1 in enumerate(a):
  for j,j1 in enumerate(b):
    for k,k1 in enumerate(c):
      if (i+1) * (j+1) * (k+1) <= n:
        d.append(i1 + j1 + k1)
d.sort(reverse = True)
for i in d[:n]:
  print(i)

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K = map(int,input().split())
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]
C = [int(n) for n in input().split()]
A_B = []
for i in range(len(A)):
    for j in range(len(B)):
        A_B.append(A[i]+B[j])
A_B.sort(reverse=True)
A_B_K = A_B[:K]
A_B_C=[]
for i in range(len(A_B_K)):
    for j in range(len(C)):
        A_B_C.append(A_B_K[i]+C[j])
A_B_C.sort(reverse=True)
for i in range(min(K,len(A_B_C))):
    print(A_B_C[i])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
X, Y, Z, K = [int(i) for i in input().split()]

A = sorted([int(i) for i in input().split()], reverse=True)
B = sorted([int(i) for i in input().split()], reverse=True)
C = sorted([int(i) for i in input().split()], reverse=True)

Anum = 0
Bnum = 0
Cnum = 0

AB=[]
for i in range(X):
    for j in range(Y):
        AB.append(A[i]+B[j])

AB = sorted(AB, reverse=True)
AB = AB[:min(X*Y,K)]

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

ABC = sorted(ABC, reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
import heapq
import itertools

x,y,z,k=(int(i) for i in input().split())
#print(x,y,z,k)
a=list((-1)*int(i) for i in input().split())
#a.sort(reverse=True)
b=list((-1)*int(i) for i in input().split())
#b.sort(reverse=True)
c=list((-1)*int(i) for i in input().split())
#c.sort(reverse=True)
#print(a,b,c)

mylist=list(itertools.product(a,b,c))
#print(mylist)
mylist=[sum(mylist[i]) for i in range(len(mylist))]
#print(mylist)

def heapsort(iterable):
    h = []
    for value in iterable:
        heapq.heappush(h, value)
    return [heapq.heappop(h) for i in range(k)]

#    return [heapq.heappop(h) for i in range(len(h))]

#heapsort([1, 3, 5, 7, 9, 2, 4, 6, 8, 0])
mylist1=heapsort(mylist)

for i in range(k):
  print((-1)*mylist1[i])

Submission status: Time Limit Exceeded

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

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

ab = sorted(list(a+b for a in A for b in B), reverse = True)[:K]
abc = sorted(list(ab+c for ab in ab for c in C), reverse = True)[:K]

for i in abc : 
    print(i)

Submission status: Time Limit Exceeded

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


A = sorted(list(map(int, input().split())))[:K]
B = sorted(list(map(int, input().split())))[:K]
C = sorted(list(map(int, input().split())))[:K]
D = []
E2 = []
F = []

# A + Bの全列挙 からのソート 

for i in A : 
    for j in B : 
        D.append(i+j)
        
E = sorted(D, reverse = True)[:K]

####

for i in E : 
    for j in C : 
        F.append(i+j)
        
G = sorted(F, reverse = True)[:K]

for i in range(K) : 
    print(G[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()))
D = []
E2 = []
F = []

# A + Bの全列挙 からのソート 

for i in A : 
    for j in B : 
        D.append(i+j)
        
E = sorted(D, reverse = True)

if len(E) > K : 
    for i in range(K) : 
        E2.append(E[i])
else : 
    E2 = E
        
####

for i in E2 : 
    for j in C : 
        F.append(i+j)
        
G = sorted(F, reverse = True)

for i in range(K) : 
    print(G[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()))
D = []
E2 = []
F = []

# A + Bの全列挙 からのソート 

for i in A : 
    for j in B : 
        D.append(i+j)
        
E = sorted(D, reverse = True)

for i in range(K) : 
    if len(E) > K : 
        E2.append(E[i])
    else : 
        E2 = E
        
####

for i in E2 : 
    for j in C : 
        F.append(i+j)
        
G = sorted(F, reverse = True)

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

Submission status: Time Limit Exceeded

Solution code:
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()))
taste_list = []

for i in range(X):
  for j in range(Y):
    for k in range(Z):
      taste_list.append(A_list[i]+B_list[j]+C_list[k])
taste_list.sort(reverse=True)
for i in range(K):
  print(taste_list[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()))

#a.sort(reverse=True)
#b.sort(reverse=True)
#c.sort(reverse=True)

li=[]
for i in a:
  for j in b:
    li.append(i+j)
li.sort(reverse=True)

ansli=[]
for i in c:
  for j in range(min(k,len(li))):
    ansli.append(i+li[j])
ansli.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
A,B,C = a[:k[3]],b[:k[3]],c[:k[3]]

ab = list(ax+bx for ax in A for bx in B)
ab.sort(reverse=True)
AB = ab[:k[3]]
abc = list(aby+cy for aby in ab for cy in C)
abc.sort(reverse=True)
for i in range(k[3]): print(abc[i])

Submission status: Time Limit Exceeded

Solution code:
k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ab = sorted(list(ax+bx for ax in a for bx in b), reverse=True)[:k[3]]
abc = sorted(list(aby+cy for aby in ab for cy in c), reverse=True)[:k[3]]
for i in abc: print(i)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math

k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ab = []
for ax, bx in itertools.product(a, b):
    ab.append(ax+bx)
ab.sort(reverse=True)
s_ab = ab[:k[3]]

abc = []
for aby, cy in itertools.product(s_ab, c):
    abc.append(aby+cy)
abc.sort(reverse=True)
s_abc = abc[:k[3]]

for i in s_abc: print(i)

Submission status: Time Limit Exceeded

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

E = []
for a in A_lst:
    for b in B_lst:
        E.append(a+b)
E = sorted(E, reverse=True)[:K]
C_lst = sorted(C_lst, reverse=True)[:K]

F = []
for e in E:
    for c in C_lst:
        F.append(e+c)
F = sorted(F, reverse=True)[:K]

[print(f) for f in F]

Submission status: Time Limit Exceeded

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


E = []
for a in A_lst:
    for b in B_lst:
        E.append(a+b)
E = sorted(E, reverse=True)[:K]
C_lst = sorted(C_lst, reverse=True)[:K]

F = []
for e in E:
    for c in C_lst:
        F.append(e+c)

for d in sorted(F, reverse=True)[:K]:
    print(d)

Submission status: Time Limit Exceeded

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

E = []
for a in A_lst:
    for b in B_lst:
        E.append(a+b)
E = sorted(E, reverse=True)[:K]

F = []
for e in E:
    for c in C_lst:
        F.append(e+c)

for d in sorted(F, reverse=True)[:K]:
    print(d)

Submission status: Time Limit Exceeded

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

delicious = []
for a in A_lst:
    for b in B_lst:
        for c in C_lst:
            delicious.append(sum([a, b, c]))

for d in sorted(delicious, reverse=True)[:K]:
    print(d)

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K = map(int,input().split())
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]
C = [int(n) for n in input().split()]
A_B = []
for i in range(len(A)):
    for j in range(len(B)):
        A_B.append(A[i]+B[j])
A_B.sort(reverse=True)
if K < len(A_B):
    A_B_K = A_B[:K]
else:
    A_B_K = A_B
A_B_C=[]
for i in range(len(A_B_K)):
    for j in range(len(C)):
        A_B_C.append(A_B_K[i]+C[j])
A_B_C.sort(reverse=True)
for i in range(min(K,len(A_B_C))):
    print(A_B_C[i])

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K = map(int, input().split())
cakes = [list(map(int, input().split())) for _ in range(3)]
 
cakes = list(map(lambda x : sorted(x, reverse=True), cakes))
ans = list()
for i in range(X):
    if X>K:
        break
    for j in range(Y):
        for k in range(Z):
            ans.append(cakes[0][i] + cakes[1][j] + cakes[2][k])
ans.sort(reverse=True)
print("\n".join(map(str, ans[:K])))

Submission status: Time Limit Exceeded

Solution code:
x,y,z,K=(int(x) for x in(input().split()))
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))
a=sorted(alist)
b=sorted(blist)
c=sorted(clist)
a.reverse()
b.reverse()
c.reverse()
azi=[i+j for i in a for j in b]
sorted(azi).reverse()
azi2=[ij+k for ij in azi for k in c[:K]]
azilist=sorted(azi2)
azilist.reverse()
for i in range(0,K):
    print(azilist[i])

Submission status: Time Limit Exceeded

Solution code:
x,y,z,K=(int(x) for x in(input().split()))
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))
a=sorted(alist)
b=sorted(blist)
c=sorted(clist)
a.reverse()
b.reverse()
c.reverse()
azi=[i+j for i in a[0:x] for j in b[0:y]]
sorted(azi).reverse()
azi2=[ij+k for ij in azi for k in c[:K]]
azilist=sorted(azi2)
azilist.reverse()
for i in range(0,K):
    print(azilist[i])

Submission status: Time Limit Exceeded

Solution code:
x,y,z,K=(int(x) for x in(input().split()))
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))
a=sorted(alist)
b=sorted(blist)
c=sorted(clist)
a.reverse()
b.reverse()
c.reverse()
azi=[i+j for i in a[0:x] for j in b[0:y]]
azi2=[ij+k for ij in azi for k in c[:K]]
azilist=sorted(azi2)
azilist.reverse()
for i in range(0,K):
    print(azilist[i])

Submission status: Time Limit Exceeded

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

AB = []
for i in range(min(X,K)):
    for j in range(min(Y,K)):
        AB.append(A[i] + B[j])

AB.sort(reverse=True)

ABC = []
for i in range(min(X*Y,K)):
    for j in range(min(Z,K)):
        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:
from sys import exit

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

score = []

for i in range(X):
    for j in range(Y):
        score.append(A[i] + B[j])

score.sort(reverse=True)

ans = []

for i in range(min(K, len(score))):
    for j in range(Z):
        ans.append(score[i] + C[j])

ans.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
list1 = raw_input().split()
listA = raw_input().split()
listB = raw_input().split()
listC = raw_input().split()


N = int(list1[3])

listA.sort(reverse = True)
listB.sort(reverse = True)
listC.sort(reverse = True)

listAB = []


listABC = []

countA = 0
countB = 0

for a in listA :
    countA += 1
    for b in listB:
        ab = int(a) + int (b)
        listAB.append(ab)
        countB += 1
        if countB == N:
            break
    if countA == N:
        break


listAB.sort(reverse = True)

countAB = 0
countC = 0

for ab in listAB :
    countAB += 1

    for c in listC:
        abc = int(ab) + int(c)
        listABC.append(abc)
        countC += 1
        if countC == N:
            break
    if countAB == N:
        break

listABC.sort(reverse = True)

for n in range(int(N)):
    print int(listABC[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()))

res = []
for a in range(X):
    for b in range(Y):
            res.append(A[a] + B[b])
            
res.sort(reverse=True)
result = []
for r in res:
    for c in C:
        result.append(r + c)
        
result.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
list1 = raw_input().split()
listA = raw_input().split()
listB = raw_input().split()
listC = raw_input().split()


N = list1[3]

listAB = []
listABC = []

for a in listA:
    a = int(a)
    for b in listB:
        b = int(b)
        ab = a + b
        listAB.append(ab)

listAB.sort(reverse=True)

listC_int = []
for c in listC:
    c = int(c)
    listC_int.append(c)

listC.sort(reverse=True)

count_C = 0
count_AB = 0

for c in listC:
    count_C += 1

    for ab in listAB:
        count_AB +=1
        abc = int(ab) + int(c)
        listABC.append(abc)
        
        if count_AB == N:
            break
    if count_C == N:
        break


listABC.sort(reverse=True)

for n in range(int(N)):
    print int(listABC[n])

Submission status: Time Limit Exceeded

Solution code:
list1 = raw_input().split()
listA = raw_input().split()
listB = raw_input().split()
listC = raw_input().split()




listABC = []
for a in listA:
    a = int(a)
    for b in listB:
        b = int(b)
        for c in listC:
            c = int(c)
            abc = a + b + c
            listABC.append(abc)

listABC.sort(reverse=True)

for n in range(int(list1[3])):
    print int(listABC[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()))
sorted_abcsum = sorted([A[x] + B[y] + C[z] for x in range(X) for y in range(Y) for z in range(Z)],reverse=True)
for k in range(K):
    print(sorted_abcsum[k])

Submission status: Time Limit Exceeded

Solution code:
import time
import math
xyzk=list(map(int,input().split()))
abc=[[],[],[]]
maxlist=[]
for a in range(len(abc)):
    abc[a]=list(map(int,input().split()))

for a in range(xyzk[0]):
    for b in range(xyzk[1]):
        maxlist.append(abc[0][a]+abc[1][b])
maxlist.sort()
maxlist.reverse()
list2=[]

for a in range(min([xyzk[3],len(maxlist)])):
    for b in range(xyzk[2]):
        list2.append(maxlist[a]+abc[2][b])
list2.sort()
list2.reverse()
for a in range(xyzk[3]):
    print(list2[a])