Problem:


Score: 400 points

Problem Statement

The Patisserie AtCoder sells cakes with number-shaped candles.
There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively.
Each cake has an integer value called deliciousness, as follows:

The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.

The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.

The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.

Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.

There are X \times Y \times Z such ways to choose three cakes.

We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.

Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Constraints

1 \leq X \leq 1 \ 000

1 \leq Y \leq 1 \ 000

1 \leq Z \leq 1 \ 000

1 \leq K \leq \min(3 \ 000, X \times Y \times Z)

1 \leq A_i \leq 10 \ 000 \ 000 \ 000

1 \leq B_i \leq 10 \ 000 \ 000 \ 000

1 \leq C_i \leq 10 \ 000 \ 000 \ 000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z

Output

Print K lines. The i-th line should contain the i-th value stated in the problem statement.

Sample Input 1

2 2 2 8
4 6
1 5
3 8

Sample Output 1

19
17
15
14
13
12
10
8

There are 2 \times 2 \times 2 = 8 ways to choose three cakes, as shown below in descending order of the sum of the deliciousness of the cakes:

(A_2, B_2, C_2): 6 + 5 + 8 = 19

(A_1, B_2, C_2): 4 + 5 + 8 = 17

(A_2, B_1, C_2): 6 + 1 + 8 = 15

(A_2, B_2, C_1): 6 + 5 + 3 = 14

(A_1, B_1, C_2): 4 + 1 + 8 = 13

(A_1, B_2, C_1): 4 + 5 + 3 = 12

(A_2, B_1, C_1): 6 + 1 + 3 = 10

(A_1, B_1, C_1): 4 + 1 + 3 = 8

Sample Input 2

3 3 3 5
1 10 100
2 20 200
1 10 100

Sample Output 2

400
310
310
301
301

There may be multiple combinations of cakes with the same sum of the deliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and the sum of A_3, B_3, C_1 are both 301.
However, they are different ways of choosing cakes, so 301 occurs twice in the output.

Sample Input 3

10 10 10 20
7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488
1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338
4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736

Sample Output 3

23379871545
22444657051
22302177772
22095691512
21667941469
21366963278
21287912315
21279176669
21160477018
21085311041
21059876163
21017997739
20703329561
20702387965
20590247696
20383761436
20343962175
20254073196
20210218542
20150096547

Note that the input or output may not fit into a 32-bit integer type.



Sample input:
2 2 2 8
4 6
1 5
3 8


Sample output:
19
17
15
14
13
12
10
8

Submission status: Time Limit Exceeded

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

max_k_list = []
for a_i in range(X):
    for b_i in range(Y):
        for c_i in range(Z):
            if (a_i + 1) * (b_i + 1) * (c_i + 1) <= K:
                max_k_list.append(a_list[a_i] + b_list[b_i] + c_list[c_i])

max_k_list.sort(reverse = True)
[print(k) for k in max_k_list[:K]]

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(" ")]
top_bc = []

for bi in b:
    for ci in c:
        top_bc.append(bi + ci)

top_bc = sorted(top_bc, reverse=True)

top_ak = []

for ki in top_bc[0:k]:
    for ai in a:
        top_ak.append(ai + ki)

top_ak = sorted(top_ak, reverse=True)

for top_k in top_ak[0:k]:
    print(top_k)

Submission status: Time Limit Exceeded

Solution code:
I=lambda:map(int,input().split());*_,k=I();s='sorted(i+j for i in I()for j in %s)[:-k-1:-1]';*a,=I();b=eval(s%'a');print(*eval(s%'b'))

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K = map(int,input().split())
#A = np.empty(X,dtype=int)
#B = np.empty(Y,dtype=int)
#C = np.empty(Z,dtype=int)
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 = [ a+b for a in A for b in B] 
ABC = [ab+c for ab in AB for c in C]
ABCs = sorted(ABC, reverse=True)[:K]
for i in range(K):
  print(ABCs[i])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
