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())
abc = [sorted(list(map(int,input().split())), reverse=True) for i in range(3)]

ans=[0]*K

for i in range(x):
    for j in range(y):
        for l in range(z):
            if min(ans) < abc[0][i]+abc[1][j]+abc[2][l]:
                ans[ans.index(min(ans))] = abc[0][i]+abc[1][j]+abc[2][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()))

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

abc = []
for i in range(min(k,len(ab))):
    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:
x,y,z,k = map(int,input().split())
a = sorted(list(map(int,input().split())), reverse = True)
b = sorted(list(map(int,input().split())), reverse = True)
c = sorted(list(map(int,input().split())), reverse = True)

ab = []
for i in range(x):
    for j in range(y):
        ab.append(a[i] + b[j])
        if len(ab) == k:
            break
ab.sort(reverse = True)

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

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

Submission status: Time Limit Exceeded

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

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

abc = []
for i in range(min(3000, len(ab))):
    for j in range(min(3000,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:
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)

abc = []
for i in range(min(3000, len(ab))):
    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:
if __name__ == "__main__":
    abck=input().split(" ")
    A,B,C,K =int(abck[0]),abck[1],abck[2],int(abck[3])
    first_sort=[]
    set_sort=[[],[],[]]
    for x in set_sort:
        stack=input().split(" ")
        for y in stack:
            x.append(int(y))
    compare_list=[]
    for x in set_sort[0]:
        for y in set_sort[1]:
            compare_list.append(x+y)
    compare_list.sort(reverse=True)
    compare_list2=[]
    if len(compare_list)>K:
        compare_list=compare_list[:K]
    for x in compare_list:
        for y in set_sort[2]:
            compare_list2.append(x+y)
    
    compare_list2.sort(reverse=True) 
    for x in compare_list2[:K]:
        print(x)

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)
AB = AB[:K]

ABC = [ab+c for ab in AB 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 = [a+b for a in A for b in B]

AB.sort(reverse=True)
AB = AB[:K]

ABC = [ab+c for ab in AB for c in C]

ABC.sort(reverse=True)
print(*ABC[:K], sep='\n')

Submission status: Time Limit Exceeded

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

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
AB = []
for a in A:
    for b in B:
        AB.append(a+b)
AB.sort(reverse=True)
AB = AB[0:min(3001,X*Y*Z+1)]

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

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

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
AB = []
for a in A:
    for b in B:
        AB.append(a+b)
AB.sort(reverse=True)
AB = AB[0:3000]

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

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

Submission status: Time Limit Exceeded

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
X,Y,Z,K = map(int, input().split())

A_list = [int(e) for e in input().split()]
B_list = [int(e) for e in input().split()]
C_list = [int(e) for e in input().split()]

delicious_list=[]

#Maxは3000通りであることを利用する
#足し算なのでA～C_listのうち上位3000しか使われない
A_list.sort(reverse=True)
B_list.sort(reverse=True)
C_list.sort(reverse=True)

for i in range(min(X,3000)):
  for j in range(min(Y,3000)):
    for k in range(min(Z,3000)):
      delicious_list.append(A_list[i]+B_list[j]+C_list[k])
      
delicious_list.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
#ABC123 D
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
X,Y,Z,K = map(int, input().split())

A_list = [int(e) for e in input().split()]
B_list = [int(e) for e in input().split()]
C_list = [int(e) for e in input().split()]

delicious_list=[]
  
for i in range(X):
  for j in range(Y):
    for k in range(Z):
      delicious_list.append(A_list[i]+B_list[j]+C_list[k])
      
delicious_list.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
x,y,z,K = map(int, input().split())
a = sorted(list(map(int, input().split())))[::-1]
b = sorted(list(map(int, input().split())))[::-1]
c = sorted(list(map(int, input().split())))[::-1]

def check(p, l=None):
    cnt = 0
    for i in range(x):
        for j in range(y):
            for k in range(z):
                if a[i]+b[j]+c[k] < p:
                    break
                if l is not None:
                    l.append(a[i]+b[j]+c[k])
                cnt += 1
                if cnt >= K:
                    return True
    return False

left = 0
right = a[0]+b[0]+c[0] + 1
while right-left > 1:
    mid = (left+right)//2
    if check(mid):
        left = mid
    else:
        right = mid
#print(left)
ans = []
check(right, ans)
ans += [left]*(K - len(ans))
for i in sorted(ans, reverse=True)[:K]:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys
X,Y,Z,K = list(map(int,sys.stdin.readline().split()))
A = list(map(int,sys.stdin.readline().split()))
B = list(map(int,sys.stdin.readline().split()))
C = list(map(int,sys.stdin.readline().split()))

ab = []
for i,j in itertools.product(A,B):
	ab.append(i+j)
ab.sort()
ab_k = ab[-K:]

abc = []
for i,j in itertools.product(ab_k,C):
	abc.append(i+j)
abc.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys
input = sys.stdin.readline
X,Y,Z,K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

ab = []
for i,j in itertools.product(A,B):
	ab.append(i+j)
ab.sort()
ab_k = ab[-K:]

abc = []
for i,j in itertools.product(ab_k,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())
abc = [sorted(list(map(int, input().split())), reverse=True) for i in range(3)]

ans = []
for i in range(x):
    for j in range(y):
        for k in range(z):
            if (i+1)*(j+1)*(k+1) <= K:
                ans.append(abc[0][i]+abc[1][j]+abc[2][k])
for i in sorted(ans)[::-1][:K]:
    print(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 = []
for i,j in itertools.product(A,B):
	ab.append(i+j)
ab_k = sorted(ab,reverse=True)[:K]

abc = []
for i,j in itertools.product(ab_k,C):
	abc.append(i+j)
abc_k = sorted(abc,reverse=True)

for i in range(K):
	print(abc_k[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 = []
for i,j in itertools.product(A,B):
	ab.append(i+j)
ab_k = sorted(ab)[-K:]

abc = []
for i,j in itertools.product(ab_k,C):
	abc.append(i+j)
abc_k = sorted(abc,reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
X,Y,Z,K = list(map(int,input().split()))
A = sorted(list(map(int,input().split())),reverse=True)
B = sorted(list(map(int,input().split())),reverse=True)
C = sorted(list(map(int,input().split())),reverse=True)
abc = []
count = 0
for l,m,n in itertools.product(A,B,C):
	abc.append(l+m+n)

new_abc = sorted(abc,reverse=True)
for i in range(K):
	print(new_abc[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()))
abc = []
for i,j,k in itertools.product(A,B,C):
	abc.append(i+j+k)
abc.sort(reverse=True)
for i in range(K):
	print(abc[i])

Submission status: Time Limit Exceeded

Solution code:
import math
xyzk = list(map(int,input().split()))
abc = [list(map(int,input().split())) for a in range(3)]
ab=[]
for a in abc[0]:
    for b in abc[1]:
        ab.append(a+b)
ab.sort()
ab.reverse()
abc2=[]
for a in range(min([xyzk[3],len(ab)])):
    for b in abc[2]:
        abc2.append(b+ab[a])
abc2.sort()
abc2.reverse()
for a in range(xyzk[3]):
    print(abc2[a])

Submission status: Time Limit Exceeded

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

# 整数の入力
x,y,z,k = map(int,input().split())

cakea = list(map(int, input().split()))
cakeb = list(map(int, input().split()))
cakec = list(map(int, input().split()))

oishisa = []

for a in range(len(cakea)):
    for b in range(len(cakeb)):
        for c in range(len(cakec)):
            oishisa.append(cakea[a] + cakeb[b] + cakec[c])

oishisa.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
import math
x, y, z, k = map(int, input().split())
listA = list(map(int, input().strip().split()))
listB = list(map(int, input().strip().split()))
listC = list(map(int, input().strip().split()))
listA.sort(reverse=True)
listB.sort(reverse=True)
listC.sort(reverse=True)
que_list = []
sum_list = []


class que:
    taste_sum = 0
    a = 0
    b = 0
    c = 0


def MakeAndApeendQue(a, b, c):
    new_que = que()
    new_que.a = a
    new_que.b = b
    new_que.c = c
    if a < len(listA) and b < len(listB) and c < len(listC):
        new_que.taste_sum = listA[a] + listB[b] + listC[c]
        que_list.append(new_que)


def SearchMaxAndDelete():
    max_a = que_list[0].a
    max_b = que_list[0].b
    max_c = que_list[0].c
    max_i = 0
    max = que_list[0].taste_sum
    for i in range(1, len(que_list)):
        if que_list[i].taste_sum > max:
            max = que_list[i].taste_sum
            max_a = que_list[i].a
            max_b = que_list[i].b
            max_c = que_list[i].c
            max_i = i
    sum_list.append(max)
    return max, max_a, max_b, max_c, max_i


def SearchQ(a, b, c):
    for i in range(0, len(que_list)):
        if que_list[i].a == a and que_list[i].b == b and que_list[i].c == c:
            return True
    return False


def AddQue(a, b, c):
    if SearchQ(a, b, c) == False:
        MakeAndApeendQue(a, b, c)


MakeAndApeendQue(0, 0, 0)
for i in range(0, k):
    max, ai, bi, ci, del_index = SearchMaxAndDelete()
    print("{}".format(max))
    AddQue(ai+1, bi, ci)
    AddQue(ai, bi+1, ci)
    AddQue(ai, bi, ci + 1)
    del que_list[del_index]

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()
ab=ab[-k:]
abc=[]
for i in ab:
    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 = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

# 美味しさ降順にソートしたListの作成
l = []
for i in range(x[0]):
  for j in range(x[1]):
    for k in range(x[2]):
      l.append(a[i] + b[j] + c[k])
l.sort(reverse=True)

# out
for i in range(x[3]):
  print(l[i])

Submission status: Time Limit Exceeded

Solution code:
x, y, z, K = map(int, input().split())
K = min(x * y * z, K)
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)


def check(p):
    cnt = 0
    for i in a:
        for j in b:
            for k in c:
                if i + j + k < p:
                    break
                cnt += 1
                if cnt >= K:
                    return True
    return False


left = 10**10 * 3
right = 0

while left - right > 1:
    center = (left + right) // 2
    if check(center):
        tmp = center
        right = center
    else:
        left = center

cnt = 0
results = []
for i in a:
    for j in b:
        for k in c:
            ijk = i + j + k
            if ijk < tmp:
                break
            results.append(ijk)
            cnt += 1
            if cnt >= K:
                print("\n".join(map(str, sorted(results, reverse=True))))
                exit()

Submission status: Time Limit Exceeded

Solution code:
x, y, z, K = map(int, input().split())
K = min(x * y * z, K)
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)


def check(p, return_array=False):
    cnt = 0
    results = []
    for i in a:
        for j in b:
            for k in c:
                ijk = i + j + k
                if ijk < p:
                    break
                results.append(ijk)
                cnt += 1
                if cnt >= K:
                    return True, results
    return False, results


left = 10**10 * 3
right = 0

while left - right > 1:
    center = (left + right) // 2
    flg, results = check(center)
    if flg:
        tmp = results
        right = center
    else:
        left = center

print("\n".join(map(str, sorted(tmp, reverse=True))))

Submission status: Time Limit Exceeded

Solution code:
# import time
# start = time.time()

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

rank = list()

A = sorted(A)[::-1]
B = sorted(B)[::-1]
C = sorted(C)[::-1]
# print(A,B,C,sep='\n')

for a in A:
    for b in B:
        for k,c in enumerate(C):
            flag = False
            abc = sum([a,b,c])
            if len(rank) < K:
                rank.append(abc)
            elif abc < rank[0]:
                if k == 0:
                    flag = True
                break
            else:
                rank[0] = abc
            rank.sort()
        if flag is True:
            break
            

rank = rank[::-1]
for i in rank:
    print(i)
            
# elapsed_time = time.time() - start

# print(elapsed_time,"sec")

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

rank = list()

A = sorted(A)[::-1]
B = sorted(B)[::-1]
C = sorted(C)[::-1]
# print(A,B,C,sep='\n')

for a in A:
    for b in B:
        for c in C:
            abc = sum([a,b,c])
            if len(rank) < K:
                rank.append(abc)
            elif abc < rank[0]:
                break
            else:
                rank[0] = abc
            rank.sort()
rank = rank[::-1]
for i in rank:
    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()
B.sort()

AB = [a+b for a in A for b in B]

AB.sort(reverse=True)
AB = AB[:min(3000, K)]

ABC = [ab+c for ab in AB for c in C]

ABC.sort(reverse=True)
print(*ABC[:K], sep='\n')

Submission status: Time Limit Exceeded

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

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

A.sort()
B.sort()

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

AB.sort(reverse=True)
AB = AB[:min(3000, K)]

ABC = []
for ab in AB:
    for c in C:
        ABC.append(ab+c)

ABC.sort(reverse=True)
print(*ABC[:K], sep='\n')

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int, input().split())
k = min(x * y * z, k)
a = list(map(int, input().split()))[:k]
b = list(map(int, input().split()))[:k]
c = list(map(int, input().split()))[:k]
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
def f(a, b):
    return [i + j for i in a for j in b]
ab_results = f(a, b)
ab_results.sort(reverse=True)
results = f(c, ab_results[:k])
results.sort(reverse=True)

print("\n".join(map(str, results[:k])))

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int, input().split())
k = min(x * y * z, k)
a = sorted(list(map(int, input().split())), reverse=True)[:k]
b = sorted(list(map(int, input().split())), reverse=True)[:k]
c = sorted(list(map(int, input().split())), reverse=True)[:k]
def f(a, b):
    results = []
    cnt = 0
    for i in a:
        for j in b:
            cnt += 1
            results.append(i + j)
    return results
ab_results = sorted(f(a, b), reverse=True)
results = sorted(f(c, ab_results[:k]), reverse=True)

print("\n".join(map(str, results[:k])))

Submission status: Time Limit Exceeded

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

def f(a, b):
    results = []
    cnt = 0
    for i in a:
        for j in b:
            cnt += 1
            results.append(i + j)
    return results
ab_results = f(a, b)
ab_results.sort(reverse=True)

results = f(c, ab_results[:k])
results.sort(reverse=True)

print("\n".join(map(str, results[:k])))

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int, input().split())
k = min(x * y * z, k)
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)

