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:
import pprint
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()]

yum = []

for i in range(x):
    for j in range(y):
        for k in range(x):
            yum.append(a[i] + b[j] + c[k])
yum = sorted(yum,reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
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)]

    BC = [0L for i in range((Y * Z))]
    count = 0
    for i in range(X):
        for j in range(Z):
            BC[count] = B[i] + C[j]
            count += 1




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

    T = [0 for i in range(X * min(K, len(BC)))]
    for i in range(X):
        for j in range(min(K, len(BC))):
            T.append(A[i] + BC[j])


    T.sort(reverse = True)
    for i in range(K):
        print T[i]

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

x1 = list(map(int,input().split(" ")))
y1 = list(map(int,input().split(" ")))
z1 = list(map(int,input().split(" ")))

sm = [int(i+j+l) for i in x1 for j in y1 for l in z1 ]

sm.sort(reverse=True)

for i in range(k):
    print(sm[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()))
li=[]
for h in a:
    for i in b:
        for j in c:li+=[h+i+j]
for i in sorted(li)[-1:~k:-1]:print(i)

Submission status: Time Limit Exceeded

Solution code:
from collections import OrderedDict
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)

max_b = max(B)
max_c = max(C)

def merge_sort(arr):
    if len(arr) <= 1:
        return arr

    mid = len(arr) // 2
    # ここで分割を行う
    left = arr[:mid]
    right = arr[mid:]

    # 再帰的に分割を行う
    left = merge_sort(left)
    right = merge_sort(right)

    # returnが返ってきたら、結合を行い、結合したものを次に渡す
    return merge(left, right)


def merge(left, right):
    merged = []
    l_i, r_i = 0, 0

    # ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
    while l_i < len(left) and r_i < len(right):
        # ここで=をつけることで安定性を保っている
        if left[l_i] <= right[r_i]:
            merged.append(left[l_i])
            l_i += 1
        else:
            merged.append(right[r_i])
            r_i += 1

    # 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
    if l_i < len(left):
        merged.extend(left[l_i:])
    if r_i < len(right):
        merged.extend(right[r_i:])
    return merged


summs = []
for a in A[:K]:
    if len(summs) >= K and a + max_b + max_c < summs[K-1]:
        break

    for b in B[:K]:
        if len(summs) >= K and a + b + max_c < summs[K-1]:
            break

        for c in C[:K]:
            summ = a + b + c
            if len(summs) >= K:
                min_sum = summs[K-1]    
                if summ < min_sum:
                    break
            summs.append(summ)
        summs = merge_sort(summs)
        summs.reverse()

for s in summs[0:K]:
    print(s)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
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)]

    BC = [0L for i in range((Y * Z))]
    count = 0
    for i in range(X):
        for j in range(Z):
            BC[count] = B[i] + C[j]
            count += 1




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

    T = []
    for i in range(X):
        for j in range(min(K, len(BC))):
            T.append(A[i] + BC[j])


    T.sort(reverse = True)
    for i in range(K):
        print T[i]

if __name__ == '__main__':
    main()

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_max = a[0]
b_max = b[0]
c_max = c[0]
a = [a_max - i for i in a]
b = [b_max - i for i in b]
c = [c_max - i for i in c]
sum_max = a_max + b_max + c_max
ls = []
for i in range(x):
    for j in range(y):
        for k in range(z):
            ls.append(a[i]+b[j]+c[k])

ls.sort()
for i in range(K):
    print(sum_max - ls[i])

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

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

x=sorted(list(map(int,input().split())),reverse=True)
y=sorted(list(map(int,input().split())),reverse=True)
z=sorted(list(map(int,input().split())),reverse=True)



"""
if X*Y*Z<=3000:
    ans=[]
    for i in range(X):
        for j in range(Y):
            for k in range(Z):  ans.append(x[i]+y[j]+z[k])
    ans.sort()
    for i in range(min(3000,X*Y*Z)):
        print(ans[i])
    sys.exit()
"""

yz=[]
for i in range(Y):
    yz=sorted(yz+[ y[i]+z[j] for j in range(Z)],reverse=True)

if len(yz)>3000:
    yz=yz[:3000]


n=len(yz)
ans=[]

for i in range(X):
    tmp=[yz[j]+x[i] for j in range(len(yz))]
    ans =sorted(ans+tmp,reverse=True)


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

Submission status: Time Limit Exceeded

Solution code:
import heapq

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

sum = []

count = 0

heapq.heapify(sum)

for i in range(x):
    for j in range(y):
        for k in range(z):
            s = a[i] + b[j] + c[k]
            if count >= 3000:
                if s > a[0]:
                    heapq.heappop(sum)
                    heapq.heappush(sum, s)
            else:
                count += 1
                heapq.heappush(sum, s)

sum.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:

import itertools

def main():
    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()))

    p = itertools.product(A, B, C)
    data = [i + j + k for i, j, k in p]
    data.sort(reverse=True)

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

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

A = [0]*X
A[:] = map(int, input().split())
B = [0]*Y
B[:] = map(int, input().split())
C = [0]*Z
C[:] = map(int, input().split())

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ABC = [0]*K
for x in range(X):
    for y in range(Y):
        for z in range(Z):
            if ABC[-1] > A[x]+B[y]+C[z]:
                break
            else:
                ABC[-1] = max(ABC[-1], A[x]+B[y]+C[z])    
                ABC.sort(reverse=True)
for k in range(K):
    print(ABC[k])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k = input().strip().split(' ')
x,y,z,k = [int(x), int(y),int(z),int(k)]
aList = list(map(int, input().strip().split(' ')))
bList = list(map(int, input().strip().split(' ')))
cList = list(map(int, input().strip().split(' ')))
ansList = []
aList
for i in range(min(len(aList),k)):
        for j in range(min(len(bList),k)):
                for n in range(min(len(cList),k)):
                        y = aList[i] + bList[j] + cList[n]
                        ansList.append(y)
ansList.sort(reverse = True)

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys

input = sys.stdin.readline

maxn = 10000000000

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.append(-maxn)
B.append(-maxn)
C.append(-maxn)

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

apos, bpos, cpos = 0, 0, 0

while (apos + 1) * (bpos + 1) * (cpos + 1) < min(2 * 10 ** 6, X * Y * Z):
    if (
        apos < len(A) - 2
        and abs(A[apos] - A[apos + 1]) < abs(B[bpos] - B[bpos + 1])
        and abs(A[apos] - A[apos + 1]) < abs(C[cpos] - C[cpos + 1])
    ):
        apos += 1
    elif bpos < len(B) - 2 and B[bpos] - B[bpos + 1] < C[cpos] - C[cpos + 1]:
        bpos += 1
    else:
        cpos += 1

res = []
for a in list(itertools.product(A[: apos + 1], B[: bpos + 1], C[: cpos + 1])):
    res.append(a[0] + a[1] + a[2])

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

Submission status: Time Limit Exceeded

Solution code:
X, Y, Z, K = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)
B = sorted([int(i) for i in input().split()], reverse=True)
C = sorted([int(i) for i in input().split()], reverse=True)
dA = [A[i] - A[i+1] for i in range(X-1)]
dB = [B[i] - B[i+1] for i in range(Y-1)]
dC = [C[i] - C[i+1] for i in range(Z-1)]

def get(x, y, z):
    s = 0
    if x >= X or y >= Y or z >= Z:
        return None

    # if x != 0:
        # s += A[x-1] - A[x]
    s += sum(dA[:x])
    # if y != 0:
        # s += B[y-1] - B[y]
    s += sum(dB[:y])
    # if z != 0:
        # s += C[z-1] - C[z]
    s += sum(dC[:z])
    return s


import numpy as np

arrived = []
keys = [[np.array([0, 0, 0], dtype=np.int), 0]]

for i in range(K):
    cur = keys.pop(0)
    print(A[cur[0][0]] + B[cur[0][1]] + C[cur[0][2]])
    for v in np.eye(3, dtype=np.int):
        t = get(*(cur[0] + v))
        if t is None or str(cur[0] + v) in arrived:
            continue
        keys.append([cur[0] + v, t])
        arrived.append(str(cur[0] + v))
    keys.sort(key=lambda x: x[1])

Submission status: Time Limit Exceeded

Solution code:
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")

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

A = sorted(list( map(int, input().split()) ), reverse=True)	# 1 2 3 4 5 ...(ソート付き)
B = sorted(list( map(int, input().split()) ), reverse=True)	# 1 2 3 4 5 ...(ソート付き)
C = sorted(list( map(int, input().split()) ), reverse=True)	# 1 2 3 4 5 ...(ソート付き)

p(X,Y,Z,K)
p(A)
p(B)
p(C)

from itertools import product
L = list( product(A,B,C) )		# 上と同じ意味
#p(L)

from operator import itemgetter
#p( sorted(L, key=lambda x: (x[0]+x[1]+x[2])*(-1)) )  # 0 番目の要素 * 2 番目の要素でソート

iCount=0
for l in sorted(L, key=lambda x: (x[0]+x[1]+x[2])*(-1)):
	a = l[0]+l[1]+l[2]
	print(a)
	iCount+=1
	if iCount>=K: break

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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()))
n = 0
mn = -1
r = [0] * k
for i in range(x):
  for j in range(y):
    for l in range(z):
      s = a[i] + b[j] + c[l]
      if n < k:
        r[n] = s
      else:
        if n == k:
        	mn = np.argmin(r)
        if r[mn] < s:
          r[mn] = s
          mn = np.argmin(r)
      n += 1
r.sort()
for i in range(k):
  print(r[-(i+1)])

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

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 product(A, B, C):
    l += [sum(i)]

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

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int, input().split())
ABC = [list(map(int, input().split())) + [-10**10] for _ in range(3)]
for i in range(3):
    ABC[i].sort(reverse = True)
yum = []
def yummy(a, b, c):
    if str(a)+str(b)+str(c) in yum:
        return max(yummy(a + 1, b, c), yummy(a, b + 1, c), yummy(a, b, c + 1))
    else:
        return [ABC[0][a]+ABC[1][b]+ABC[2][c], str(a)+str(b)+str(c)]
for _ in range(k):
    a, b, c = 0, 0, 0
    ans, s = yummy(a,b,c)
    print(ans)
    yum.append(s)

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k = map(int,input().split())
lisa = list(map(int,input().split()))
lisb = list(map(int,input().split()))
lisc = list(map(int,input().split()))
an = []
ans = []
for num in lisb:
    for nu in lisa:an.append(num+nu)
an.sort(reverse=True)
an = an[:min(3001,x*y*z+1)]
for num in lisc:
    for nu in an:ans.append(num+nu)
ans.sort(reverse=True)
for i in range(k):print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
x, y, z, pos = 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)
result = []
for i in range(x):
    for j in range(y):
        for k in range(z):
            result.append(a[i] + b[j] + c[k])
            if len(result) == pos: break
result.sort(reverse=True)
for x in range(pos):
    print(result[x])

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K=map(int,input().split())
A=map(int,input().split())
B=map(int,input().split())
C=map(int,input().split())
A=list(A)
B=list(B)
C=list(C)
s=[]
count=0
for i in range(len(A)):
    for j in range(len(B)):
        for k in range(len(C)):
            count+=1
            if count>3000:
                if A[i]+B[j]+C[k]<max(s):
                    s+=[A[i]+B[j]+C[k]]
                    s.remove(max(s))
            else:
                s+=[A[i]+B[j]+C[k]]
s.sort(reverse=True)
for i in range(K):
    print(s[i])

Submission status: Time Limit Exceeded

Solution code:
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]


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

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

abc = [[0,0,0]]
#next_abc = [[1,0,0],[0,1,0],[0,0,1]]
#print(A[abc[0][0]]+B[abc[0][1]]+C[abc[0][2]])

for i in range(K):
    max_v = 0
    for j in range(len(abc)):
        if A[abc[j][0]]+B[abc[j][1]]+C[abc[j][2]] > max_v:
            max_v = A[abc[j][0]]+B[abc[j][1]]+C[abc[j][2]]
            temp_j = j
            
    max_abc = abc.pop(temp_j)
    #print(max_abc)
    #print(A[max_abc[0]]+B[max_abc[1]]+C[max_abc[2]])
    print(max_v)
    
    if max_abc[0]<X-1:
        abc.append([max_abc[0]+1,max_abc[1],max_abc[2]])
    if max_abc[1]<Y-1:
        abc.append([max_abc[0],max_abc[1]+1,max_abc[2]])
    if max_abc[2]<Z-1:
        abc.append([max_abc[0],max_abc[1],max_abc[2]+1])
    abc = get_unique_list(abc)
    #print(abc)

Submission status: Time Limit Exceeded

Solution code:
line = input().split(sep=" ")
x = int(line[0])
y = int(line[1])
z = int(line[2])
in_k = int(line[3])


in_x = list(map(int,input().split(sep=" ")))
in_y = list(map(int,input().split(sep=" ")))
in_z = list(map(int,input().split(sep=" ")))

ans_arr = []

for i in range(x):
	for j in range(y):
		for k in range(z):
			ans_arr.append(in_x[i] + in_y[j] + in_z[k])

ans_arr = sorted(ans_arr,reverse=True)

for i in range(in_k):
	print(ans_arr[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()))

li = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            li.append(A[i] + B[j] + C[k])
li.sort()
li.reverse()

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

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush, heappop

X, Y, Z, K = map(int, input().split())
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
h = []

maxv = A[0] + B[0] + C[0]


def inv(v):
    return maxv - v


