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:
from heapq import heappop , heappush

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)

# 処理済みフラグ
confilm = []

q = [(-(A[0] + B[0] + C[0]) , 0,0,0)]

for _ in range(K) :
    val , i , j , k = heappop(q)

    print(-val)

    t = (i+1,j,k)
    if i + 1 < X and not t in confilm :
        heappush(q,(-(A[i+1] + B[j] + C[k]),) + t)
        confilm.append(t)

    t = (i,j+1,k)
    if j + 1 < Y and not t in confilm :
        heappush(q,(-(A[i] + B[j+1] + C[k]),) + t)
        confilm.append(t)

    t = (i,j,k+1)
    if k + 1 < Z and not t in confilm :
        heappush(q,(-(A[i] + B[j] + C[k+1]),) + t)
        confilm.append(t)

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

# 処理済みフラグ
confilm = []

q = [(-(A[0] + B[0] + C[0]) , 0,0,0)]
confilm.append((0,0,0))

for _ in range(K) :
    val , i , j , k = heapq.heappop(q)

    print(-val)

    t = (i+1,j,k)
    if i + 1 < X and not t in confilm :
        heapq.heappush(q,(-(A[i+1] + B[j] + C[k]),) + t)
        confilm.append(t)
    t = (i,j+1,k)
    if j + 1 < Y and not t in confilm :
        heapq.heappush(q,(-(A[i] + B[j+1] + C[k]),) + t)
        confilm.append(t)
    t = (i,j,k+1)
    if k + 1 < Z and not t in confilm :
        heapq.heappush(q,(-(A[i] + B[j] + C[k+1]),) + t)
        confilm.append(t)

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


# 処理済みフラグ
confilm = []

q = [(-(A[0] + B[0] + C[0]) , 0,0,0)]
confilm.append((0,0,0))

for _ in range(K) :
    val , i , j , k = heapq.heappop(q)

    print(-val)

    if i + 1 < X and not (i+1,j,k) in confilm :
        heapq.heappush(q,(-(A[i+1] + B[j] + C[k]), i+1,j,k))
        confilm.append((i+1,j,k))
    if j + 1 < Y and not (i,j+1,k) in confilm :
        heapq.heappush(q,(-(A[i] + B[j+1] + C[k]), i,j+1,k))
        confilm.append((i,j+1,k))
    if k + 1 < Z and not (i,j,k+1) in confilm :
        heapq.heappush(q,(-(A[i] + B[j] + C[k+1]), i,j,k+1))
        confilm.append((i,j,k+1))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

# A,Bでソート
D = list(itertools.product(A,B))
D.sort(key=lambda A : A[0] + A[1], reverse=True)

subD = D[:K]

E = list(itertools.product(D,C))

E.sort(key=lambda A : A[0][0] + A[0][1] + A[1], reverse=True)

for (i , j) , k in E[:K] :
    print(i+j+k)

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)

ans = []
check = [[[False for i in range(K)] for j in range(K)] for k in range(K)]
q = [[0, 0, 0, 0]]
check[0][0][0] = True
while len(q) > 0:
    i, j, k, step = q.pop(0)
    if step < min(K, 3000):
        ans.append(a[i]+b[j]+c[k])
        if i+1 < x:
            if not check[i+1][j][k]:
                check[i+1][j][k] = True
                q.append([i+1, j, k, step+1])
        if j+1 < y:
            if not check[i][j+1][k]:
                check[i][j+1][k] = True
                q.append([i, j+1, k, step+1])
        if k+1 < z:
            if not check[i][j][k+1]:
                check[i][j][k+1] = True
                q.append([i, j, k+1, step+1])

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

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

Q=[A[0]+B[0]+C[0]]
I=[[0,0,0]]
for i in range(k):
    qmax=max(Q)
    print(qmax)
    imax=Q.index(qmax)
    j,k,l=I[imax]
    del Q[imax]
    del I[imax]
    xt=0;yt=0;zt=0
    for jt,kt,lt in I:
        if (j+1,k,l)==(jt,kt,lt):
            xt+=1
        if (j,k+1,l)==(jt,kt,lt):
            yt+=1
        if (j,k,l+1)==(jt,kt,lt):
            zt+=1
    if xt==0 and j+1<x:
        Q.append(A[j+1]+B[k]+C[l])
        I.append([j+1,k,l])
    if yt==0 and k+1<y:
        Q.append(A[j]+B[k+1]+C[l])
        I.append([j,k+1,l])
    if zt==0 and l+1<z:
        Q.append(A[j]+B[k]+C[l+1])
        I.append([j,k,l+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()))