X,Y,Z,K = map(int,input().split())
#A = np.empty(X,dtype=int)
#B = np.empty(Y,dtype=int)
#C = np.empty(Z,dtype=int)
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))
A.sort()
B.sort()
C.sort()

AB = [ a+b for a in A for b in B] 
ABC = [ab+c for ab in AB for c in C]
ABC.sort()
ABC = ABC[::-1]
for i in range(K):
  print(ABC[i])

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
cc = list(map(int, input().split()))

ab = sorted(a+b for a in aa for b in bb)[:-k-1:-1]
abc = sorted(s+c for s in ab[:k] for c in cc)[:-k-1:-1]
print(*abc, sep='\n')

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

ab = sorted(a+b for a in aa for b in bb)[:-k-1:-1]
abc = sorted(s+c for s in ab for c in cc)[:-k-1:-1]
print(*abc, 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)
AB =[]
ABC = []
for i in range(X):
    for j in range(Y):
        ab = A[i] + B[j]
        AB.append(ab)
AB.sort(reverse = True)
m = min(K, X*Y)
for i in range(m):
    for j in range(Z):
        abc = AB[i] + C[j]
        ABC.append(abc)
ABC.sort(reverse = True)
for i in range(K):
    print(ABC[i])

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
x,y,z,k = input().split()
x = int(x)
y = int(y)
z = int(z)
k = int(k)
a = input().split()
b = input().split()
c = input().split()
for i in range(x):
    a[i] = int(a[i])
for i in range(y):
    b[i] = int(b[i])
for i in range(z):
    c[i] = int(c[i])
def max(x,y,k):
    if x * y < k:
        return x * y
    else:
        return k
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
s = [0] * (x * y)
l = 0
for i in range(x):
    for j in range(y):
        s[l] = a[i] + b[j]
        l += 1
s.sort(reverse=True)
s2 = [0] * (z * max(x,y,k))
l = 0
for i in range(z):
    for j in range(max(x,y,k)):
        s2[l] = c[i] + s[j]
        l += 1
s2.sort(reverse=True)
for i in range(k):
    print(s2[i])

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

# A,Bでソート
score_ab = []
for a in aa:
    for b in bb:
        # bisect.insort_right(score_ab, a+b)
        score_ab.append(a+b)
score_ab = sorted(score_ab)[::-1][:k]
# print(score_ab[::-1])
# A,B合計値の上位K個とCでソート
score = []
for s in score_ab:
    for c in cc:
        # bisect.insort_right(score, s+c)
        score.append(s+c)
score = sorted(score)[::-1][:k]
for s in score:
    print(s)

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
x,y,z,k = input().split()
x = int(x)
y = int(y)
z = int(z)
k = int(k)
a = input().split()
b = input().split()
c = input().split()
for i in range(x):
    a[i] = int(a[i])
for i in range(y):
    b[i] = int(b[i])
for i in range(z):
    c[i] = int(c[i])
def max(x,y,k):
    if x * y < k:
        return x * y
    else:
        return k
s = []
for i in range(x):
    for j in range(y):
        s.append(a[i] + b[j])
s.sort(reverse=True)
s2 = []
for i in range(z):
    for j in range(max(x,y,k)):
        s2.append(c[i] + s[j])
s2.sort(reverse=True)
for i in range(k):
    print(s2[i])

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
x,y,z,k = input().split()
x = int(x)
y = int(y)
z = int(z)
k = int(k)
a = input().split()
b = input().split()
c = input().split()
for i in range(x):
    a[i] = int(a[i])
for i in range(y):
    b[i] = int(b[i])
for i in range(z):
    c[i] = int(c[i])
def max(x,y,k):
    if x * y < k:
        return x * y
    else:
        return k
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
s = []
for i in range(x):
    for j in range(y):
        s.append(a[i] + b[j])