def f(a, b):
    results = []
    cnt = 0
    for i in a:
        for j in b:
            cnt += 1
            results.append(i + j)
    return results
ab_results = f(a, b)
ab_results.sort(reverse=True)

results = f(c, ab_results[:k])
results.sort(reverse=True)

print("\n".join(map(str, results[:k])))

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int, input().split())
k = min(x * y * z, k)
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)

def f(a, b):
    results = []
    cnt = 0
    for i in a:
        for j in b:
            cnt += 1
            results.append(i + j)
    return results
ab_results = f(a, b)
ab_results.sort(reverse=True)

results = f(c, ab_results[:k])
results.sort(reverse=True)
list(map(print, results[:k]))

Submission status: Time Limit Exceeded

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

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

ab_results = ab_results[:k]
results = [i + j for i in c for j in ab_results]
results.sort(reverse=True)
list(map(print, results[:k]))

Submission status: Time Limit Exceeded

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

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

ab_results = ab_results[:k]
results = []
for i in c:
    for j in ab_results:
        results.append(i + j)
results.sort(reverse=True)
list(map(print, results[: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()))

A = sorted(A, reverse=True)[:K+1]
B = sorted(B, reverse=True)[:K+1]
C = sorted(C, reverse=True)[:K+1]

res = []

for i in A:
    for j in B:
        for k in C:
            res.append(i + j + k)

res = sorted(res, reverse=True)[:K+1]
for i in range(K):
    print(res[i])

Submission status: Time Limit Exceeded

Solution code:
l = []
w = []
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()))
for i in range(len(a)):
    for j in range(len(b)):
        l.append(a[i]+b[j])
        l = sorted(l)[::-1][:k]