ab = []
for a in A:
	for b in B:
		ab += [a + b]

ab3000 = sorted(ab)[::-1][:3000]

abc = []
for ab in ab3000:
	for c in C:
		abc += [ab + c]

abc.sort(reverse=True)

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


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

ABC=[ab+c for ab in AB[:min(k,x*y)] for c in 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()))

AB=[0]*(x*y)
i=0
for a in A:
    for b in B:
        AB[i]=a+b
        i+=1

AB.sort(reverse=True)
ABC=[0]*(min(k,x*y)*z)
i=0
for ab in AB[:min(k,x*y)]:
    for c in C:
        ABC[i]=ab+c
        i+=1

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=[0]*(x*y)
i=0
for a in A:
    for b in B:
        AB[i]=a+b
        i+=1

AB=sorted(AB,reverse=True)[:min(k,x*y)]
ABC=[0]*(min(k,x*y)*z)
i=0
for ab in AB:
    for c in C:
        ABC[i]=ab+c
        i+=1

ABC=sorted(ABC,reverse=True)[:k]

for abc in ABC:
    print(abc)

Submission status: Time Limit Exceeded

Solution code:
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    X, Y, Z, K = MAP()
    A = sorted(LIST(), reverse=True)
    B = sorted(LIST(), reverse=True)
    C = sorted(LIST(), reverse=True)
    tmp = []
    for aa in range(X):
        for bb in range(Y):
            for cc in range(Z):
                if (aa + 1) * (bb + 1) * (cc + 1) <= K:
                    tmp.append(A[aa] + B[bb] + C[cc])
    tmp.sort(reverse=True)
    for kk in range(K):
        print(tmp[kk])

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# PDFで解法が4つも書いてある。これはその最初の解法

x,y,z,k =  list(map(int, input().split() ))

aa = list(map(int, input().split() ))
bb = list(map(int, input().split() ))
cc = list(map(int, input().split() ))

aa.sort(reverse = True)
bb.sort(reverse = True)
cc.sort(reverse = True)
# 降順＝大きい方から順

ab = []
for i in aa:
	for j in bb:
		ab.append(i + j)

# ab = [i + j for i in aa for j in bb]
# appendを使うと遅いので、二重の内包記法を使う 
# 外側でaaの要素、内側でbbの要素が動いていく。今回はどっちでも良いけど。
ab.sort(reverse = True)

max_len = min(k, len(ab))
abc = []
for i in ab[:max_len]:
	for j in cc:
		abc.append(i + j)

# abc = [i + j for i in ab[:max_len] for j in cc]
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()))

x_pls_y = []

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

xy_pls_z = []

for i in range(min(3000,x*y)):
    for j in range(z):
        xy_pls_z.append(x_pls_y[i]+c[j])
        
xy_pls_z.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
def my_solve(string):
    x, y, z, k, *abc = map(int, string.split())
    a, b, c = abc[:x], abc[x:x + y], abc[x + y:]
    ab = sorted([_a + _b for _b in b for _a in a])[-k:]
    *abc, = map(str, sorted([_ab + _c for _c in c for _ab in ab], reverse=True)[:k])
    return "\n".join(abc)


def solve(string):
    x, y, z, k, *abc = map(int, string.split())
    a, b, c = map(sorted, [abc[:x], abc[x:x + y], abc[x + y:]])
    ans = []
    for ia, _a in enumerate(a[::-1], start=1):
        for ib, _b in enumerate(b[::-1], start=1):
            for ic, _c in enumerate(c[::-1], start=1):
                if ia * ib * ic <= k:
                    ans.append(_a + _b + _c)
                else:
                    break
    return "\n".join(list(map(str, sorted(ans, reverse=True)[:k])))


if __name__ == '__main__':
    print(solve('\n'.join([input() for _ in range(4)])))

Submission status: Time Limit Exceeded

Solution code:
def solve(string):
    x, y, z, k, *abc = map(int, string.split())
    a, b, c = map(sorted, [abc[:x], abc[x:x + y], abc[x + y:]])
    ans = []
    for ia, _a in enumerate(a[::-1]):
        for ib, _b in enumerate(b[::-1]):
            for ic, _c in enumerate(c[::-1]):
                if ia * ib * ic < k:
                    ans.append(_a + _b + _c)
                else:
                    break
    return "\n".join(list(map(str, sorted(ans, reverse=True)[:k])))