s.sort(reverse=True)
s2 = []
for i in range(z):
    for j in range(max(x,y,k)):
        s2.append(c[i] + s[j])
s2.sort(reverse=True)
for i in range(k):
    print(s2[i])

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K = map(int, input().split())
a_list = [int(i) for i in input().split()]
b_list = [int(i) for i in input().split()]
c_list = [int(i) for i in input().split()]
a_list.sort(reverse = True)
b_list.sort(reverse = True)
c_list.sort(reverse = True)
total_list = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i+1)*(j+1)*(k+1) <= K:
                total_list.append(a_list[i] + b_list[j] + c_list[k])
total_list =  sorted(total_list, reverse = True)
for i in range(K):
    print(total_list[i])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-


def main():
    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)
    count = min(x * z, k)
    ac = list()
    ans = list()

    for ai in a:
        for ci in c:
            ac.append(ai + ci)

    for bi in b:
        for ac_i in sorted(ac, reverse=True)[:count]:
            ans.append(bi + ac_i)

    for j in sorted(ans, reverse=True)[:k]:
        print(j)


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


array = []
tmp = []

for a in A:
  for b in B:
    tmp.append(a+b)
tmp.sort()
tmp.reverse()

for i in tmp:
  for c in C:
    array.append(i+c)

array.sort()
array.reverse()

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

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K = map(int, input().split())
a_list = [int(i) for i in input().split()]
b_list = [int(i) for i in input().split()]
c_list = [int(i) for i in input().split()]
a_b_total = [0 for _ in range(X*Y)]
for i in range(X):
    for j in range(Y):
        a_b_total[i*Y+j] = a_list[i] + b_list[j]
a_b_total.sort(reverse = True)
a_b_c_total = [0 for _ in range(min(K,X*Y)*Z)]
for i in range(min(K,X*Y)):
    for j in range(Z):
        a_b_c_total[i*Z+j] = a_b_total[i] + c_list[j]
a_b_c_total.sort(reverse = True)
for i in range(K):
    print(a_b_c_total[i])

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K = map(int, input().split())
a_list = [int(i) for i in input().split()]
b_list = [int(i) for i in input().split()]
c_list = [int(i) for i in input().split()]
a_b_total = [0 for _ in range(X*Y)]
for i in range(X):
    for j in range(Y):
        a_b_total[i*Y+j] = a_list[i] + b_list[j]
a_b_total.sort(reverse = True)
a_b_c_total = [0 for _ in range(K*Z)]
for i in range(min(K,X*Y)):
    for j in range(Z):
        a_b_c_total[i*Z+j] = a_b_total[i] + c_list[j]
a_b_c_total.sort(reverse = True)
for i in range(K):
    print(a_b_c_total[i])

Submission status: Time Limit Exceeded

Solution code:
lst = list(map(int, input().split()))
a_lst = list(map(int, input().split()))
b_lst = list(map(int, input().split()))
c_lst = list(map(int, input().split()))

k = lst[3]
candidate = []
for n, a in enumerate(sorted(a_lst, reverse=True)):
    for m, b in enumerate(sorted(b_lst, reverse=True)):
        if (n+1)*(m+1) > k:
            break
        else:
            for l, c in enumerate(sorted(c_lst, reverse=True)):
                if (n+1)*(m+1)*(l+1) > k:
                    break
                else:
                    candidate.append(a+b+c)
for i in sorted(candidate, reverse=True)[:k]:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
lst = list(map(int, input().split()))
a_lst = list(map(int, input().split()))
b_lst = list(map(int, input().split()))
c_lst = list(map(int, input().split()))

k = lst[3]
candidate = []
for n, a in enumerate(sorted(a_lst, key = lambda x: -x)):
    for m, b in enumerate(sorted(b_lst, key = lambda x: -x)):
        for l, c in enumerate(sorted(c_lst, key = lambda x: -x)):
            if (n+1)*(m+1)*(l+1) <= k:
                candidate.append(a+b+c)
