Problem:


Score: 400 points

Problem Statement

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

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

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

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

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

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

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

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

Constraints

1 \leq X \leq 1 \ 000

1 \leq Y \leq 1 \ 000

1 \leq Z \leq 1 \ 000

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

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

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

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

All values in input are integers.

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

2 2 2 8
4 6
1 5
3 8

Sample Output 1

19
17
15
14
13
12
10
8

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

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

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

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

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

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

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

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

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

Sample Input 2

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

Sample Output 2

400
310
310
301
301

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

Sample Input 3

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

Sample Output 3

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

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



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


Sample output:
19
17
15
14
13
12
10
8

Submission status: Time Limit Exceeded

Solution code:
X, Y, Z, K = map( int, input().split())
A = list( map( int, input().split()))
B = list( map( int, input().split()))
C = list( map( int, input().split()))
A.sort( key=None, reverse = True)
B.sort( key=None, reverse = True)
C.sort( key=None, reverse = True)
AB = [0]*(X*Y)
for i in range(X):
    for j in range(Y):
        AB[i*Y+j] = A[i]+B[j]
AB.sort( key=None, reverse = True)
ABC = [0]*3000000
for i in range( min(X*Y, 3000)):
    for j in range(Z):
        ABC[i*Z + j] = AB[i]+C[j]
ABC.sort( key=None, reverse = True)
for i in range(K):
    print( ABC[i])

Submission status: Time Limit Exceeded

Solution code:
I=lambda:tuple(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];print(*s(s(I(),I()),I()))

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, X, 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)

ab = [a+b for a in A for b in B]
ab.sort(reverse=True)

ans = [x+c for x in ab[:K] for c in C]
ans.sort(reverse=True)
print('\n'.join(map(str, ans[:K])))

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];print(*s(s(I(),I()),I()))

Submission status: Time Limit Exceeded

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

A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

A.sort(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])
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 = 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)
xy=[]
for a in A:
    for b in B:
        xy.append(a+b)
xy=sorted(xy,reverse=True)
xy=xy[:K]
xyz=[]
for c in C:
    for x in xy:
        xyz.append(x+c)
xyz=sorted(xyz,reverse=True)
for i in range(K):
    print(xyz[i])

Submission status: Time Limit Exceeded

Solution code:
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()
B.sort()
C.sort()
A.reverse()
B.reverse()
C.reverse()
li=[]
inf = 10**11
for i in range(X):
    for j in range(Y):
        if((i+1)*(j+1)>K): break
        for k in range(Z):
            if((i+1)*(j+1)*(k+1)<=K):
                li.append(A[i]+B[j]+C[k])
li.sort()
li.reverse()
for i in li[:K]:
    print(i)

Submission status: Time Limit Exceeded

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

A.sort(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])
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 ans:
    print(i)

Submission status: Time Limit Exceeded

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

a = sorted(a,reverse=True)
b = sorted(b,reverse=True)
c = sorted(c,reverse=True)

l = []
for i in range(x):
    for j in range(y):
            l.append(a[i] + b[j])
ll = []
for i in range(len(l)):
    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:
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)
xy=[]
for a in range(X):
    for b in range(Y):
        xy.append(A[a]+B[b])
xy=sorted(xy,reverse=True)
xy=xy[:K]
xyz=[]
for x in xy:
    for c in range(Z):
        xyz.append(x+C[c])
xyz=sorted(xyz,reverse=True)
for i in range(K):
    print(xyz[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)

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 j in ansListab:
  for i in c:
    ansList.append(i+j)

ansList.sort(reverse= True)

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

Submission status: Time Limit Exceeded

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

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

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

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:
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=[]
ans2=[]
for i in range(x):
  for j in range(y):
    ans.append(a[i]+b[j])
if len(ans)>=k:
  ans.sort()
  ans.reverse()
  ans=ans[:k]
for i in range(len(ans)):
  for j in range(z):
    ans2.append(ans[i]+c[j])
ans2.sort()
ans2.reverse()
for i in range(k):
  print(ans2[i])

Submission status: Time Limit Exceeded

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

    AB = []
    ABappend = AB.append
    for i in range(X):
        for j in range(Y):
            ABappend(A[i] + B[j])
    ABC = []
    ABCappend = ABC.append
    for i in range(X * Y):
        for j in range(Z):
            ABCappend(AB[i] + C[j])
    ABC.sort(reverse=True)
    print('\n'.join(map(str, ABC[:K])))


if __name__ == '__main__':
    main()

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

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[:min(3001, X * Y * Z + 1)]
ABC = []
for c in C:
  for ab in AB:
    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())
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
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:
                minlist = min(list)
            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 = 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)
xy=[]
for a in A:
    for b in B:
        xy.append(a+b)
xy=sorted(xy,reverse=True)
xy=xy[:K]
xyz=[]
for x in xy:
    for c in C:
        xyz.append(x+c)
xyz=sorted(xyz,reverse=True)
for i in range(K):
    print(xyz[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, a in enumerate(A):
    for j, b in enumerate(B):
        AB.append(a + b)

AB.sort(reverse=True)

ABC = []
for i, ab in enumerate(AB[:K+1]):
    for j, c in enumerate(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,B,C= [[int(i) for i in input().split()] for j in range(3)]
AB = []
ABC = []
for i in range(x):
        for j in range(y):
                AB.append(A[i]+B[j])
AB.sort(reverse = True)
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:
import numpy as np
import itertools

X, Y, Z, K = tuple([int(x) for x in str(input()).split(' ')])

A = np.array(sorted([int(x) for x in str(input()).split(' ')], reverse=True))
B = np.array(sorted([int(x) for x in str(input()).split(' ')], reverse=True))
C = np.array(sorted([int(x) for x in str(input()).split(' ')], reverse=True))

out = sorted([A[a] + B[b] + C[c] for a, b, c in itertools.product(range(len(A)), range(len(B)), range(len(C))) if (a+1)*(b+1)*(c+1) <= K], reverse=True)

for x in out[:K]:
    print(x)

Submission status: Time Limit Exceeded

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

    AB = []
    # AB.append=append
    for i in range(X):
        for j in range(Y):
            AB.append(A[i] + B[j])
    ABC = []
    for i in range(X * Y):
        for j in range(Z):
            ABC.append(AB[i] + C[j])
    ABC.sort()
    print('\n'.join(map(str, ABC[:-K-1:-1])))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# # -*- coding: utf-8 -*-
#
# X, Y, Z, K = map(int, input().split())
# A = map(int, input().split())
# B = map(int, input().split())
# C = map(int, input().split())
#
# y = []
#
# for a in A:
#     for b in B:
#         for c in C:
#             y.append(a + b + c)
#
# y = sorted(y, reverse=True)
# y = [str(n) for n in y]
#
# print("\n".join(y))

#

# -*- 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)

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

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

tmp=[]
for i in range(x):
    for j in range(y):
        tmp.append(a[i]+b[j])
tmp.sort(reverse=True)
ans=[]
for i in tmp[:3000]:
    for j in range(z):
        ans.append(i+c[j])
ans.sort(reverse=True)
for i in range(K):
    print(ans[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()))
r = [0] * x * y
tmp = min(k, x * y)
r2 = [0] * tmp * z
n = 0
for i in range(x):
  for j in range(y):
      r[n] = a[i] + b[j]
      n += 1
r.sort(reverse=True)
r = r[:tmp]
n = 0
for i in range(tmp):
  for j in range(z):
      r2[n] = r[i] + c[j]
      n += 1
r2.sort()
for i in range(k):
  print(r2[-(i+1)])

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

ans = []
for i in AB[0:k]:
    for c in C:
        ans.append(i + c)
ans.sort(reverse=True)
# print(ans[0:k])

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

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)

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

AB.sort(reverse=True)
AB = AB[:min(3001, X * Y * Z + 1)]
ABC = []
for c in C:
  for ab in AB:
    ABC.append(ab + c)
ABC.sort(reverse=True)

print(*ABC[:K], sep='\n')

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):
            heapq.heappush(T, -(A[i] + BC[j]))

    for i in range(K):
        t = -heapq.heappop(T)
        print t

if __name__ == '__main__':
    main()

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

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

ans = []
for i in AB[0:k]:
    for c in C:
        ans.append(i + c)
ans.sort(reverse=True)
# print(ans[0:k])

for i in ans[0:k]:
    print(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)
xy=[]
for a in A:
    for b in B:
        xy.append(a+b)
xy=sorted(xy,reverse=True)
xy=xy[:K]
xyz=[]
for x in xy[:K]:
    for c in C:
        xyz.append(x+c)
xyz=sorted(xyz,reverse=True)
for i in range(K):
    print(xyz[i])

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k = map(int,input().split())
a = [int(v) for v in input().split()]
b = [int(v) for v in input().split()]
c = [int(v) for v in input().split()]

a.sort()
b.sort()
c.sort()

ab = []

for v1 in a[:k]:
  for v2 in b[:k]:
    ab.append(v1+v2)
ab.sort(reverse=True)
ab = ab[:k]

ans = []

for v1 in ab:
  for v2 in c[:k]:
    ans.append(v1+v2)
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()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

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

a = sorted(a,reverse=True)
b = sorted(b,reverse=True)
c = sorted(c,reverse=True)

l = []
for i in range(min(1000,x)):
    for j in range(min(1000,y)):
            l.append(a[i] + b[j])
l = sorted(l,reverse=True)
ll = []
for i in range(len(l)):
    for j in range(min(1000,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:
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)
xy=[]
for a in A[:K]:
    for b in B[:K]:
        xy.append(a+b)
xy=sorted(xy,reverse=True)
xy=xy[:K]
xyz=[]
for x in xy[:K]:
    for c in C:
        xyz.append(x+c)
xyz=sorted(xyz,reverse=True)
for i in range(K):
    print(xyz[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 = []
for i in range(X):
    for j in range(Y):
        a.append(A[i] + B[j])
a.sort()
b = []
for i in range(min(3000, X * Y)):
    b.append(a[- i - 1])
c = []
for i in range(len(b)):
    for j in range(Z):
        c.append(b[i] + C[j])
c.sort()
for i in range(K):
    print(c[- i - 1])

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

AB = []
for a in range(x):
    for b in range(y):
        AB.append(A[a] + B[b])
AB = sorted(AB,reverse=True)[0:k]

ans = []
for i in AB:
    for c in C:
        ans.append(i + c)
ans = sorted(ans,reverse=True)[0:k]

for i in ans:
    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 = [int(input_raw[i]) for i in range(X)]
    input_raw = read_func().strip().split()
    B = [int(input_raw[i]) for i in range(Y)]
    input_raw = read_func().strip().split()
    C = [int(input_raw[i]) for i in range(Z)]

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

    A.sort(reverse = True)

    T = []
    for j in range(min(K, len(BC))):
        bc = -heapq.heappop(BC)
        for i in range(X):
            heapq.heappush(T, -(A[i] + bc))

    for i in range(K):
        t = -heapq.heappop(T)
        print t

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

sumAB =[]
index=0
while index < len(listA):
    index2=0
    while index2 < len(listB):
        sumAB.append(listA[index]+listB[index2])
        index2+=1
    index+=1
sumAB.sort()
sumAB.reverse()
abSL=[]
index3=0
while index3 < min(k, len(sumAB)):
    abSL.append(sumAB[index3])
    index3+=1

answerL=[]
index4=0
while index4 < len(abSL):
    index5=0
    while index5 < min(k,len(listC)):
        answerL.append(abSL[index4]+listC[index5])
        index5+=1
    index4+=1

answerL.sort()
answerL.reverse()
index6=0
while index6 < k:
    print(answerL[index6])
    index6+=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)
ans = []

ApB = []

for i in range(min(X, K)):
  for j in range(min(Y, K)):
      ApB.append(A[i] + B[j])

ApB.sort(reverse = True)

for i in range(min(Z, K)):
  for j in range(min(len(ApB), K)):
    ans.append(C[i] + ApB[j])

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

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[: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[:min(3001, X * Y * Z + 1)]
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())
a = [int(v) for v in input().split()]
b = [int(v) for v in input().split()]
c = [int(v) for v in input().split()]

a.sort()
b.sort()
c.sort()

ab = []

for v1 in a:
  for v2 in b:
    ab.append(v1+v2)
ab.sort(reverse=True)
ab = ab[:k]

ans = []

for v1 in ab:
  for v2 in c[:k]:
    ans.append(v1+v2)
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=[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)
if k<x: a=a[:k]
if k<y: b=b[:k]
if k<z: c=c[:k]
d=[]
ans=[]
for i in a:
    for j in b:
        d.append(i+j)
d.sort(reverse=True)
if k<len(d): d=d[:k]
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 = 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 A:
  for b in B:
    AB.append(a + b)

AB.sort(reverse=True)
AB = AB[:min(3001, X * Y * Z + 1)]
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())
listA = list(map(int, input().split()))
listB = list(map(int, input().split()))
listC = list(map(int, input().split()))
listA.sort()
listB.sort()
listC.sort()

sumAB =[]
index=0
while index < len(listA):
    index2=0
    while index2 < len(listB):
        sumAB.append(listA[index]+listB[index2])
        index2+=1
    index+=1
sumAB.sort()
sumAB.reverse()
abSL=[]
index3=0
while index3 < min(k, len(sumAB)):
    abSL.append(sumAB[index3])
    index3+=1

answerL=[]
index4=0
while index4 < len(abSL):
    index5=0
    while index5 < len(listC):
        answerL.append(abSL[index4]+listC[index5])
        index5+=1
    index4+=1

answerL.sort()
answerL.reverse()
index6=0
while index6 < k:
    print(answerL[index6])
    index6+=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)

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:
def int_raw():
    return int(input())

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

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

X,Y,Z,K = ints_raw()

A = ints_raw()
B= ints_raw()
C= ints_raw()

arg_buf = {}
def main():
    D = [a+b for a in A for b in B]
    D.sort(reverse=True)
    E = [D[d]+c for d in range(min(K,len(D))) for c in C]
    E.sort(reverse=True)
    for k in range(K):
        print(E[k])

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()))
xy=[]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
for a in A:
    for b in B:
        xy.append(a+b)
xy.sort(reverse=True)
xy=xy[:K]
xyz=[]
for x in xy:
    for c in C:
        xyz.append(x+c)
xyz.sort(reverse=True)
for i in range(K):
    print(xyz[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:li+=[h+i]
st=[]
for h in sorted(li)[-1:~k:-1]:
    for i in c:st+=[h+i]
for i in sorted(st)[-1:~k:-1]:print(i)

Submission status: Time Limit Exceeded

Solution code:
def main():
  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 = [a+b for a in A for b in B]
  res = [c+ab for c in C for ab in AB]
  res.sort(reverse = True)
  print("\n".join(list(map(str,res[:K]))))

if __name__ == "__main__":
  main()