if __name__ == '__main__':
    print(solve('\n'.join([input() for _ in range(4)])))

Submission status: Time Limit Exceeded

Solution code:
def solve(string):
    x, y, z, k, *abc = map(int, string.split())
    a, b, c = map(sorted, [abc[:x], abc[x:x + y], abc[x + y:]])
    ans = []
    for ia, _a in enumerate(a[::-1]):
        for ib, _b in enumerate(b[::-1]):
            for ic, _c in enumerate(c[::-1]):
                if ia * ib * ic < k:
                    ans.append(_a + _b + _c)
    return "\n".join(list(map(str, sorted(ans, reverse=True)[:k])))


if __name__ == '__main__':
    print(solve('\n'.join([input() for _ in range(4)])))

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 = [0] * (X * Y)
E = [0] * (K * Z)
m, n = 0, 0

for i in range(X):
    for j in range(Y):
        D[m] = A[i] + B[j]
        m += 1

for k in range(len(sorted(D)[:: -1][: K])):
    for l in range(Z):
        E[n] = sorted(D)[:: -1][: K][k] + C[l]
        n += 1

for p in range(K):
    print(sorted(E)[:: -1][p])

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = list(map(int, input().split()))
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))
clist = list(map(int, input().split()))
alist.sort(reverse=True)
blist.sort(reverse=True)
clist.sort(reverse=True)
delist = []
for a in range(x) :
    for b in range(y) :
        if a+b > k :
            break
        for c in range(z) :
            if a+b+c > k :
                break
            else :
                delist.append(alist[a]+blist[b]+clist[c])
delist.sort(reverse=True)
for n in delist[:k] :
    print(n)

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = list(map(int, input().split()))
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))
clist = list(map(int, input().split()))
delist = []
for a in alist :
    for b in blist :
        for c in clist :
            delist.append(a+b+c)
delist.sort(reverse=True)
for n in delist[:k] :
    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()))

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

F = []
for k in range(len(E)):
    for l in range(Z):
        F.append(E[k]+C[l])

F = sorted(F, reverse=True)

for i in range(K):
    print(F[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())
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[:k]
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 = [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 A:
	for b in B:
		AB.append(a+b)

AB.sort(reverse=True)
C.sort(reverse=True)

#print(AB)
#print(C)

ABC = []

if len(AB) < k:
	p = len(AB)
else:
	p = k

if len(C) < k:
	q = len(C)
else:
	q = k

for i in range(p):
	for j in range(q):
		ABC.append(AB[i]+C[j])

ABC.sort(reverse=True)
#print(ABC)

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()))
ans=[]
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
for i in range(min(x,k)):
  for j in range(min(y,k)):
    for l in range(min(z,k)):
      if i*j*l>k:
        break
      else:
        ans.append(a[i]+b[j]+c[l])
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)
D = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if i * j * k > K:
                break
            D.append(A[i] + B[j] + C[k])
D.sort(reverse=True)
for ans in D[:K]:
    print(ans)

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)
D = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if i + j + k > K:
                break
            D.append(A[i] + B[j] + C[k])
D.sort(reverse=True)
for ans in D[:K]:
    print(ans)

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

e = []

cnt = 0
for va in a:
    for vb in b:
        heapq.heappush(e, -(va+vb))

d = []
while len(e):
    ve = -heapq.heappop(e)
    for vc in c:
        heapq.heappush(d, -(ve+vc))

for i in range(k):
    print(-heapq.heappop(d))

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()))[:k]

e = []

for va in a:
    for vb in b:
        e.append(va+vb)

e.sort(reverse=True)

e = e[:k]

d = []
for vc in c:
    for ve in e:
        d.append(vc+ve)

d.sort(reverse=True)
d = d[:k]

for vd in d:
    print(vd)

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

e = []

for va in a:
    for vb in b:
        e.append(va+vb)

e.sort(reverse=True)

e = e[:k]

d = []
for vc in c:
    for ve in e:
        d.append(vc+ve)

d.sort(reverse=True)
d = d[:k]

for vd in d:
    print(vd)

Submission status: Time Limit Exceeded

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

L=[xx+yy for xx in x for yy in y ]
L=sorted(L,reverse=True)

if K > X*Y:
  LL=[l+zz for l in L for zz in z]
  [print(i) for i in sorted(LL,reverse=True)]   
