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 collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
Mod = 1000000007




def main(): #startline--------------------------------------------
    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()))
    Pre = []
    for i in range(min(X,K)):
        for j in range(min(Y,K)):
            Pre.append(A[i]+B[j])
    Pre.sort(reverse = True)
    Pre = Pre[:K]
    ans = []
    for i in range(min(Z,K)):
        for j in Pre:
            ans.append(j+C[i])
    ans.sort(reverse = True)
    for i in range(K):
        print(ans[i])



if __name__ == "__main__":
    main() #endline===============================================





def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n < 2 is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))):
        if prime[i] == 1:
            for j in range(2*i,n):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n):
        if prime[i] == 1:
            res.append(i)
    return res

class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py

    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
Mod = 1000000007




def main(): #startline--------------------------------------------
    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()))
    Pre = []
    for i in range(X):
        for j in range(Y):
            Pre.append(A[i]+B[j])
    Pre.sort(reverse = True)
    Pre = Pre[:K]
    ans = []
    for i in range(Z):
        for j in Pre:
            ans.append(j+C[i])
    ans.sort(reverse = True)
    for i in range(K):
        print(ans[i])



if __name__ == "__main__":
    main() #endline===============================================





def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n < 2 is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))):
        if prime[i] == 1:
            for j in range(2*i,n):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n):
        if prime[i] == 1:
            res.append(i)
    return res

class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py

    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
import sys
sys.setrecursionlimit(2**31-1)
input = sys.stdin.readline
write = sys.stdout.write
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
dbg = lambda *something : print(*something) if DEBUG is True else 0
DEBUG = True

def main():
    X,Y,Z,K = LMIIS()
    A = LMIIS()
    B = LMIIS()
    C = LMIIS()
    
    # A.sort(reverse=True)
    # B.sort(reverse=True)
    # C.sort(reverse=True)
    
    h = []
    from heapq import heappush,heappop
    for a in A:
        for b in B:
            for c in C:
                heappush(h,-(a+b+c))
    for _ in range(K):
        print(-heappop(h))
    # A.append(0)
    # B.append(0)
    # C.append(0)

    # # ai = bi = ci = 0

    # # for i in range(min(3000,X*Y*Z)):
    # #     print(A[ai],B[bi],C[ci])
    # #     print(A[ai]+B[bi]+C[ci])
    # #     nextai = ai + 1 if ai < X else ai
    # #     nextbi = bi + 1 if bi < Y else bi
    # #     nextci = ci + 1 if ci < Z else ci

    # #     #aiを更新する場合
    # #     if  A[nextai] >= B[nextbi]:
    # #         if A[nextai] >= C[nextci]:
    # #             ai = nextai
    # #         else:
    # #             ci = nextci
    # #     else:
    # #         if B[nextbi] >= C[nextci]:
    # #             bi = nextbi
    # #         else:
    # #             ci = nextci






    pass
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import heapq

X, Y, Z, K = [int(v) for v in input().split()]
A = [int(v) for v in input().split()]
B = [int(v) for v in input().split()]
C = [int(v) for v in input().split()]

h = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            heapq.heappush(h, (-(A[i]+B[j]+C[k]), A[i], B[j], C[k]))

for i in range(K):
    print(sum(heapq.heappop(h)[1:]))

Submission status: Time Limit Exceeded

Solution code:
from bisect import insort

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)
for i in range(Z-1, 0, -1) :
    C[i] -= C[i-1]

n = []
for x in range(X) :
    for y in range(Y) :
        n.append((A[x]+B[y]+C[0], 0))
n.sort()

for _ in range(K) :
    cur, z = n.pop()
    print(cur)
    if z < Z - 1 :
        z += 1
        insort(n, (cur+C[z], z))

Submission status: Time Limit Exceeded

Solution code:
from bisect import insort

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)
for i in range(Z-1, 0, -1) :
    C[i] -= C[i-1]

n = []
for x in range(X) :
    for y in range(Y) :
        n.append((A[x]+B[y]+C[0], (x, y, 0)))
n.sort()

for _ in range(K) :
    cur, (x, y, z) = n.pop()
    print(cur)
    if z < Z - 1 :
        z += 1
        insort(n, (cur+C[z], (x, y, z)))

Submission status: Time Limit Exceeded

Solution code:
from bisect import insort

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)

z = [[0] * Y for _ in range(X)]
n = []
for x in range(X) :
    for y in range(Y) :
        n.append((A[x]+B[y]+C[0], (x, y)))
n.sort()