for i in range(len(l)):
    for j in range(len(c)):
        w.append(l[i]+c[j])
        w = sorted(w)[::-1]
for i in range(k):
    print(w[i])

Submission status: Time Limit Exceeded

Solution code:
l = []
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()))
for i in range(len(a)):
    for j in range(len(b)):
        for m in range(len(c)):
            l.append(a[i]+b[j]+c[m])
            l = sorted(l)[::-1]
for i in range(k):
    print(l[i])

Submission status: Time Limit Exceeded

Solution code:
def lsum(x):
    return A[x[0]] + B[x[1]] + C[x[2]]

def nextlist():
    global lx
    idx = 0
    m = lsum(lx[0])
    for i in range(len(lx)):
        s = lsum(lx[i])
        if m < s:
            m = s
            idx = i
    p = lx.pop(idx)
    wa.append(lsum(p))
    if p[0] > 0:
        if not [p[0]-1, p[1], p[2]] in lx:
            lx.append([p[0]-1, p[1], p[2]])
    if p[1] > 0:
        if not [p[0], p[1]-1, p[2]] in lx:
            lx.append([p[0], p[1]-1, p[2]])
    if p[2] > 0:
        if not [p[0], p[1], p[2]-1] in lx:
            lx.append([p[0], p[1], p[2]-1])