else:
  LL=[l+zz for l in L[:K] for zz in z]
  LL=sorted(LL,reverse=True)
  [print(ll) for k,ll in zip(range(K),LL)]

Submission status: Time Limit Exceeded

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

L=[]
for xx in x:
  for yy in y:
    L.append(yy+xx)
L=sorted(L,reverse=True)

if K > X*Y:
  LL=[]
  for l in L:
    for zz in z:
      LL.append(l+zz)
  [print(i) for i in sorted(LL,reverse=True)]   
else:
  LL=[]
  for l in L[:K]:
    for zz in z:
      LL.append(l+zz)
  LL=sorted(LL,reverse=True)
  for k,ll in zip(range(K),LL):
    print(ll)

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 = sorted(A, key = lambda x:-x)
B = sorted(B, key = lambda x:-x)
C = sorted(C, key = lambda x:-x)

AB = [0] * (X * Y)

index = 0
for i in range(len(A)):
    for j in range(len(B)):
        AB[index] = A[i] + B[j]
        index += 1

AB = sorted(AB, key = lambda x:-x)
AB = AB[0:3010]

ABC = [0] * (3010 * Z)
index = 0

for i in AB:
    for j in range(len(C)):
        if j > 3010:
            break
        ABC[index] = i + C[j]
        index += 1

ABC = sorted(ABC, key = lambda x:-x)
for i in range(0,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 = sorted(A, key = lambda x:-x)
B = sorted(B, key = lambda x:-x)
C = sorted(C, key = lambda x:-x)

AB = [0] * (X * Y)

index = 0
for i in range(len(A)):
    for j in range(len(B)):
        AB[index] = A[i] + B[j]
        index += 1

AB = sorted(AB, key = lambda x:-x)
AB = AB[0:3010]

ABC = [0] * (3010 * Z)
index = 0

for i in AB:
    for j in C:
        ABC[index] = i + j
        index += 1

ABC = sorted(ABC, key = lambda x:-x)
for i in range(0,K):
    print(ABC[i])

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline

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()))
a_list.sort(reverse=True)
b_list.sort(reverse=True)
c_list.sort(reverse=True)
tmp_list = [a+b for a in a_list for b in b_list]
tmp_list.sort(reverse=True)
honest_list = [tmp+c for tmp in tmp_list for c in c_list]
honest_list.sort(reverse=True)
for h in honest_list[:k]:
    print(h)

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline

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()))
a_list.sort(reverse=True)
b_list.sort(reverse=True)
c_list.sort(reverse=True)
tmp_list = []
for a in a_list:
    for b in b_list:
            tmp_list.append(a+b)
tmp_list.sort(reverse=True)
honest_list = []
for tmp in tmp_list[:k]:
    for c in c_list:
        honest_list.append(tmp+c)
honest_list.sort(reverse=True)
for h in honest_list[:k]:
    print(h)

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()))
e=[]
for ai in a:
    for bi in b:
        e.append(ai+bi)
e.sort(reverse=True)
e=e[:k]
ans=[]
for ci in c:
    for ei in e:
        ans.append(ci+ei)
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

ab = [sum(e) for e in itertools.product(A, B)]
ab.sort(reverse=True)
C.sort(reverse=True)
abc = [sum(e) for e in itertools.product(ab[:K], C[:K])]
abc.sort(reverse=True)
for i in range(K):
    print(abc[i])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

ab = [sum(e) for e in itertools.product(A, B)]
ab.sort(reverse=True)

abc = [sum(e) for e in itertools.product(ab[:K], 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()))

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


ab.sort(reverse=True)
c.sort(reverse=True)

abc = []
for i in range(min(k, x * y)):
    for j in range(z):
        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:
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()))

sums = []
for ai in a:
    for bi in b:
        for ci in c:
            heapq.heappush(sums, -(ai + bi + ci))

cnt = 0
while (cnt < k):
    print(-heapq.heappop(sums))
    cnt += 1

Submission status: Time Limit Exceeded

Solution code:
def get_integers(n):
    '''
    Reads in one line of input that contains n integers.
    Returns a list of n integers
    '''
    s = input()
    numbers = s.split(' ')
    r = []
    for x in numbers:
        r.append(int(x))
    return  r

numbers = get_integers(4)
X = int(numbers[0])
Y = int(numbers[1])
Z = int(numbers[2])
K = int(numbers[3])

A = get_integers(X)
B = get_integers(Y)
C = get_integers(Z)

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

for i in range(1, K+1):
    print(l[len(l) - i])

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np