for i in sorted(candidate, key = lambda x: -x)[:k]:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K = list(map(int,input().split()))
import numpy as np
A = np.array([(sorted(list(map(int,input().split())))[::-1]) for i in range(3)])
from itertools import product
AB = sorted([sum(i) for i in list(product(A[0],A[1]))])[::-1][:K]
for i in sorted([sum(i) for i in list(product(AB,A[2]))])[::-1][:K]:
    print(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()))


ab_sum = [0] * (X * Y)
i = 0
for a in a_list:
    for b in b_list:
        ab_sum[i] = a + b
        i += 1
ab_sum.sort(reverse = True)

answer_sums = [0] * (K * Z)
i = 0
for e in ab_sum[:K]:
    for c in c_list:
        answer_sums[i] = e + c
        i += 1
answer_sums.sort(reverse = True)
[print(num) for num in answer_sums[:K]]

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

ab_items = []
for a in a_list:
    for b in b_list:
        ab_items.append(a + b)

ab_items.sort(reverse=True)
ab_items = ab_items[:K + 1]

ans = []
for c in c_list:
    for ab in ab_items:
        ans.append(c + ab)

ans.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
lst = list(map(int, input().split()))
a_lst = list(map(int, input().split()))
b_lst = list(map(int, input().split()))
c_lst = list(map(int, input().split()))

k = lst[3]
ab_lst = []
for i in a_lst:
    for j in b_lst:
        ab_lst.append(i+j)
ab_lst = sorted(ab_lst, key = lambda x: -x)[:k]
abc_lst = []
for i in ab_lst:
    for j in c_lst[:k]:
        abc_lst.append(i+j)
for i in sorted(abc_lst, key = lambda x: -x)[:k]:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
lst = list(map(int, input().split()))
a_lst = list(map(int, input().split()))
b_lst = list(map(int, input().split()))
c_lst = list(map(int, input().split()))

ab_lst = []
for i in a_lst:
    for j in b_lst:
        ab_lst.append(i+j)
ab_lst = sorted(ab_lst, key = lambda x: -x)[:lst[3]]
abc_lst = []
for i in ab_lst:
    for j in c_lst:
        abc_lst.append(i+j)
for i in sorted(abc_lst, key = lambda x: -x)[:lst[3]]:
    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()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

sum_ab=[]

for i in a:
    for j in b:
      sum_ab.append(i+j)

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

sum_abc=[]
for i in c:
    for j in sum_ab:
      sum_abc.append(i+j)

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

ab.sort()
ab.reverse()

abc = []
for i in range(K):
    if len(ab) == i:
        break
    for j in range(Z):
        abc.append(ab[i] + C[j])

abc.sort()
abc.reverse()

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)

sum_ab=[]

for i in a:
    for j in b:
      sum_ab.append(i+j)

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

sum_abc=[]
for i in sum_ab:
    for j in c:
      sum_abc.append(i+j)

sum_abc.sort(reverse=True)
for v in sum_abc[:k]:
    print(v)

Submission status: Time Limit Exceeded

Solution code:
def main():
    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)
    L = []
    for a in A:
        for b in B:
            L.append(a + b)
    LL = []
    for ab in L:
        for c in C:
            LL.append(ab + c)
    for x in sorted(LL, reverse=True)[:K]:
        print(x)


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

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

ab.sort()
ab.reverse()

abc = []
for i in range(K):
    if len(ab) == i:
        break
    for j in range(Z):
        abc.append(ab[i] + C[j])

abc.sort()
abc.reverse()

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)

sum_ab=[]

for i in a:
    for j in b:
      sum_ab.append(i+j)

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

sum_abc=[]
for i in sum_ab:
    for j in c:
      sum_abc.append(i+j)

sum_abc.sort(reverse=True)
for v in sum_abc[:k]:
    print(v)

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)