pushed = []
heappush(h, (0, 0, 0, 0))
for _ in range(K):
    invv, i, j, k = heappop(h)
    print(inv(invv))
    if i + 1 < X and (i + 1, j, k) not in pushed:
        heappush(h, (inv(A[i + 1] + B[j] + C[k]), i + 1, j, k))
        pushed.append((i + 1, j, k))
    if j + 1 < Y and (i, j + 1, k) not in pushed:
        heappush(h, (inv(A[i] + B[j + 1] + C[k]), i, j + 1, k))
        pushed.append((i, j + 1, k))
    if k + 1 < Z and (i, j, k + 1) not in pushed:
        heappush(h, (inv(A[i] + B[j] + C[k + 1]), i, j, k + 1))
        pushed.append((i, j, k + 1))

Submission status: Time Limit Exceeded

Solution code:
num = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

d = []
for i_a in range(len(a)):
  for i_b in range(len(b)):
    for i_c in range(len(c)):
      s = a[i_a] + b[i_b] + c[i_c]
      if len(d) < num[3]:
        d.append(s)
      else:
        if min(d) < s:
          m = min(d)
          d.remove(m)
          d.append(s)

for j in range(len(d)):
  n = max(d)
  print(n)
  d.remove(n)

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)

sums = []
lower = a[min(X-1,20)]+b[min(Y-1,20)]+c[min(Z-1,20)]
b_max,c_max = max(b),max(c)
for i in range(X):
    if a[i]+b_max+c_max<lower:
        break
    for j in range(Y):
        if a[i]+b[j]+c_max<lower:
            break
        for k in range(Z):
            s = a[i]+b[j]+c[k]
            if s<lower:
                break
            sums.append(s)
sums.sort(reverse=True)
for si in sums[:K]:
    print(si)

Submission status: Time Limit Exceeded

Solution code:
x , y ,z , k = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = [p+q+r for p in a for q in b for r in c]

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

Submission status: Time Limit Exceeded

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

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

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

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


ABX=[AB[0]-ab for ab in AB]
CX=[C[0]-c for c in C]

ABX.append(float("inf"))
CX.append(float("inf"))

j=0
for i in range(X*Y):
    while j<Z-1 and CX[j]<ABX[i]:
        j+=1

    if (i+1)*(j+1)>K:
        break

#print(i,j)

MIN=AB[i]+C[j]
MAX=AB[0]+C[0]-MIN
LIST=[]

for ii in range(X*Y):
    if AB[0]-AB[ii]>MAX:
        break
    for jj in range(Z):
        if AB[ii]+C[jj]>=MIN:
            LIST.append(AB[ii]+C[jj])
        else:
            break

LIST.sort(reverse=True)

for j in range(K):
    print(LIST[j])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
x, y, z, k = map(int, input().split())
a_s = list(map(int, input().split()))
b_s = list(map(int, input().split()))
c_s = list(map(int, input().split()))

deliciouses = []
for a in a_s:
    for b in b_s:
        for c in c_s:
            deliciouses.append(a+b+c)

for d in sorted(deliciouses, reverse=True)[:k]:
    print(d)

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int, input().split())
a_cakes = sorted(list(map(int, input().split())), reverse=True)
b_cakes = sorted(list(map(int, input().split())), reverse=True)
c_cakes = sorted(list(map(int, input().split())), reverse=True)

total = []

for i in range(len(a_cakes)):
  for j in range(len(b_cakes)):
    for h in range(len(c_cakes)):
      total.append(a_cakes[i] + b_cakes[j] + c_cakes[h])

for i, v in enumerate(sorted(total, reverse=True)):
  if i <= (k-1):
    print(v)
  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()))

if x>200:
  a.sort()
  a.reverse()
  a=a[0:200]

if y>200:
  b.sort()
  b.reverse()
  b=b[0:200]

if z>200:
  c.sort()
  c.reverse()
  c=c[0:200]

lena=len(a)
lenb=len(b)
lenc=len(c)
  
ansList=[]
for m in range(lena):
  for n in range(lenb):
    for o in range(lenc):
      ansList.append(a[m]+b[n]+c[o])

ansList.sort()
ansList.reverse()

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

selection = [0, 0, 0]
a.sort()
b.sort()
c.sort()

deli = list()

for aa in range(x):
    for bb in range(y):
        for cc in range(z):
            deli.append(a[aa] + b[bb] + c[cc])

deli.sort()
# print(deli)

for i in range(k):
    print(deli.pop())

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

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

Submission status: Time Limit Exceeded

Solution code:

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

A = [0]*X
A[:] = map(int, input().split())
B = [0]*Y
B[:] = map(int, input().split())
C = [0]*Z
C[:] = map(int, input().split())