def main():
    x, y, z, k = [int(n) for n in input().split()]
    va = np.array(sorted([int(n) for n in input().split()], reverse=True))[:, np.newaxis]
    vb = np.array(sorted([int(n) for n in input().split()], reverse=True))[np.newaxis, :]
    xy = min(x*y, k)
    vac = np.array(sorted((va + vb).reshape(-1), reverse=True)[:xy]).reshape(xy, 1)
    vc = np.array(sorted([int(n) for n in input().split()], reverse=True))[np.newaxis, :]
    xyz = min(x*y*z, k)
    print(*(sorted((vac + vc).reshape(-1), reverse=True)[:xyz]), sep="\n")


main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np


def main():
    x, y, z, k = [int(n) for n in input().split()]
    a = sorted([int(n) for n in input().split()], reverse=True)
    b = sorted([int(n) for n in input().split()], reverse=True)
    c = sorted([int(n) for n in input().split()], reverse=True)
    result = [a[ai] + b[bi] + c[ci]
              for ai in range(x) for bi in range(y) for ci in range(z)
              if (ai + 1) * (bi + 1) * (ci + 1) <= k]
    print(*(sorted(result, reverse=True))[:k], sep="\n")


main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np


def main():
    x, y, z, k = [int(n) for n in input().split()]
    a = sorted([int(n) for n in input().split()], reverse=True)
    b = sorted([int(n) for n in input().split()], reverse=True)
    c = sorted([int(n) for n in input().split()], reverse=True)
    result = [a[ai] + b[bi] + c[ci] for ai in range(x) for bi in range(y) for ci in range(z) if ai * bi * ci <= k]
    print(*(sorted(result, reverse=True))[:k], sep="\n")


main()

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int, input().split())
*xl, = list(map(int, input().split()))
*yl, = list(map(int, input().split()))
*zl, = list(map(int, input().split()))
xl.sort(reverse=True)
yl.sort(reverse=True)
zl.sort(reverse=True)

point = []

for xi in range(min(x, k)):
    for yi in range(min(y, k)):
        for zi in range(min(z, k)):
            point.append(xl[xi] + yl[yi] + zl[zi])

point.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int, input().split())
*xl, = list(map(int, input().split()))
*yl, = list(map(int, input().split()))
*zl, = list(map(int, input().split()))
point = []

for xi in range(x):
    for yi in range(y):
        for zi in range(z):
            point.append(xl[xi] + yl[yi] + zl[zi])

point.sort(reverse=True)

for i in range(k):
    print(point[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)
T=min(A[min(K,len(A)-1)],B[min(K,len(B))-1],C[min(K,len(C)-1)])

L=[]
for i in range(min(K,len(A))):
    if A[i]<T:continue
    for j in range(min(K,len(B))):
        if B[i]<T:continue
        for k in range(min(K,len(C))):
            if C[i]<T:continue
            L.append(A[i]+B[j]+C[k])
L.sort(reverse=True)
for p in range(K):
    print(L[p])

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)
L=[]
for i in range(min(3002,len(A))):
    for j in range(min(3002,len(B))):
        for k in range(min(3002,len(C))):
            L.append(A[i]+B[j]+C[k])
L.sort(reverse=True)
for p in range(K):
    print(L[p])

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()))
e=[]
for ai in a:
    for bi in b:
        e.append(ai+bi)
e.sort(reverse=True)
e=e[:min(3001,x*y*z+1)]
ans=[]
for ci in c:
    for ei in e:
        ans.append(ci+ei)
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()))
e=[]
for ai in a:
    for bi in b:
        e+=[ai+bi]
e.sort(reverse=True)
e=e[:k]
ans=[]
for ci in c:
    for ei in e:
        ans+=[ci+ei]
ans.sort(reverse=True)
ans=ans[:k]
for ansi in ans:
    print(ansi)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[1]:


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()))
"""
2 2 2 8
4 6
1 5
3 8
"""


# In[12]:


#import numpy as np
import itertools
import math


# In[20]:


sA = sorted(A, reverse=True)
sB = sorted(B, reverse=True)
sC = sorted(C, reverse=True)

ps = list(itertools.product(A[:K], B[:K], C[:K]))
les = len(ps)


# In[22]:


mem = [0]*les
for i in range(les):
    mem[i] = sum(ps[i])
    
mem = sorted(mem, reverse=True)
for i in range(K):
    print(mem[i])


# In[ ]: