Problem:


Score: 400 points

Problem Statement

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

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

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

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

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

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

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

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

Constraints

1 \leq X \leq 1 \ 000

1 \leq Y \leq 1 \ 000

1 \leq Z \leq 1 \ 000

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

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

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

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

All values in input are integers.

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

2 2 2 8
4 6
1 5
3 8

Sample Output 1

19
17
15
14
13
12
10
8

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

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

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

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

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

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

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

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

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

Sample Input 2

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

Sample Output 2

400
310
310
301
301

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

Sample Input 3

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

Sample Output 3

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

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



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


Sample output:
19
17
15
14
13
12
10
8

Submission status: Time Limit Exceeded

Solution code:
#n=int(input())
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#import math
#li=input().split()
#S=input()

lis=[]
A=[]
B=[]
C=[]
AB=[]
ABC=[]
lis=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
C.sort(reverse=True)

for i in A:
    for j in B:
        AB.append(i+j)
AB.sort(reverse=True)
AB=AB[:lis[3]]
for i in AB:
    for j in C:
        ABC.append(i+j)
ABC.sort(reverse=True)
for i in range(lis[3]):
    print(ABC[i])

Submission status: Time Limit Exceeded

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

A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))


import itertools
val_list = []


A_list = sorted(A_list, reverse=True)
B_list = sorted(B_list, reverse=True)
C_list = sorted(C_list, reverse=True)

#print(A_list)
#print(B_list)
#print(C_list)

for a in range(len(A_list)):
    for b in range(len(B_list)):
        for c in range(len(C_list)):
            if (a+1) * (b+1) * (c+1) > K:
                continue
        
            val_list.append(A_list[a] + B_list[b] + C_list[c])

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

Submission status: Time Limit Exceeded

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



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

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

    count = 0
    BC = [0 for i in range(Y * Z)]
    for i in range(Y):
        for j in range(Z):
            BC[count] = (long(B[i] + C[j]))
            count += 1
            #heapq.heappush(BC, -long(B[i] + C[j]))

    A.sort(reverse = True)
    BC.sort(reverse = True)

    T = [0 for i in range(min(K, len(BC)) * K)]
    count = 0
    for j in range(min(K, len(BC))):
        for i in range(X):
            T[count] = A[i] + BC[j]
            count += 1
            #heapq.heappush(T, -(A[i] + BC[j]))
    T.sort(reverse = True)
    for i in range(K):
        #t = -heapq.heappop(T)
        print T[i]

if __name__ == '__main__':
    main()

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(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
d = []
e = []
s = 0
for i in range(x):
    for j in range(y):
        d.append(a[i]+b[j])

d.sort(reverse=True)
p = min(k,len(d))

for i in range(p):
    for j in range(z):
        e.append(d[i]+c[j])

e.sort(reverse=True)
#print(e)
for i in range(k):
    print(e[i])

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

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

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

for i in range(len(abc)):
  if i < k:
    print(abc[i])
  else:
    break

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)
AB = []
ABC = []
for i in A:
        for j in B:
                AB.append(i+j)
AB.sort(reverse = True)
AB = AB[:k]
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:
import sys
from collections import deque
import heapq
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



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

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

    count = 0
    BC = [0 for i in range(Y * Z)]
    for i in range(Y):
        for j in range(Z):
            BC[count] = (long(B[i] + C[j]))
            count += 1
            #heapq.heappush(BC, -long(B[i] + C[j]))

    A.sort(reverse = True)
    BC.sort(reverse = True)

    T = []
    for j in range(min(K, len(BC))):
        for i in range(X):
            T.append(A[i] + BC[j])
            #heapq.heappush(T, -(A[i] + BC[j]))
    T.sort(reverse = True)
    for i in range(K):
        #t = -heapq.heappop(T)
        print T[i]

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))


import itertools
val_list = []


A_list = sorted(A_list, reverse=True)
B_list = sorted(B_list, reverse=True)
C_list = sorted(C_list, reverse=True)

#print(A_list)
#print(B_list)
#print(C_list)

for a, b, c in itertools.product(range(len(A_list)), range(len(B_list)), range(len(C_list))):
    if (a+1) * (b+1) * (c+1) > K:
        continue
        
    val_list.append(A_list[a] + B_list[b] + C_list[c])

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

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

bimi = []
for a in range(X):
        for b in range(Y):
                bimi.append(A[a] + B[b])