a=a[:k]
b=b[:k]

sum_ab=[]

for i in a:
    for j in b:
      sum_ab.append(i+j)

sorted(sum_ab,reverse=True)

sum_abc=[]
for i in sum_ab:
    for j in c:
      sum_abc.append(i+j)

sum_abc.sort(reverse=True)
for v in sum_abc[:k]:
    print(v)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# なんかおかしい！！
import math
import sys
import itertools
import numpy as np

 
# なんこか入力
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()
b.sort()
c.sort()
#cake = [[0 for i in range(3)] for j in range(3000)]
#cake[0][0]=x-1
#cake[0][1]=y-1
#cake[0][2]=z-1
#print(a[x-1]+b[y-1]+c[z-1])
#print(a[cake[0][0]],b[cake[0][1]],c[cake[0][2]])
t = [[-1,-1,-1,-1] for i in range(3*k)]
t[0] = [a[x-1]+b[y-1]+c[z-1],x-1,y-1,z-1]
t_a = 1
#print(s)
 
for i in range(0,k):
    ma = 0
    ma_j = -1
    temp = [-1,-1,-1,-1]
    for j in range(len(t)):
        if ma <= t[j][0] :
            temp = t[j]
            ma = t[j][0]
            ma_j = j
#    print(temp)
    print(temp[0])
    t[ma_j][0]=0
#    print("s=",s)
#    print("t=",t)
#    print(temp)
    f =1
    if temp[1] > 0:
        for j in range(len(t)):
            if temp[1]-1 == t[j][1] and temp[2]==t[j][2] and temp[3]==t[j][3]:
                f = 0
                break
        if f == 1:
            t[t_a] = [a[temp[1]-1]+b[temp[2]]+c[temp[3]],temp[1]-1,temp[2],temp[3]]
            t_a += 1
    f =1
    if temp[2] > 0:
        for j in range(len(t)):
            if temp[1] == t[j][1] and temp[2]-1==t[j][2] and temp[3]==t[j][3]:
                f = 0
                break
        if f == 1:
            t[t_a] = [a[temp[1]]+b[temp[2]-1]+c[temp[3]],temp[1],temp[2]-1,temp[3]]
            t_a += 1
    f =1
    if temp[3] > 0:
        for j in range(len(t)):
            if temp[1] == t[j][1] and temp[2]==t[j][2] and temp[3]-1==t[j][3]:
                f = 0
                break
        if f == 1:
            t[t_a] = [a[temp[1]]+b[temp[2]]+c[temp[3]-1],temp[1],temp[2],temp[3]-1]
            t_a += 1

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k=map(int,input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
ab =[]
for aa in a:
    for bb in b:
        ab.append(aa+bb)
ab.sort()
ab.reverse()
ab = ab[:k]
cd =[]
for x in ab:
    for cc in c:    
        cd.append(x+cc)
cd.sort()
cd.reverse()
for i in range(k):
    print(cd[i])

Submission status: Time Limit Exceeded

Solution code:
import itertools
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()]

D = []
for a, b in itertools.product(A, B):
    d = a + b
    D.append(d)
D.sort(reverse = True)

E = []
for c, d in itertools.product(C, D[:K]):
    e = c + d
    E.append(e)
    
E.sort(reverse = True)
for e in E[:K]:
    print(e)

Submission status: Time Limit Exceeded

Solution code:
import itertools
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()]

D = []
for a, b in itertools.product(A, B):
    d = a + b
    D.append(d)

E = []
for c, d in itertools.product(C, D):
    e = c + d
    E.append(e)
    
E.sort(reverse = True)
for e in E[:K]:
    print(e)

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k=map(int,input().split())
a,b,c=[list(map(int,input().split())) for i in range(3)]
l=[i+j for i in a for j in b]
l.sort(reverse=True)
maxl=[i+j for i in l[:k] for j in c]
maxl.sort(reverse=True)
for a in maxl[:k]:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
x,y,z,q=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)
 
