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:
N=list(map(int,(input().split(" "))))
teast=[]
K = N[3]
total=[]
c=0
for i in range(3):
    teast.append(list(map(int,input().split(" "))))
A=sorted(teast[0],reverse=True)
B=sorted(teast[1],reverse=True)
C=sorted(teast[2],reverse=True)

for i in range(N[0]):

    for j in range(N[1]):

        for k in range(N[2]):
            if i*j*k<=K:
                total.append(A[i] + B[j] + C[k])
            else:
                break

total_s=sorted(total,reverse=True)

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

import itertools
val_list = []

a_max = min(len(A_list), K)
b_max = min(len(B_list), K)
c_max = min(len(C_list), K)

A_list = sorted(A_list, reverse=True)
B_list = sorted(B_list, reverse=True)
C_list = sorted(C_list, reverse=True)
for a, b, c in itertools.product(A_list[:a_max], B_list[:b_max], C_list[:c_max]):
    val_list.append(a + b + c)
    
val_list = sorted(val_list, reverse=True)
for i in range(K):
    print(val_list[i])

Submission status: Time Limit Exceeded

Solution code:
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 = tuple(map(int,input().split()))
 
ab = []
for e in a:
    for w in b:
        ab.append(e+w)
ab.sort()
 
ok = -1
ng = 10**11
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])

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
import heapq
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [X, Y, Z, K] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2]), int(input_raw[3])]

    input_raw = read_func().strip().split()
    A = [long(input_raw[i]) for i in range(X)]
    input_raw = read_func().strip().split()
    B = [long(input_raw[i]) for i in range(Y)]
    input_raw = read_func().strip().split()
    C = [long(input_raw[i]) for i in range(Z)]

    count = 0
    BC = []
    for i in range(X):
        for j in range(Z):
            heapq.heappush(BC, -(B[i] + C[j]))

    A.sort(reverse = True)

    T = []
    for j in range(min(K, len(BC))):
        bc = -heapq.heappop(BC)
        for i in range(X):
            heapq.heappush(T, -(A[i] + bc))

    for i in range(K):
        t = -heapq.heappop(T)
        print t

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

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

ansListab.sort(reverse= True)

ansListab=ansListab[:min(3001,x*y*z+1)]

ansList=[]

for i in c:
  for j in ansListab:
    ansList.append(i+j)

ansList.sort(reverse= True)

for i in range(k):
  print(ansList[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)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)
XY=[]

for a in A:
    for b in B:
        XY.append(a+b)
XY.sort(reverse=True)
XY=XY[:K]
XYZ=[]
for xy in XY:
    for c in C:
        XYZ.append(xy+c)
XYZ.sort(reverse=True)
for i in range(K):
    print(XYZ[i])

Submission status: Time Limit Exceeded

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

X,Y,Z,K = (int(i) for i in input().split())
ax = [int(i) for i in input().split()]
by = [int(i) for i in input().split()]
cz = [int(i) for i in input().split()]
ab = [0] * (X*Y)
cnt = 0
for i in ax:
  for j in by:
    ab[cnt] = i + j
    cnt += 1
ab.sort(reverse=True)
kab = ab[:K]
ans = [0] * (len(kab)*Z)
cnt = 0
for i in kab:
  for j in cz:
    ans[cnt] = i + j
    cnt += 1
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 = sorted([int(i) for i in input().split()])
B = sorted([int(i) for i in input().split()])
C = sorted([int(i) for i in input().split()])

AB = []
for a in A:
  for b in B:
    AB.append(a + b)

AB.sort(reverse=True)
AB = AB[:min(3001, X * Y * Z + 1)]
ABC = []
for ab in AB:
  for c in C:
    ABC.append(ab + c)
ABC.sort(reverse=True)
print(*ABC[: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)

temp = []
for a in A:
	for b in B:
		temp.append(a+b)

temp = sorted(temp, reverse=True)
temp = temp[:K]

ans = []
for c in C:
	for num in temp:
		ans.append(num+c)

ans = sorted(ans, 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 = sorted([a + b for a in A for b in B])[-1:-K-1:-1]
ABC = sorted([ab + c for ab in AB for c in C])[-1:-K-1:-1]
print('\n'.join(map(str, ABC)))

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k = map(int,input().split())
A,B,C= [[int(i) for i in input().split()] for j in range(3)]
AB = []
ABC = []
for i in range(x):
        for j in range(y):
                AB.append(A[i]+B[j])
AB_sort = sorted(AB,reverse=True)
for i in range(min(k,len(AB))):
        for j in range(z):
                ABC.append(AB_sort[i]+C[j])
ABC_sort = sorted(ABC,reverse = True)
for i in range(k):
        print(ABC_sort[i])

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int,input().split())
a =list(map(int,input().split()))
b =list(map(int,input().split()))
c =list(map(int,input().split()))
c.sort(reverse=True)
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)
#print(ab)
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)
#print(ans)
for i in range(k):
    print(ans[i])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