bimi.sort(reverse=True)
ans = []
for x in range(min(K, len(bimi))):
        for c in range(Z):
                ans.append(bimi[x] + C[c])

ans.sort(reverse=True)

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

Submission status: Time Limit Exceeded

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



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

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

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

    A.sort(reverse = True)
    BC.sort(reverse = True)

    T = []
    for j in range(min(K, len(BC))):
        for i in range(X):
            T.append(A[i] + BC[j])
            #heapq.heappush(T, -(A[i] + BC[j]))
    T.sort(reverse = True)
    for i in range(K):
        #t = -heapq.heappop(T)
        print T[i]

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 = sorted(A,reverse = True)
B = sorted(B,reverse = True)
C = sorted(C,reverse = True)
AB = []
ABC = []
for i in A:
        for j in B:
                AB.append(i+j)
AB.sort(reverse = True)
AB = AB[:k]
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 = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ab=sorted(s+t for t in B for s in A)[-1:-K-1:-1]
abc=sorted(i+x for i in ab for x in C)[-1:-K-1:-1]
print("\n".join(map(str,abc)))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

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

bimi = []
for a in range(X):
        for b in range(Y):
                bimi.append(A[a] + B[b])

bimi.sort(reverse=True)
ans = []
for x in range(min(3000, len(bimi))):
        for c in range(Z):
                ans.append(bimi[x] + C[c])

ans.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ab=sorted(s+t for t in B for s in A)[-1:-K-1:-1]
abc=sorted(i+x for i in ab for x in C)[-1:-K-1:-1]
print(*abc,sep="\n")

Submission status: Time Limit Exceeded

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

AB = sorted([a + b for a in A for b in B], reverse=True)[:K]
ABC = sorted([ab + c for ab in AB for c in C], reverse=True)[:K]
for v in ABC:
    print(v)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr  7 00:03:49 2019