def bisect(l,r):
  cnt=(l+r)//2
  if cnt==l:
    return l-1+judge(l)
  if judge(cnt):
    return bisect(cnt+1,r)
  else:
    return bisect(l,cnt)
def judge(thr):
  m=0
  for i in range(x):
    for j in range(y):
      for k in range(z):
        if i*j*k>q or a[i]+b[j]+c[k]<thr:
          break
        m+=1
        if m>=q:
          return True
  return False
def make(thr):
  m=0
  l=[]
  for i in a:
    for j in b:
      for k in c:
        n=i+j+k
        if n<thr+1:
          break
        m+=1
        l+=[n]
  l.sort(reverse=True)
  return l+[thr]*(q-len(l))
thr=bisect(0,a[0]+b[0]+c[0]+1)
ans=make(thr)
for w in ans:
  print(w)

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k=map(int,input().split())
a,b,c=[list(map(int,input().split())) for i in range(3)]
l=sorted([i+j for i in a for j in b])[:-k-1:-1]
maxl=sorted([i+j for i in l for j in c])[:-k-1:-1]
for a in maxl:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k=map(int,input().split())
a,b,c=[list(map(int,input().split())) for i in range(3)]
l=[i+j for i in a for j in b]
l=sorted(l,reverse=True)[:k]
maxl=sorted([i+j for i in l for j in c])[::-1]
for i in range(k):
    print(maxl[i])

Submission status: Time Limit Exceeded

Solution code:
x,y,z,q=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)

def bisect(l,r):
  cnt=(l+r)//2
  if cnt==l:
    return l-1+judge(l)
  if judge(cnt):
    return bisect(cnt+1,r)
  else:
    return bisect(l,cnt)
def judge(thr):
  m=0
  for i in a:
    for j in b:
      for k in c:
        if i+j+k<thr:
          break
        m+=1
        if m>=q:
          return True
  return False
def make(thr):
  m=0
  l=[]
  for i in a:
    for j in b:
      for k in c:
        n=i+j+k
        if n<thr+1:
          break
        m+=1
        l+=[n]
  l.sort(reverse=True)
  return l+[thr]*(q-len(l))
thr=bisect(0,a[0]+b[0]+c[0]+1)
ans=make(thr)
for w in ans:
  print(w)

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import product

def main():
    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 = []
    for x in product(A, B):
        AB.append(sum(x))

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

    ABC = []
    for x in product(AB, C):
        ABC.append(sum(x))

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import product

def main():
    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 = sorted(A, key=lambda x: -x) + [-10**9]
    B = sorted(B, key=lambda x: -x) + [-10**9]
    C = sorted(C, key=lambda x: -x) + [-10**9]

    AB = []
    for x in product(A, B):
        AB.append(sum(x))

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

    ABC = []
    for x in product(AB, C):
        ABC.append(sum(x))

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import itertools
X, Y ,Z, K = map(int, input().split())
A = map(int, input().split())
B = map(int, input().split())
C = map(int, input().split())
l = list(itertools.product(A, B, C))
ans = sorted([sum(n) for n in l ],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()]

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

data = []

for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if i * j * k <= K:
                data.append(A[i] + B[j] + C[k])
                
data.sort()
data.reverse()
for i in range(K):
    print(data[i])

Submission status: Time Limit Exceeded

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

d = {}
abcs = [0]
j = -1

for a in a_s:
    for b in b_s:
        for c in c_s:
            abc = a + b + c
            if j >= k and abcs[k-1] >= abc:
                break
            if abcs[0] == 0:
                abcs[0] = abc
            else:
                for i in reversed(range(len(abcs))):
                    if abcs[i] >= abc:
                        abcs.insert(i+1, abc)
                        break
                if j >= k:
                    abcs.pop(-1)
            j += 1