l1 = list(map(int, input().split(" ")))

X,Y,Z,K = l1[0],l1[1],l1[2],l1[3]
A = sorted(list(map(int, input().split(" "))))
B = sorted(list(map(int, input().split(" "))))
C = sorted(list(map(int, input().split(" "))))

wa = []
lx = [[X-1,Y-1,Z-1]]

for i in range(K):
    nextlist()

for l in wa:
    print(l)

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)

count = 0
candidates = []
heapq.heappush(candidates, (-(A[0] + B[0] + C[0]), 0, 0, 0))
used = set()
while True:
    s, i, j, k = heapq.heappop(candidates)
    s *= -1
    if not (i, j, k) in used:
        print(s)
        count += 1
        if count >= K:
            break
    used.add((i, j, k))
    if i < X - 1:
        heapq.heappush(candidates, (-(A[i+1] + B[j] + C[k]), i+1, j, k))
    if j < Y - 1:
        heapq.heappush(candidates, (-(A[i] + B[j+1] + C[k]), i, j+1, k))
    if k < Z - 1:
        heapq.heappush(candidates, (-(A[i] + B[j] + C[k+1]), i, j, k+1))

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)

count = 0
candidates = {(0, 0, 0)}
used = set()
while True:
    max_x, max_y, max_z = (0, 0, 0)
    max_sum = -1
    for x, y, z in candidates:
        s = a_list[x] + b_list[y] + c_list[z]
        if s > max_sum:
            max_x, max_y, max_z = x, y, z
            max_sum = s
    if not (max_x, max_y, max_z) in used:
        print(max_sum)
        count += 1
        if count >= K:
            break
    candidates.remove((max_x, max_y, max_z))
    used.add((max_x, max_y, max_z))
    if max_x < X - 1:
        candidates.add((max_x + 1, max_y, max_z))
    if max_y < Y - 1:
        candidates.add((max_x, max_y + 1, max_z))
    if max_z < Z - 1:
        candidates.add((max_x, max_y, max_z + 1))

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)
ans = []
candidates = [(0, 0, 0)]
used = set()
while len(ans) < K:
    max_x, max_y, max_z = candidates[0]
    max_sum = a_list[max_x] + b_list[max_y] + c_list[max_z]
    for x, y, z in candidates:
        s = a_list[x] + b_list[y] + c_list[z]
        if s > max_sum:
            max_x, max_y, max_z = x, y, z
            max_sum = s
    if not (max_x, max_y, max_z) in used:
        ans.append(max_sum)
    candidates.remove((max_x, max_y, max_z))
    used.add((max_x, max_y, max_z))
    if max_x < X - 1:
        candidates.append((max_x + 1, max_y, max_z))
    if max_y < Y - 1:
        candidates.append((max_x, max_y + 1, max_z))
    if max_z < Z - 1:
        candidates.append((max_x, max_y, max_z + 1))
for a in ans:
    print(a)