for _ in range(K) :
    cur, (x, y) = n.pop()
    # print(cur, x, y)
    if z[x][y] < Z - 1 :
        z[x][y] += 1
        insort(n, (A[x]+B[y]+C[z[x][y]], (x, y)))
    print(cur)

Submission status: Time Limit Exceeded

Solution code:
import bisect
X, Y, X, 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()
B.sort()
C.sort()
ans1 = []
ans2 = []
for i in range(min(K,len(A))):
  for j in range(min(K,len(B))):
    ans1.append(A[i]+B[j])
ans1.sort(reverse=True)
for i in range(min(K,len(ans1))):
  for k in range(min(K,len(C))):
    ans2.append(ans1[i]+C[k])
ans2.sort(reverse=True)  
for i in range(K):
  print(ans2[i])

Submission status: Time Limit Exceeded

Solution code:
import bisect
X, Y, X, 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()
B.sort()
C.sort()
ans= []

for i in range(min(K,len(A))):
  for j in range(min(K,len(B))):
    for k in range(min(K,len(C))):
      tmp = A[i]+B[j]+C[k]
      bisect.insort_left(ans,tmp)
for i in range(K):
  print(ans[len(ans)-1-i])

Submission status: Time Limit Exceeded

Solution code:
import heapq
X, Y, Z, K = map(int, 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)
# done = [[[True for _ in range(Z+1)] for _ in range(Y+1)] for _ in range(Z+1)]
done = []

h = []
heapq.heappush(h, (-(A[0]+B[0]+C[0]), 0, 0, 0))  # リストaのheap化
done.append((0, 0, 0))

for _ in range(K):
    p, i, j, k = heapq.heappop(h)
    # print(h)
    print(-p)

    if (i+1, j, k) not in done and i+1 < X:
        # heap化されたリストaに要素xを追加
        heapq.heappush(h, (-(A[i+1]+B[j]+C[k]), i+1, j, k))
        # print(h)
        done.append((i+1, j, k))

    if (i, j+1, k) not in done and j+1 < Y:
        # heap化されたリストaに要素xを追加
        heapq.heappush(h, (-(A[i]+B[j+1]+C[k]), i, j+1, k))
        # print(h)
        done.append((i, j+1, k))

    if (i, j, k+1) not in done and k+1 < Z:
        # heap化されたリストaに要素xを追加
        heapq.heappush(h, (-(A[i]+B[j]+C[k+1]), i, j, k+1))
        # print(h)
        done.append((i, j, k+1))

Submission status: Time Limit Exceeded

Solution code:
import heapq
X, Y, Z, K = map(int, 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)
done = [[[True for _ in range(Z+1)] for _ in range(Y+1)] for _ in range(Z+1)]

h = []
heapq.heappush(h, (-(A[0]+B[0]+C[0]), 0, 0, 0))  # リストaのheap化
done[0][0][0] = False

for _ in range(K):
    p, i, j, k = heapq.heappop(h)
    # print(h)
    print(-p)

    if done[i+1][j][k] and i+1 < X:
        # heap化されたリストaに要素xを追加
        heapq.heappush(h, (-(A[i+1]+B[j]+C[k]), i+1, j, k))
        # print(h)
        done[i+1][j][k] = False

    if done[i][j+1][k] and j+1 < Y:
        # heap化されたリストaに要素xを追加
        heapq.heappush(h, (-(A[i]+B[j+1]+C[k]), i, j+1, k))
        # print(h)
        done[i][j+1][k] = False

    if done[i][j][k+1] and k+1 < Z:
        # heap化されたリストaに要素xを追加
        heapq.heappush(h, (-(A[i]+B[j]+C[k+1]), i, j, k+1))
        # print(h)
        done[i][j][k+1] = False

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k = (int(i) for i in 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 i in range(x):
  for j in range(y):
    tmp = a[i] + b[j]
    ab += [tmp]
ab.sort()
ab = ab[::-1][:k]
#print(ab)

ans = []
for i in range(len(ab)):
  for j in range(z):
    tmp = ab[i] + c[j]
    ans += [tmp]
ans.sort()
ans = ans[::-1][:k]
for i in ans:
  print(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(len(A)):
    for j in range(len(B)):
        L.append(A[i] + B[j])

L.sort(reverse=True)

ans_list = [0] * (10000000)

for i in range(min(K,len(L))):
    for j in range(len(C)):
        ans_list.append(L[i] + C[j])

ans_list.sort(reverse=True)


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

L = [0] * (1000000)

for i in range(len(A)):
    for j in range(len(B)):
        tmp = A[i] + B[j] 
        L[i*1000+j] = tmp

L.sort(reverse=True)

ans_list = [0] * (3000000)

for i in range(min(K,len(L))):
    for j in range(len(C)):
        tmp = L[i] + C[j]
        ans_list[i*1000+j] = tmp

ans_list.sort(reverse=True)


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

L = [0] * (4000000)

for i in range(len(A)):
    for j in range(len(B)):
        tmp = A[i] + B[j] 
        L[i*1000+j] = tmp

L.sort(reverse=True)

ans_list = [0] * (4000000)

for i in range(min(K,len(L))):
    for j in range(len(C)):
        tmp = L[i] + C[j]
        ans_list[i*1000+j] = tmp

ans_list.sort(reverse=True)


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

L = []

for i in range(len(A)):
    for j in range(len(B)):
        tmp = A[i] + B[j] 
        L.append(tmp)

L.sort(reverse=True)

ans_list =[]
for i in range(min(K,len(L))):
    for j in range(len(C)):
        tmp = L[i] + C[j]
        ans_list.append(tmp)

ans_list.sort(reverse=True)


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

L.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
import itertools


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()))
AB = [a + b for (a, b) in list(itertools.product(A, B))]
AB.sort(reverse=True)
ABC = [ab + c for (ab, c) in list(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 = 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 i in range(len(a)):
    for j in range(len(b)):
        ab.append(a[i] + b[j])

ab = sorted(ab, reverse=True)
ab = ab[:k]
abc = []
for i in range(len(ab)):
    for j in range(len(c)):
        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:
X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
AB = []
ABC = []
for i in A:
    for j in B:
        AB.append(i+j)
AB.sort(reverse = True)
for i in AB[:K+1]:
    for j in C:
        ABC.append(i+j)
ABC.sort(reverse = True)
for i in range(K):
    print(ABC[i])

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
AB=[]
append=AB.append
for i in range(min(K,X)):
    for j in range(min(K,Y)):
        append(A[i]+B[j])
AB.sort(reverse=True)
ABC=[]
appendd=ABC.append
for k in range(min(K,len(AB))):
    for l in range(min(K,Z)):
        appendd(AB[k]+C[l])
ABC.sort(reverse=True)
for m in range(K):
    print(ABC[m])

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,reverse=True)
B = sorted(B,reverse=True)
C = sorted(C,reverse=True)
#print(A,B,C)

list1 = []
a,b,c = 0,0,0

for a in range(X):
  for b in range(Y):
    for c in range(Z):
      list1.append(A[a]+B[b]+C[c])

for i in range(K):
  print(max(list1))
  list1.remove(max(list1))

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)

li = []
for i in range(len(a)):
    for j in range(len(b)):
        li.append(a[i]+b[j])

li.sort(reverse = True)

li1 = []
for i in range(len(li)):
    for j in range(len(c)):
        li1.append(li[i]+c[j])
li1.sort(reverse = True)
n = 1
while n < K+1:
    print(li1[n-1])
    n += 1

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K = map(int,input().split())
*A, = map(int,input().split())
*B, = map(int,input().split())
*C, = map(int,input().split())
AB = sorted(a+b for a in A for b in B)[::-1][:K]
ABC = sorted(ab+c for ab in AB for c in C)[::-1][:K]
print(*ABC,sep="\n")

Submission status: Time Limit Exceeded

Solution code:
X, Y, Z, K = map(int, input().split())
A, B, C = [sorted(list(map(int, input().split())))[:: -1][: K] for _ in range(3)]
D = []
for ai in A:
    for bi in B:
        D.append(ai + bi)

D = sorted(D)[:: -1][: K]

res = []
for di in D:
    for ci in C:
        res.append(di + ci)

res = sorted(res)[:: -1][: K]

for ans in res:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
X, Y, Z, K = map(int, input().split())
A, B, C = [sorted(list(map(int, input().split())))[:: -1][: K] for _ in range(3)]
res = []
for ai in A:
    for bi in B:
        for ci in C:
            res.append(ai + bi + ci)
res = sorted(res)[:: -1][: K]
for ans in res:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

X, Y, Z, K = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Cs = list(map(int, input().split()))

sumABs = [A + B for A, B in product(As, Bs)]
sumABs.sort(reverse=True)

sumABCs = [sumAB + C for sumAB, C in product(sumABs[:K], Cs)]
sumABCs.sort(reverse=True)

print('\n'.join(map(str, sumABCs[:K])))

Submission status: Time Limit Exceeded

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

ans = []
for abc in itertools.product(A, B, C):
    ans.append(sum(list(abc)))
ans = sorted(ans,reverse=True)[:K]
print("\n".join(map(str,ans)))

Submission status: Time Limit Exceeded