for i in range(k):
    print(abcs[i])

Submission status: Time Limit Exceeded

Solution code:
from itertools import groupby
from operator import itemgetter

x,y,z,k = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
# key, group
ga0 = [{'val':key, 'cnt':len(list(group))} for key, group in groupby(a)]
ga = list(reversed(sorted(ga0, key=itemgetter('val'))))
gb = list(reversed(sorted([{'val':key, 'cnt':len(list(group))} for key, group in groupby(b)], key=itemgetter('val'))))
gc = list(reversed(sorted([{'val':key, 'cnt':len(list(group))} for key, group in groupby(c)], key=itemgetter('val'))))

lga, lgb = len(ga), len(gb)
ia,ib = 0,0
ca,cb = ga[0]['cnt'],gb[0]['cnt']
while ca*cb < k:
    if ia == lga-1 and ib == lgb-1:
        break
    elif ia == lga-1:
        ib += 1
        cb += gb[ib]['cnt']
    elif ib == lgb-1:
        ia += 1
        ca += ga[ia]['cnt']
    elif ga[ia+1]['val'] + gb[ib]['val'] >= ga[ia]['val'] + gb[ib+1]['val']:
        ia += 1
        ca += ga[ia]['cnt']
    else:
        ib += 1
        cb += gb[ib]['cnt']
d = []
for va in ga:
    for vb in gb:
        d.append((va['val']+vb['val'],va['cnt']*vb['cnt']))
gd0 = [{'val':key, 'cnt':sum(c_ for _, c_ in list(group))} for key, group in groupby(d,itemgetter(0))]
gd = list(reversed(sorted(gd0, key=itemgetter('val'))))[:k]

lgc, lgd = len(gc), len(gd)
ic,id = 0,0
cc,cd = gc[0]['cnt'],gd[0]['cnt']
while cc*cd < k:
    if ic == lgc-1 and id == lgd-1:
        break
    elif ic == lgc-1:
        id += 1
        cd += gd[id]['cnt']
    elif id == lgd-1:
        ic += 1
        cc += gc[ic]['cnt']
    elif gc[ic+1]['val'] + gd[id]['val'] >= gc[ic]['val'] + gd[id+1]['val']:
        ic += 1
        cc += gc[ic]['cnt']
    else:
        id += 1
        cd += gd[id]['cnt']
r = []
for vc in gc:
    for vd in gd:
        r.append((vc['val']+vd['val'],vc['cnt']*vd['cnt']))
gr0 = [{'val':key, 'cnt':sum(c_ for _, c_ in list(group))} for key, group in groupby(r,itemgetter(0))]
gr = list(reversed(sorted(gr0, key=itemgetter('val'))))[:k]
i = 0
for vr in gr:
    for j in range(vr['cnt']):
        print(vr['val'])
        i += 1
        if i == k:
            exit

Submission status: Time Limit Exceeded

Solution code:
input_out_data = input().split(" ")
cake_sum_point = []

for i in range(4):
    input_out_data[i] = int(input_out_data[i])


cake_A = input().split(" ")
cake_B = input().split(" ")
cake_C = input().split(" ")
for k in range(input_out_data[0]):
    cake_A[k] = int(cake_A[k])
cake_A.sort(reverse=True)
for k in range(input_out_data[1]):
    cake_B[k] = int(cake_B[k])
cake_B.sort(reverse=True)
for k in range(input_out_data[2]):
    cake_C[k] = int(cake_C[k])
cake_C.sort(reverse=True)

for i in range(input_out_data[0]):
    for k in range(input_out_data[1]):
        for j in range(input_out_data[2]):
            if (i+1)*(k+1)*(j+1)<=input_out_data[3]:
                cake_sum_point.append(cake_A[i]+cake_B[k]+cake_C[j])
cake_sum_point.sort(reverse=True)
for i in range(input_out_data[3]):
    print(cake_sum_point[i])