@author: Yamazaki Kenichi
"""
import heapq

X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split())) + [-10**9]
B = list(map(int,input().split())) + [-10**9]
C = list(map(int,input().split())) + [-10**9]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
Q = []
T = [[[-1 for i in range(Z+1)] for i in range(Y+1)] for i in range(X+1)]
T[0][0][0] = 1
heapq.heappush(Q,[-(A[0]+B[0]+C[0]),0,0,0])
for i in range(K-1):
    k = heapq.heappop(Q)
    s1,s2,s3 = k[1],k[2],k[3]
    if T[s1+1][s2][s3] == -1:
        heapq.heappush(Q,[-(A[s1+1]+B[s2]+C[s3]),s1+1,s2,s3])
        T[s1+1][s2][s3] = 1
    if T[s1][s2+1][s3] == -1:
        heapq.heappush(Q,[-(A[s1]+B[s2+1]+C[s3]),s1,s2+1,s3])
        T[s1][s2+1][s3] = 1
    if T[s1][s2][s3+1] == -1:
        heapq.heappush(Q,[-(A[s1]+B[s2]+C[s3+1]),s1,s2,s3+1])
        T[s1][s2][s3+1] = 1
    print(-k[0])
k = heapq.heappop(Q)
print(-k[0])

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

X, Y, Z, K = MAP()
A = LIST()
B = LIST()
C = LIST()

A=sorted(A)[::-1]
B=sorted(B)[::-1]
C=sorted(C)[::-1]
ans = []
for i in range(len(A)):
	if i > K:
		continue
	for j in range(len(B)):
		if i * j > K:
			continue
		for k in range(len(C)):
			if i * j * k > K:
				continue
			else:
				ans.append(A[i]+B[j]+C[k])
for i in sorted(ans)[::-1][0:K]:
	print(i)

Submission status: Time Limit Exceeded

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



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

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

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

    A.sort(reverse = True)
    BC.sort(reverse = True)

    T = []
    for j in range(min(K, len(BC))):
        for i in range(X):
            T.append(A[i] + BC[j])
            #heapq.heappush(T, -(A[i] + BC[j]))
    T.sort(reverse = True)
    for i in range(K):
        #t = -heapq.heappop(T)
        print T[i]

if __name__ == '__main__':
    main()

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] 
AB.sort()
AB = AB[::-1]
AB= AB[:3000]
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:
xyzk = list(map(int, input().split()))
x = xyzk[0]
y = xyzk[1]
z = xyzk[2]
k = xyzk[3]

a = list(map(int, input().split()))
a.sort(reverse=True)
a = a[0:min(k, len(a))]
b = list(map(int, input().split()))
b.sort(reverse=True)
b = b[0:min(k, len(b))]
c = list(map(int, input().split()))
c.sort(reverse=True)
c = c[0:min(k, len(c))]

ablist = []

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

ablist.sort(reverse=True)
ablist = ablist[0:min(k, len(ablist))]

abclist = []
for i in range(len(ablist)):
    for j in range(len(c)):
        abclist.append(ablist[i] + c[j])

abclist.sort(reverse=True)
abclist = abclist[0:k + 1]

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()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
sum = 0
ans = []
ans2 = []
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
for i in range(X):
    for j in range(Y):
        sum = A[i] + B[j]
        ans.append(sum)
ans.sort(reverse=True)

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

for l in range(K):
    print(ans2[l])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

Ai= sorted(A, reverse=True)
Bi= sorted(B, reverse=True)
Ci= sorted(C, reverse=True)

def su(a,b,c):
	return(Ai[a]+Bi[b]+Ci[c])

a=0
b=0
c=0

pq=[[su(a,b,c),a,b,c]]
ck=[[su(a,b,c),a,b,c]]

dl=0
for i in range(k):
	dl=pq.index(max(pq))
	res=pq.pop(dl)
	print(res[0])
	#print(pq)
	
	a=res[1]
	b=res[2]
	c=res[3]
	if a+1<=x-1 and (not [su(a+1,b,c),a+1,b,c] in ck):
		pq.append([su(a+1,b,c),a+1,b,c])
		ck.append([su(a+1,b,c),a+1,b,c])
	if b+1<=y-1 and (not [su(a,b+1,c),a,b+1,c] in ck):
		pq.append([su(a,b+1,c),a,b+1,c])
		ck.append([su(a,b+1,c),a,b+1,c])
	if c+1<=z-1 and (not [su(a,b,c+1),a,b,c+1] in ck):
		pq.append([su(a,b,c+1),a,b,c+1])
		ck.append([su(a,b,c+1),a,b,c+1])

Submission status: Time Limit Exceeded

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

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
AB=[]
for i in range(len(A)):
    for j in range(len(B)):
        AB.append(A[i]+B[j])
AB.sort(reverse=True)

AB=AB[:min(3000,len(A)*len(B))]
ABC=[]
for i in range(len(AB)):
    for j in range(len(C)):
        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:
xyzk = list(map(int, input().split()))
x = xyzk[0]
y = xyzk[1]
z = xyzk[2]
k = xyzk[3]

a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ablist = []

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

ablist.sort(reverse=True)
ablist = ablist[0:min(k, len(ablist))]

abclist = []
for i in range(len(ablist)):
    for j in range(len(c)):
        abclist.append(ablist[i] + c[j])

abclist.sort(reverse=True)
abclist = abclist[0:k + 1]

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
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()))
la = len(A)
lb = len(B)
lc = len(C)
AB = deque()
for i in range(la):
    for j in range(lb):
        AB.append(A[i] + B[j])
AB = sorted(AB, reverse=True)
AB = AB[:K]
lab = len(AB)
ABC = deque()
for i in range(lab):
    for j in range(lc):
        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:
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

X,Y,Z,K = IL()
A = IL()
B = IL()
C = IL() 

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

ab = []
for i in list(itertools.product(A,B)):
    ab.append(sum(i))

ab.sort(reverse=True)

ans = []
for i in list(itertools.product(ab[:3000],C)):
    ans.append(sum(i))

ans.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]
    ans = []
    X, Y, Z, K = (int(_) for _ in input().split())
    A = list(int(_) for _ in input().split())
    A.sort()
    B = list(int(_) for _ in input().split())
    B.sort()
    C = list(int(_) for _ in input().split())
    C.sort()
    for a in A:
        for b in B:
            for i in range(min(len(C),3001)):
                ans.append(a + b + C[i])
    ans.sort()
    ans = ans[::-1]
    ans = ans[:K]
    print('\n'.join(map(str,ans)))

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

e = [a_i + b_j for b_j in b for a_i in a]
e.sort(reverse=True)

ans = [e_i + c_j for c_j in c[:k] for e_i in e[:k]]
ans.sort(reverse=True)

for idx in range(k):
    print(ans[idx])

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)

AB = []
for a in range(x):
    for b in range(y):
        AB.append(A[a] + B[b])
AB.sort(reverse=True)
# print(AB[0:k])
if len(AB)>k:
    AB=AB[0:k]
    
ans = []
for i in AB:
    for c in C:
        ans.append(i + c)
ans.sort(reverse=True)

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

Submission status: Time Limit Exceeded

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

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 = sorted(AB, reverse=True)

if 3000 < len(AB):
    AB = AB[:3000]

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

ABC = sorted(ABC, reverse=True)

ABC = ABC[:K]
ABC = [str(abc) for abc in ABC]

print("\n".join(ABC))

Submission status: Time Limit Exceeded

Solution code:
I=lambda:list(map(int,input().split()));x,y,z,k=I();s=lambda a,b:sorted(i+j for i in a for j in b)[:-k-1:-1];S=sorted;print(*s(s(S(I()),S(I())),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()))
sum = 0
ans = []
ans2 = []
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
for i in range(X):
    for j in range(Y):
        sum = A[i] + B[j]
        ans.append(sum)
ans.sort(reverse=True)

for i in range(min(3000,len(ans))):
    for j in range(Z):
        sum = ans[i] + C[j]
        ans2.append(sum)
ans2.sort(reverse=True)

for l in range(K):
    print(ans2[l])

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

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

ALL=[]

for ab in AB:
    for c in C:
        ALL.append(ab+c)

ALL.sort(reverse=True)

for k in range(K):
    print(ALL[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.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
 
ansListab=[]
for i in range(x):
  for j in range(y):
    ansListab.append(a[i]+b[j])
 
ansListab.sort(reverse= True)
 
if len(ansListab)>k:
  ansListab=ansListab[0:k]
 
ansList=[]
 
for i in c:
  for j in ansListab:
    ansList.append(i+j)
 
ansList.sort(reverse= True)
 
for i in range(k):
  print(ansList[i])

Submission status: Time Limit Exceeded

Solution code:
I=lambda:list(map(int,input().split()));x,y,z,k=I();s=lambda a,b:sorted(i+j for i in a for j in b)[-k:];print(*s(s(I(),I()),I())[::-1])

Submission status: Time Limit Exceeded

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

list = []
i = 0
flag = True
minlist = 0
for a in a_s:
    if minlist >= (a + bs[0] + cs[0]):
        break
    for b in bs:
        if minlist >= (a + b + cs[0]):
            break
        for c in cs:
            abc = a + b +c
            if flag and i >= k:
                minlist = min(list)
                flag = False
            if minlist >= abc:
                break
            list.append(a + b + c)
            i += 1
list.sort(reverse=True)
for i in range(k):
    print(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(x):
    for j in range(y):
            l.append(a[i] + b[j])

l = sorted(l,reverse=True)
ll = []
for i in range(min(len(l),k)):
    for j in range(z):
        ll.append(l[i] + c[j])

ll = sorted(ll,reverse=True)
for i in range(k):
    print(ll[i])

Submission status: Time Limit Exceeded

Solution code:
xyzk = list(map(int, input().split()))
x = xyzk[0]
y = xyzk[1]
z = xyzk[2]
k = xyzk[3]

a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ablist = []

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

newlist = []
for i in range(min(k, len(ablist))):
    newlist.append(max(ablist))
    ablist.remove(max(ablist))

abclist = []
for i in range(len(newlist)):
    for j in range(len(c)):
        abclist.append(newlist[i] + c[j])

for i in range(k):
    print(max(abclist))
    abclist.remove(max(abclist))

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)

AB = []
for a in range(x):
    for b in range(y):
        AB.append(A[a] + B[b])
AB.sort(reverse=True)
# print(AB[0:k])
if len(AB)>k:
    AB=AB[0:k]
    
ans = []
for i in AB:
    for c in C:
        ans.append(i + c)
ans.sort(reverse=True)
# print(ans[0:k])
ans = ans[0:k]

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)
AB = AB[:K+1]
ABC = []
for i in range(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:
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()))

d = [0]*(X*Y)
for i in range(X):
	for j in range(Y):
		d[i*Y+j] = a[i]+b[j]

d_sort = sorted(d,reverse = True)

e = [0]*(K*Z)

for i in range(min(K,X*Y)):
	for j in range(Z):
		e[i*Z+j] = d_sort[i]+c[j]

e_sort = sorted(e,reverse = True)

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

Submission status: Time Limit Exceeded

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

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)

AB = []

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

AB = sorted(AB, reverse=True)

if 3000 < len(AB):
    AB = AB[:3000]

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

ABC = sorted(ABC, reverse=True)

ABC = ABC[:K]
ABC = [str(abc) for abc in ABC]

print("\n".join(ABC))