Solution code:
X, Y, Z, K = [int(c) for c in input().split()]
A, B, C = [sorted(map(int, input().split()), reverse=True) for _ in range(3)]

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

ABC = []
for ab in sorted(AB, reverse=True)[:K]:
    for c in C:
        ABC.append(ab+c)

for abc in sorted(ABC, reverse=True)[:K]:
    print(abc)

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k = map(int,input().split())
ax = [int(_) for _ in input().split()]
ay = [int(_) for _ in input().split()]
az = [int(_) for _ in input().split()]
ax.sort(reverse=True)
ay.sort(reverse=True)
az.sort(reverse=True)
INF = - 3 *10 ** 10
ax.extend([INF])
ay.extend([INF])
az.extend([INF])
l = [(ax[0]+ay[0]+az[0],0,0,0)]
for i in range(k):
    t = l.pop(0)
    print(t[0])
    if (ax[t[1]+1]+ay[t[2]]+az[t[3]],t[1]+1,t[2],t[3]) not in l:
        l.append((ax[t[1]+1]+ay[t[2]]+az[t[3]],t[1]+1,t[2],t[3]))
    if (ax[t[1]]+ay[t[2]+1]+az[t[3]],t[1],t[2]+1,t[3]) not in l:
        l.append((ax[t[1]]+ay[t[2]+1]+az[t[3]],t[1],t[2]+1,t[3]))    
    if (ax[t[1]]+ay[t[2]]+az[t[3]+1],t[1],t[2],t[3]+1) not in l:
        l.append((ax[t[1]]+ay[t[2]]+az[t[3]+1],t[1],t[2],t[3]+1))
    l.sort(key=lambda x:(-x[0],x[1],x[2],x[3]))

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k = map(int,input().split())
ax = [int(_) for _ in input().split()]
ay = [int(_) for _ in input().split()]
az = [int(_) for _ in input().split()]
ax.sort(reverse=True)
ay.sort(reverse=True)
az.sort(reverse=True)
INF = - 3 *10 ** 10
ax.extend([INF]*k)
ay.extend([INF]*k)
az.extend([INF]*k)
l = [(ax[0]+ay[0]+az[0],0,0,0)]
for i in range(k):
    t = l.pop(0)
    print(t[0])
    if (ax[t[1]+1]+ay[t[2]]+az[t[3]],t[1]+1,t[2],t[3]) not in l:
        l.append((ax[t[1]+1]+ay[t[2]]+az[t[3]],t[1]+1,t[2],t[3]))
    if (ax[t[1]]+ay[t[2]+1]+az[t[3]],t[1],t[2]+1,t[3]) not in l:
        l.append((ax[t[1]]+ay[t[2]+1]+az[t[3]],t[1],t[2]+1,t[3]))    
    if (ax[t[1]]+ay[t[2]]+az[t[3]+1],t[1],t[2],t[3]+1) not in l:
        l.append((ax[t[1]]+ay[t[2]]+az[t[3]+1],t[1],t[2],t[3]+1))
    l.sort(key=lambda x:(-x[0],x[1],x[2],x[3]))

Submission status: Time Limit Exceeded

Solution code:
a, b, c, d = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))
al = sorted(al, reverse=True)
bl = sorted(bl, reverse=True)
cl = sorted(cl, reverse=True)
q = [[al[0] + bl[0] + cl[0], 0, 0, 0]]
ans = [[al[0] + bl[0] + cl[0], 0, 0, 0]]
c = -1
#while True:
    #c += 1
for i in range(d):
    #print(c)
    #print(len(ans))
    s, aq, bq, cq = map(int, q.pop())
    if len(al) > aq+1:
        if [al[aq+1] + bl[bq] + cl[cq], aq+1, bq, cq] not in ans:
            q.append([al[aq+1] + bl[bq] + cl[cq], aq+1, bq, cq])
            ans.append([al[aq+1] + bl[bq] + cl[cq], aq+1, bq, cq])

    if len(bl) > bq+1:
        if [al[aq] + bl[bq+1] + cl[cq], aq, bq+1, cq] not in ans:
            q.append([al[aq] + bl[bq+1] + cl[cq], aq, bq+1, cq])
            ans.append([al[aq] + bl[bq+1] + cl[cq], aq, bq+1, cq])

    if len(cl) > cq+1:
        if [al[aq] + bl[bq] + cl[cq+1], aq, bq, cq+1] not in ans:
            q.append([al[aq] + bl[bq] + cl[cq+1], aq, bq, cq+1])
            ans.append([al[aq] + bl[bq] + cl[cq+1], aq, bq, cq+1])

    q = sorted(q)

    if len(ans) > d:
        ans = sorted(ans, reverse=True)
        if ans[d-1][0] > q[len(q)-1][0]:
            break

ans = sorted(ans, reverse=True)
for i in range(d):
    print(ans[i][0])

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k = map(int,input().split())
Alist = list(map(int,input().split()))
Blist = list(map(int,input().split()))
Clist = list(map(int,input().split()))

Alist.sort(reverse=True)
Blist.sort(reverse=True)
Clist.sort(reverse=True)

ABlist = []
for i in Alist[:k]:
    for j in Blist[:k]:
        ABlist.append(i + j)

ABlist.sort(reverse=True)

ABClist = []
for i in ABlist[:k]:
    for j in Clist[:k]:
        ABClist.append(i + j)

ABClist.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k = map(int,input().split())
Alist = list(map(int,input().split()))
Blist = list(map(int,input().split()))
Clist = list(map(int,input().split()))

Alist.sort(reverse=True)
Blist.sort(reverse=True)
Clist.sort(reverse=True)

ABlist = []
for i in Alist:
    for j in Blist:
        ABlist.append(i + j)

ABlist.sort(reverse=True)

if len(ABlist) > 3000:
    ABlist = ABlist[0:3000]

ABClist = []
for i in ABlist:
    for j in Clist:
        ABClist.append(i + j)

ABClist.sort(reverse=True)

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

Submission status: Time Limit Exceeded

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

ls1= []
for i in range(min(x,k)):
    for j in range(min(y,k)):
        ls1.append(a[i]+b[j])

ls1 = sorted(ls1,reverse=True)

ls1 = ls1[:k]
ls2 = []
for i in range(min(z,k)):
    for j in range(len(ls1)):
        ls2.append(c[i]+ls1[j])

ls2 = sorted(ls2,reverse=True)

for i in range(k):
    print(ls2[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()))
ls1= []
for i in range(x):
    for j in range(y):
        ls1.append(a[i]+b[j])

ls1 = sorted(ls1,reverse=True)

ls1 = ls1[:k]
ls2 = []
for i in range(z):
    for j in range(len(ls1)):
        ls2.append(c[i]+ls1[j])

ls2 = sorted(ls2,reverse=True)

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

Submission status: Time Limit Exceeded

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

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

ab = [ai + bi for bi in b[:k] for ai in a[:k]]
ab.sort(reverse=True)

s = [ci + abi for abi in ab[:k] for ci in c[:k]]
s.sort(reverse=True)

for si in s[:k]:
    print(si)

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 = [ai + bi for bi in b for ai in a]
ab.sort(reverse=True)
ab = ab[:k]

s = [ci + abi for abi in ab for ci in c]
s.sort(reverse=True)

for si in s[:k]:
    print(si)

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 = [ai + bi for bi in b for ai in a]
s = [ci + abi for abi in ab for ci in c]
s.sort(reverse=True)

for si in s[:k]:
    print(si)

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline

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

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

d = []
for aa in a[:k]:
    for bb in b[:k]:
        d.append(aa + bb)

d.sort(reverse=True)

e = []
for dd in d[:k]:
    for cc in c[:k]:
        e.append(dd + cc)

e.sort(reverse=True)

print(*e[:k], sep='\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()))

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

d = []
for aa in a[:k]:
    for bb in b[:k]:
        d.append(aa + bb)

d.sort(reverse=True)

e = []
for dd in d[:k]:
    for cc in c[:k]:
        e.append(dd + cc)

e.sort(reverse=True)

print(*e[:k], sep='\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()))

N = []
for a in A:
    for b in B:
        N.append(a + b)
N.sort(reverse=True)
N = N[:K]

M = []
for n in N:
    for c in C:
        M.append(n + c)
M.sort(reverse=True)
M = M[:K]

print(*M, sep="\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()))
ab=[]
for i in a:
  for j in b:
    ab.append(i+j)
ab.sort(reverse=True)
e=ab[:k]
abc=[]
for i in e:
  for j in c:
    abc.append(i+j)
abc.sort(reverse=True)
for _ in range(k):
  print(abc[_])

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
x, y, z, k = map(int, raw_input().split())
A = map(int, raw_input().split())
B = map(int, raw_input().split())
C = map(int, raw_input().split())
AB = []
for (a, b) in product(A, B):
    AB.append(a+b)
AB.sort(reverse=True)
C.sort(reverse=True)
ABC = []
for i in range(min(k+1, len(AB))):
    for j in range(len(C)):
        ABC.append(AB[i]+C[j])
ABC.sort(reverse=True)
for i in range(min(k, len(ABC))):
    print ABC[i]