if k<x: a=a[:k]
if k<y: b=b[:k]
if k<z: c=c[:k]
d=[]
ans=[]
for i in a:
    for j in b:
        d.append(i+j)
d.sort(reverse=True)
if len(d)<k: d=d[:k]
for i in c:
    for j in d:
        ans.append(i+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()))
XY=[]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
for a in A[:K]:
    for b in B[:K]:
        XY.append(a+b)
XY.sort(reverse=True)
XY=XY[:K]
XYZ=[]
for xy in XY:
    for c in C:
        XYZ.append(xy+c)
XYZ.sort(reverse=True)
for i in range(K):
    print(XYZ[i])

Submission status: Time Limit Exceeded

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

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

ansListab.sort(reverse= True)

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

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

ansList.sort(reverse= True)

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

Submission status: Time Limit Exceeded

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

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)

res = []

for a in A:
    for b in B:
        res.append(a+b)

res.sort(reverse=True)

res = res[:K]
ans = []

for ab in res:
    for c in C:
        ans.append(ab+c)
    
ans.sort(reverse=True)
ans = ans[:K]

for a in ans:
    print(a)

Submission status: Time Limit Exceeded

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

#a.reverse()
#b.reverse()
#c.reverse()

a_bsum = []

for i in range(x):
	for j in range(y):
			a_bsum.append(a[i]+b[j])
a_bsum.sort()
a_bsum.reverse()

temp_sum = a_bsum[0:k]

sum = []

c.sort()
c.reverse()
c = c[0:k]

for i in a_bsum:
	for j in c:
		sum.append(i+j)

sum.sort()
sum.reverse()

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

Submission status: Time Limit Exceeded

Solution code:
def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int,ss_raw()))

X,Y,Z,K = ints_raw()

A = ints_raw()
B= ints_raw()
C= ints_raw()

arg_buf = {}
def main():
    D = sorted([a+b for a in A for b in B],reverse=True)[:K]
    E = [d+c for d in D for c in C]
    E.sort(reverse=True)
    for k in range(K):
        print(E[k])

main()

Submission status: Time Limit Exceeded

Solution code:
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
B = list(map(int, input().split()))
B.sort(reverse=True)
C = list(map(int, input().split()))
C.sort(reverse=True)
# 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 = []
ABC = []
for b in B:
    for a in A:
        AB.append(a+b)
AB.sort(reverse=True)
AB = AB[:K]
# AB = AB[:min(3001, X*Y*Z+1)]

for c in C:
    for ab in AB:
        ABC.append(ab+c)
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()))

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

ansListab.sort(reverse= True)

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

ansList=[]

for i in ansListab:
  for j in c:
    ansList.append(i+j)

ansList.sort(reverse= True)

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

r = []

for x in range(X):
    for y in range(Y):
        r.append(A[x] + B[y])

r.sort(reverse=True)

k = 0
r2 = []
for Cv in C:
    for Rv in r:
        r2.append(Rv + Cv)
        k += 1
        if k == K:
            break

r2.sort(reverse=True)

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

Submission status: Time Limit Exceeded

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

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

for ab in AB:
    for c in C:
        ABC.append(ab+c)
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())
listA = list(map(int, input().split()))
listB = list(map(int, input().split()))
listC = list(map(int, input().split()))

sumAB =[]
index=0
while index < len(listA):
    index2=0
    while index2 < len(listB):
        sumAB.append(listA[index]+listB[index2])
        index2+=1
    index+=1
sumAB.sort()
sumAB.reverse()
abSL=[]
index3=0
while index3 < min(k, len(sumAB)):
    abSL.append(sumAB[index3])
    index3+=1

answerL=[]
index4=0
while index4 < len(abSL):
    index5=0
    while index5 < len(listC):
        answerL.append(abSL[index4]+listC[index5])
        index5+=1
    index4+=1

answerL.sort()
answerL.reverse()
index6=0
while index6 < k:
    print(answerL[index6])
    index6+=1

Submission status: Time Limit Exceeded

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

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

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

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

Submission status: Time Limit Exceeded

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

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

ansListab.sort(reverse= True)

ansListab=ansListab[:min(3001,x*y*z+1)]

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

ansList.sort(reverse= True)

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

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K = map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
XYZ=[]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
for a in range(1,X+1):
    for b in range(1,Y+1):
        for c in range(1,Z+1):
            if(a*b*c)<=K:
                XYZ.append(A[a-1]+B[b-1]+C[c-1])
XYZ.sort(reverse=True)
for xyz in XYZ[:K]:
    print(xyz)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys

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

A = np.array(sorted(list(map(int,input().split()))))[::-1]
B = np.array(sorted(list(map(int,input().split()))))[::-1]
C = np.array(sorted(list(map(int,input().split()))))[::-1]

k = min(3000, K)

zenbu = []
for x in range(len(A)):
    for y in range(len(B)):
        for z in range(len(C)):
            if (x+1)*(y+1)*(z+1) <= k:
                zenbu.append(A[x]+B[y]+C[z])

zenbu.sort()
zenbu = zenbu[::-1]

for r in zenbu[:k]:
    print(r)

Submission status: Time Limit Exceeded

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

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

ans = []
for i in AB:
    for c in range(z):
        ans.append(i + C[c])
ans = sorted(ans,reverse=True)[0:k]

for i in ans:
    print(i)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import itertools

X, Y, Z, K = tuple([int(x) for x in str(input()).split(' ')])

A = np.array(sorted([int(x) for x in str(input()).split(' ')], reverse=True))
B = np.array(sorted([int(x) for x in str(input()).split(' ')], reverse=True))
C = np.array(sorted([int(x) for x in str(input()).split(' ')], reverse=True))

out = sorted([A[a] + B[b] + C[c] for a, b, c in itertools.product(range(len(A)), range(len(B)), range(len(C))) if a*b*c <= K], reverse=True)

for x in out[:K]:
    print(x)

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
if k<x: a=a[:k]
if k<y: b=b[:k]
if k<z: c=c[:k]
d=[]
ans=[]
for i in a:
    for j in b:
        d.append(i+j)
d.sort(reverse=True)
if len(d)<k: d=d[:k]
for i in c:
    for j in d:
        ans.append(i+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()))
AB = []
ans = []
for a in A:
    for b in B:
        AB.append(a + b)
AB.sort(reverse=True)
AB = AB[:min(3001, X*Y*Z+1)]
for c in C:
    for ab in AB:
        ans.append(c + ab)
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())

aa = list(map(int,input().split()))
aa.sort(reverse = True)
bb = list(map(int,input().split()))
bb.sort(reverse = True)
cc = list(map(int,input().split()))
cc.sort(reverse = True)
al = []
aal = []
for i in aa:
    for j in bb:
        al.append(i+j)
al.sort()
if len(al) > k:
    al = al[len(al)-k:]

for i in al:
    for j in cc:
        aal.append(i+j)
aal.sort()

if len(aal) > k:
    aal = aal[len(aal)-k:]
aal.reverse()
for i in aal:
    print(i)

Submission status: Time Limit Exceeded

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

AB = []
for b in B:
    for a in A:
        AB.append(a+b)
AB = sorted(AB, reverse=True)[:K]

ABC = []
for ab in AB:
    for c in C:
        ABC.append(ab+c)
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 = 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)

L1 = []
for i in range(X) :
    for j in range(Y) :
        l1 = A[i] + B[j]
        L1.append(l1)
L1 = sorted(L1,reverse=True)[:K]

L2 = []
for i in range(len(L1)) :
    for j in range(Z) :
        l2 = L1[i] + C[j]
        L2.append(l2)
L2 = sorted(L2,reverse=True)[:K]
print(*L2,sep="\n")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys

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

A = np.array(sorted(list(map(int,input().split()))))[::-1]
B = np.array(sorted(list(map(int,input().split()))))[::-1]
C = np.array(sorted(list(map(int,input().split()))))[::-1]

zenbu = []
k = min(3000, K)

for x in range(len(A)):
    for y in range(len(B)):
        for z in range(len(C)):
            if x*y*z <= k:
                zenbu.append(A[x]+B[y]+C[z])

zenbu = np.array(zenbu)
ichibu = np.partition(-zenbu, k-1)[:k]
ichibu.sort()
result = -ichibu.astype(np.int64)
for r in result:
    print(r)

Submission status: Time Limit Exceeded

Solution code:
X, Y, X, 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)

ab = [a+b for a in A for b in B]
ab.sort(reverse=True)

ans = [x+c for x in ab[:K] for c in C]
ans.sort(reverse=True)
print('\n'.join(list(map(str, ans[:K]))))

Submission status: Time Limit Exceeded

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

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

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

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

tmp.sort(reverse=True)
del tmp[min(K, X*Y):]

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

ans.sort(reverse=True)

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

Submission status: Time Limit Exceeded

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

AB = []
for b in B:
    for a in A:
        AB.append(a+b)
AB = sorted(AB, reverse=True)[:K]

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

Submission status: Time Limit Exceeded

Solution code:
import sys
X, Y, Z, K = map(int, input().split())
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))
C = list(map(int, sys.stdin.readline().split()))
AB = []
for a in A:
    for b in B:
        AB.append(a + b)
AB.sort(reverse = True)
ans = []
AB2 = AB[:min(X * Y + 1, K + 1)]
for ab in AB2:
    for c in C:
        ans.append(ab + c)
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())
l_a = [int(x) for x in input().split()]
l_a.sort(reverse = True) 
l_b = [int(x) for x in input().split()]
l_b.sort(reverse = True) 
l_c = [int(x) for x in input().split()]
l_c.sort(reverse = True)  
l_d = [a + b for a in l_a for b in l_b]
l_d.sort(reverse = True)
l_d[:3000]
l_e = [ab + c for ab in l_d for c in l_c]
l_e.sort(reverse = True)
for i in range(K):
    print(l_e[i])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

sums = []
for x in range(X):
  for y in range(Y):
    for z in range(Z):
      if x * y * z <= K:
        sums.append(As[x] + Bs[y] + Cs[z])
      else:
        break
sums = sorted(sums, reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
#D問題
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 b in range(Y):
    for a in range(X):
        ab=A[a]+B[b]
        AB.append(ab)
AB.sort(reverse=True)
ABC=[]
roopk=min(K,X*Y)
roopz=min(K,Z)
for k in range(roopk):
    for c in range(roopz):
        abc=AB[k]+C[c]
        ABC.append(abc)
ABC.sort(reverse=True)
for i in range(K):
    print(ABC[i])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

del A[K:]
del B[K:]
del C[K:]

a = 0
b = 0
c = 0

r = []

if K < X:
    X = K
if K < Y:
    Y = K
if K < Z:
    Z = K 

for x in range(X):
    for y in range(Y):
        for z in range(Z):
            r.append(A[x] + B[y] + C[z])

r.sort(reverse=True)

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

Submission status: Time Limit Exceeded

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

list = []
i = -1
minlist = 0
for a in a_s:
    if minlist > (a + bs[0] + cs[0]):
        break
    for b in bs:
        if minlist > (a + b + cs[0]):
            break
        for c in cs:
            list.append(a + b + c)
            i += 1
            if  i > k:
                minlist = min(list)
            if minlist > list[i]:
                break
list.sort(reverse=True)
for i in range(k):
    print(list[i])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

sums = [As[x] + Bs[y] + Cs[z] for x, y, z in itertools.product(range(X), range(Y), range(Z)) if x * y * z <= K]
sums = sorted(sums, reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
import sys
X, Y, Z, K = map(int, input().split())
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))
C = list(map(int, sys.stdin.readline().split()))
AB = []
for i in range(X):
    for j in range(Y):
        AB.append(A[i] + B[j])
AB.sort(reverse = True)
ans = []
AB2 = AB[:min(X * Y + 1, K + 1)]
for ab in AB2:
    for c in C:
        ans.append(ab + c)
ans.sort(reverse = True)
for i in range(K):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import itertools

X, Y, Z, K = tuple([int(x) for x in str(input()).split(' ')])

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

out = sorted([A[a] + B[b] + C[c] for a, b, c in itertools.product(range(len(A)), range(len(B)), range(len(C))) if a*b*c <= K], reverse=True)

for x in out[:K]:
    print(x)