#A.sort(reverse=True)
#B.sort(reverse=True)
#C.sort(reverse=True)
ABC = [0]*K
for x in range(X):
    for y in range(Y):
        for z in range(Z):
            ABC[-1] = max(ABC[-1], A[x]+B[y]+C[z])    
            ABC.sort(reverse=True)
for k in range(K):
    print(ABC[k])

Submission status: Time Limit Exceeded

Solution code:
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
sum = [(i + j + k)for i in A for j in B for k in C]
sum.sort(reverse = True)
for i in range(K):
    print(sum[i])

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = []

for l in range(len(A)):
    for m in range(len(B)):
        for n in range(len(C)):
            ans.append(A[l]+B[m]+C[n])
ans.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
def int_raw():
    return int(input())


def ss_raw():
    return raw_input().split()


def ints_raw():
    return list(map(int, ss_raw()))


def diff_array(array):
    return [array[i + 1] - array[i] for i in xrange(len(array) - 1)]


X, Y, Z, K = ints_raw()
A = ints_raw()
sorted_A = sorted(A, reverse=True)
B = ints_raw()
sorted_B = sorted(B, reverse=True)
C = ints_raw()
sorted_C = sorted(C, reverse=True)

current_A = 0
current_B = 0
current_C = 0


def diff(array, index):
    if len(array) <= index:
        return 10000000000
    return array[0] - array[index]


count = 0
while count < 2000:
    count += 1
    a = diff(sorted_A, current_A + 1)
    b = diff(sorted_B, current_B + 1)
    c = diff(sorted_C, current_C + 1)
    if a <= b and a <= c and current_A < X - 1:
        current_A += 1
        continue
    if b <= c and b <= a and current_B < Y - 1:
        current_B += 1
        continue
    if c <= a and c <= b and current_C < Z - 1:
        current_C += 1
        continue

result = []
for i in xrange(current_A + 1):
    for j in xrange(current_B + 1):
        for k in xrange(current_C + 1):
            result.append(sorted_A[i] + sorted_B[j] + sorted_C[k])

sorted_result = sorted(result, reverse=True)
for i in xrange(K):
    print(sorted_result[i])

Submission status: Time Limit Exceeded

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

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

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

a = []
b = []
c = []

for i in range(1,len(A)):
    a.append(abs(A[i]-A[i-1]))
for i in range(1,len(B)):
    b.append(abs(B[i]-B[i-1]))
for i in range(1,len(C)):
    c.append(abs(C[i]-C[i-1]))


ans = A[0] + B[0] + C[0]

anse = []

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

anse.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappop, heappush

X, Y, Z, K = [int(s) for s in input().split()]
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]
h = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            heappush(h, -(A[i] + B[j] + C[k]))
for _ in range(K):
    print(-heappop(h))

Submission status: Time Limit Exceeded

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

info = [list(map(int,input().split())) for i in range(3)]

li = []
ans = []
li_append = li.append 
ans_append = ans.append

for i in info[0]:
  for j in info[1]:
    li_append(i+j)
li = sorted(li,reverse=True)

for i in li[:3000]:
  for j in info[2]:
    ans_append(i+j)
ans = sorted(ans,reverse = True)

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

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k = map(int,input().split())
lisa = list(map(int,input().split()))
lisb = list(map(int,input().split()))
lisc = list(map(int,input().split()))
an = []
ans = []
for i in range(x):
    for j in range(y):
        an.append(lisa[i]+lisb[j])
an.sort(reverse=True)
an = an[:min(3001,x*y*z+1)]
for num in lisc:
    for nu in an:
        ans.append(num+nu)
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])

Submission status: Time Limit Exceeded

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

list = []
for i in range(x):
    for j in range(y):
        list.append(a[i]+b[j])
list.sort(reverse = True)
list1 = []
for i in range(min(k,x*y)):
    for j in range(y):
        list1.append(list[i]+c[j])
list1.sort(reverse = True)
for i in range(k):
    print(list1[i])

Submission status: Time Limit Exceeded

Solution code:
import itertools
X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
L = [A,B,C]
M = list(itertools.product(*L))
T = []
for i in range(len(M)):
  T.append(sum(M[i]))
T.sort()
for i in range(len(T)-1,len(T)-K-1,-1):
  print(T[i])

Submission status: Time Limit Exceeded

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

ans = []

AA = sorted(A, key=lambda a: -a)
BB = sorted(B, key=lambda a: -a)
CC = sorted(C, key=lambda a: -a)
for a in AA:
    for b in BB:
        for c in CC:
            ans.append(a+b+c)

for an in sorted(ans, key=lambda p: -p)[:K]:
    print(an)