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()))
AB = [a + b for a in A for b in B]
AB.sort()
AB = AB[-K:]
ABC = [ab + c for ab in AB for c in C]
ABC.sort()
for v in ABC[-1:-K-1:-1]:
    print(v)

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)

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

scores = [ab + c for ab in ab_scores for c in C]
scores.sort(reverse=True)

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

C.sort(reverse=True)

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

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

scores = []
for ab in ab_scores:
    for c in C:
        scores.append(ab + c)



scores.sort(reverse=True)

for i in range(K):
    print(scores[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()))
M = []
for i in range(X):
  for j in range(Y):
    for k in range(Z):
      M.append(A[i]+B[j]+C[k])
M.sort(reverse=True)
for l in range(K):
  print(M[l])

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

X, Y, Z, K = map(int, input().split())
lst_A = list(map(int, input().split()))
lst_B = list(map(int, input().split()))
lst_C = list(map(int, input().split()))
lst_A.sort(reverse=True)
lst_B.sort(reverse=True)
lst_C.sort(reverse=True)


lst_A_K = lst_A[:K]
lst_B_K = lst_B[:K]
lst_C_K = lst_C[:K]


lst_AB = sorted([a+b for a, b in product(lst_A_K, lst_B_K)], reverse=True)
lst_AB_K = lst_AB[:K]

lst_ABC = sorted([ab+c for ab, c in product(lst_AB_K, lst_C_K)], reverse=True)
lst_ABC_K = lst_ABC[:K]

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

Submission status: Time Limit Exceeded

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

A = map(int,raw_input().split())
B = map(int,raw_input().split())
C = map(int,raw_input().split())

D = []
for i in xrange(len(A)):
    for j in xrange(len(B)):
        D.append(A[i]+B[j])

D.sort(reverse = True)
E = []
for i in xrange(min(len(D),K)):
    for j in xrange(min(len(C),K)):
        E.append(D[i]+C[j])

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

X, Y, Z, K = map(int, input().split())
lst_A = list(map(int, input().split()))
lst_B = list(map(int, input().split()))
lst_C = list(map(int, input().split()))
lst_A.reverse()
lst_B.reverse()
lst_C.reverse()
lst_C_K = lst_C[:K]


lst_AB = sorted([a+b for a, b in product(lst_A, lst_B)], reverse=True)
lst_AB_K = lst_AB[:K]

lst_ABC = sorted([ab+c for ab, c in product(lst_AB_K, lst_C_K)], reverse=True)
lst_ABC_K = lst_ABC[:K]

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

Submission status: Time Limit Exceeded

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

def f(thres:int)->bool:
    """return (おいしさが thres 以上の組み合わせ) >= K
    """
    global K
    cnt = 0
    for a in range(X):
        for b in range(Y):
            for c in range(Z):
                if A[a]+B[b]+C[c]<thres:
                    break
                cnt += 1
                if cnt >= K:
                    return True
    return False

def binary_search(f, s:int, t:int)->int:
    """f: function(x:int)->bool
    f(s)=False, f(t)=True，f は広義単調増加
    return : [s, t) での f(x)=True なる最小のx
    """
    ok = s-1
    ng = t
    while ng - ok > 1:
        mid = (ok + ng)//2
        if f(mid): ok = mid
        else:      ng = mid
        # print(ng, ok, ok-ng)

    if ok==s-1:
        raise(ValueError("For all x, f(x)=False"))
    return ok

M = A[0]+B[0]+C[0]
m = A[-1]+B[-1]+C[-1]
# print(f(m), f(M))
thres = binary_search(f, m, M+1)-1
# print("thres:",thres)
ans = []
for a in range(X):
    for b in range(Y):
        for c in range(Z):
            if A[a]+B[b]+C[c]<thres:
                break
            ans.append(A[a]+B[b]+C[c])

ans.sort(reverse=True)
print("\n".join(map(str, ans[:K])))

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)

def f(thres:int)->bool:
    """return (おいしさが thres 以上の組み合わせ) >= K
    """
    global K
    cnt = 0
    for a in range(X):
        for b in range(Y):
            for c in range(Z):
                if A[a]+B[b]+C[c]<thres:
                    break
                cnt += 1
                if cnt >= K:
                    return True
    return False

def binary_search(f, s:int, t:int)->int:
    """f: function(x:int)->bool
    f(s)=False, f(t)=True，f は広義単調増加
    return : [s, t) での f(x)=True なる最小のx
    """
    ok = s-1
    ng = t
    while ng - ok > 1:
        mid = (ok + ng)//2
        if f(mid): ok = mid
        else:      ng = mid
        # print(ng, ok, ok-ng)

    if ok==s-1:
        raise(ValueError("For all x, f(x)=False"))
    return ok

M = A[0]+B[0]+C[0]
m = A[-1]+B[-1]+C[-1]
# print(f(m), f(M))
thres = binary_search(f, m, M+1)-1
# print("thres:",thres)
ans = []
for a in range(X):
    for b in range(Y):
        for c in range(Z):
            if A[a]+B[b]+C[c]<thres:
                break
            ans.append(A[a]+B[b]+C[c])

ans.sort(reverse=True)
print("\n".join(map(str, ans[:K])))

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import product


X, Y, Z, K = map(int, input().split())
lst_A = sorted(map(int, input().split()), reverse=True)
lst_B = sorted(map(int, input().split()), reverse=True)
lst_C = sorted(map(int, input().split()), reverse=True)
lst_A_K = lst_A[:K]
lst_B_K = lst_B[:K]
lst_C_K = lst_C[:K]


lst_AB = sorted([a+b for a, b in product(lst_A_K, lst_B_K)], reverse=True)
lst_AB_K = lst_AB[:K]


lst_ABC = sorted([ab+c for ab, c in product(lst_AB_K, lst_C_K)], reverse=True)
lst_ABC_K = lst_ABC[:K]


print(*lst_ABC_K, sep="\n")

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import product

read = sys.stdin.readline
X, Y, Z, K = map(int, read().split())
lst_A = sorted(map(int, read().split()), reverse=True)
lst_B = sorted(map(int, read().split()), reverse=True)
lst_C = sorted(map(int, read().split()), reverse=True)


lst_AB = sorted([a+b for a, b in product(lst_A, lst_B)], reverse=True)
lst_AB_K = lst_AB[:K]


lst_C_K = lst_C[:K]
lst_ABC = sorted([ab+c for ab, c in product(lst_AB_K, lst_C_K)], reverse=True)
lst_ABC_K = lst_ABC[:K]


print(*lst_ABC_K, sep="\n")

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import product

read = sys.stdin.readline
X, Y, Z, K = map(int, read().split())
lst_A = sorted(map(int, read().split()), reverse=True)
lst_B = sorted(map(int, read().split()), reverse=True)
lst_C = sorted(map(int, read().split()), reverse=True)


lst_AB = sorted([a+b for a, b in product(lst_A, lst_B)], reverse=True)
lst_AB_K = lst_AB[:K]
lst_ABC = sorted([ab+c for ab, c in product(lst_AB_K, lst_C)], reverse=True)
lst_ABC_K = lst_ABC[:K]


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

C.sort(reverse=True)

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

cut = min(K, len(ab_scores))
ab_scores.sort(reverse=True)
ab_scores = ab_scores[:cut]
scores = []
for ab in ab_scores:
    for c in C:
        scores.append(ab + c)



scores.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc123_d
import itertools
import math

# input
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 = range(1000)
# B = range(1000)
# C = range(1000)
# getans
A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
C = sorted(C, reverse=True)
arr = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if i*j*k > K:
                break
            arr.append(A[i]+B[j]+C[k])
#print(len(arr))
arr = sorted(arr, reverse=True)[:K]
# output
ans = '\n'.join(map(str, arr))
print(ans)

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)

ABC = []
for i in range(x):
    for j in range(y):
        if (i + 1) * (j + 1)  <= k:
            for h in range(z):
                if (i + 1) * (j + 1) * (h + 1) <= k:
                    ABC.append(A[i] + B[j] + C[h])

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,raw_input().split())

A = map(int,raw_input().split())
B = map(int,raw_input().split())
C = map(int,raw_input().split())

D = []
for i in A:
    for j in B:
        D.append(i+j)

D.sort(reverse = True)
E = []
for i in range(min(len(D),K)):
    for j in range(min(len(C),K)):
        E.append(D[i]+C[j])

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

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int, input().split())
a_array = sorted([int(x) for x in input().split()], reverse=True)
b_array = sorted([int(x) for x in input().split()], reverse=True)
c_array = sorted([int(x) for x in input().split()], reverse=True)


def solver1():
    ab_array = [x + y for x in a_array for y in b_array]
    abc_array = sorted([ab + c for ab in ab_array for c in c_array], reverse=True)
    for abc in abc_array[:k]:
        print(abc)


solver1()

Submission status: Time Limit Exceeded

Solution code:
# from collections import deque

X, Y, Z, K = map(int, input().split())
aa = [int(s) for s in input().split()]
ba = [int(s) for s in input().split()]
ca = [int(s) for s in input().split()]

# sum_ab_a = deque()
# for a in aa:
#     for b in ba:
#         sum_ab_a.append(a+b)

sum_ab_a = [a+b for a in aa for b in ba]

sum_ab_a = sorted(sum_ab_a, reverse=True)
sum_ab_a = sum_ab_a[0:K]

# ans = deque()
# for n in sum_ab_a:
#     for c in ca:
#         ans.append(n+c)

ans = [n+c for n in sum_ab_a for c in ca]

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())
A = sorted([int(a) for a in input().split()])[::-1]
B = sorted([int(a) for a in input().split()])[::-1]
C = sorted([int(a) for a in input().split()])[::-1]
L = [(0,0,0)]
for k in range(K):
    ma = 0
    for i,j,k in L:
        if A[i]+B[j]+C[k] > ma:
            ma = A[i]+B[j]+C[k]
            mai,maj,mak = i,j,k
    if mai+1<X and (mai+1,maj,mak) not in L: L.append((mai+1,maj,mak))
    if maj+1<Y and (mai,maj+1,mak) not in L: L.append((mai,maj+1,mak))
    if mak+1<Z and (mai,maj,mak+1) not in L: L.append((mai,maj,mak+1))
    print(ma)
    L.remove((mai,maj,mak))

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
x,y,z,p = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
"""
if x*y*z <= 3*10**6:
    abc = []
    for i in range(x):
        for j in range(y):
            for k in range(z):
                abc.append(a[i]+b[j]+c[k])
    abc.sort()
    abc = abc[::-1]
    for i in range(p):
        print(abc[i])  
    exit()
"""
ab = []
for i in range(x):
    for j in range(y):
        ab.append(a[i]+b[j])
ab.sort()
c = c[::-1]
ab = ab[::-1]
ab.append(-2**62)
ans = []
miru = [0]*z
for i in range(z):
    if i + 1 == z:
        d = -2**60
    else:
        d = c[i+1]+ab[0]
    for j in range(i+1):
         while ab[miru[j]] + c[j] >= d:
             ans.append(ab[miru[j]] + c[j])
             miru[j]+=1
    if len(ans) >= 3000:
        break
ans.sort()
ans = ans[::-1]
for i in range(p):
    print(ans[i])

Submission status: Time Limit Exceeded

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

abc = []

for i in range(min(len(ab),k)):
    for j in range(min(z,k)):
        abc.append(ab[-(i+1)] + c[j])

abc.sort()

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
x,y,z,k = map(int,input().split())
a,b,c = [],[],[]
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ab = []

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

ab.sort()
ab.reverse()

abc = []

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

abc.sort()
abc.reverse()

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

Submission status: Time Limit Exceeded

Solution code:
import heapq as hq

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

pri = []
data = []
hq.heapify(pri)

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

hq.heappush(pri, [-A[0]-B[0]-C[0],0,0,0])
data.append([0,0,0])

for i in range(K):
    s = pri[0][1]
    t = pri[0][2]
    u = pri[0][3]
    if s+1 <= X-1:
        if [s + 1, t, u] not in data:
            data.append([s+1, t, u])
            hq.heappush(pri, [-A[s+1]-B[t]-C[u],s+1,t,u])
    if t+1 <= Y-1:
        if [s, t+1, u] not in data:
            data.append([s, t+1, u])
            hq.heappush(pri, [-A[s]-B[t+1]-C[u],s,t+1,u])
    if u+1 <= Z-1:
        if [s, t, u+1] not in data:
            data.append([s, t, u+1])
            hq.heappush(pri, [-A[s]-B[t]-C[u+1],s,t,u+1])
    print(hq.heappop(pri)[0] * -1)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc123_d
import itertools
import math

# input
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 = range(1000)
# B = range(1000)
# C = range(1000)
# getans
arr = itertools.product(A, B)
arr = map(sum, arr)
arr = sorted(arr, reverse=True)[:K]
arr = itertools.product(arr, C)
arr = map(sum, arr)
arr = sorted(arr, reverse=True)[:K]
# output
ans = '\n'.join(map(str, arr))
print(ans)

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

from itertools import product
D=sorted([a+b for a,b in product(A,B)],reverse=True)
D=D[:K]
E=sorted([d+c for d,c in product(D,C)],reverse=True)
E=E[:K]
for i in range(K):
    print(E[i])

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K = map(int,input().split())
A = [i for i in map(int,input().split())]
B = [i for i in map(int,input().split())]
C = [i for i in map(int,input().split())]
AB = []
for a in A:
    for b in B:
        AB.append(a+b)
AB.sort(reverse=True)
ABC = []
for i in range(min(K,len(AB))):
    for j in range(len(C)):
        ABC.append(AB[i]+C[j])
ABC.sort(reverse=True)
for i in range(min(K,len(ABC))):
    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()))
C.sort(reverse=True)
C=C[:K]

from itertools import product
D=sorted([a+b for a,b in product(A,B)],reverse=True)
D=D[:K]

E=sorted([d+c for d,c in product(D,C)],reverse=True)
for i in range(K):
    print(E[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()))

from itertools import product
D=sorted([a+b for a,b in product(A,B)],reverse=True)
D=D[:K]
E=sorted([d+c for d,c in product(D,C)],reverse=True)
for i in range(K):
    print(E[i])

Submission status: Time Limit Exceeded

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


def read_ints():
    return list(map(int, read().split()))


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

from itertools import product

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

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

ABC = ABC[:K]

print(*ABC, sep='\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)

ab = []
for ai in a:
    for bj in b:
        ab.append(ai+bj)
ab.sort(reverse=True)
ab = ab[:K]
cond = []
for abi in ab:
    for cj in c:
        cond.append(abi+cj)
cond = sorted(cond, reverse=True)[:K]
for condi in cond:
    print(condi)

Submission status: Time Limit Exceeded

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


def read_ints():
    return list(map(int, read().split()))


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

from itertools import product

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

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

ABC = ABC[:K]

print(*ABC, sep='\n')

Submission status: Time Limit Exceeded

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


def read_ints():
    return list(map(int, read().split()))


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

from itertools import product

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

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

ABC = ABC[:K]

print(*ABC, sep='\n')

Submission status: Time Limit Exceeded

Solution code:
from collections import deque 

X, Y, Z, K = map(int, input().split())
aa = [int(s) for s in input().split()]
ba = [int(s) for s in input().split()]
ca = [int(s) for s in input().split()]

sum_ab_a = deque()
for a in aa:
    for b in ba:
        sum_ab_a.append(a+b)

sum_ab_a = sorted(sum_ab_a, reverse=True)
sum_ab_a = sum_ab_a[0:K]

ans = deque()
for n in sum_ab_a:
    for c in ca:
        ans.append(n+c)
ans = sorted(ans, reverse=True)
for i in range(K):
    print(ans[i])

Submission status: Time Limit Exceeded

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


def read_ints():
    return list(map(int, read().split()))


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

from itertools import product

AB = [a + b for a, b in product(A, B)]
AB.sort(reverse=True)
AB = AB[:K]

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

ABC = ABC[:K]

print(*ABC, sep='\n')

Submission status: Time Limit Exceeded

Solution code:
X, Y, Z, K = map(int, input().split())
aa = [int(s) for s in input().split()]
ba = [int(s) for s in input().split()]
ca = [int(s) for s in input().split()]

sum_ab_a = []
for a in aa:
    for b in ba:
        sum_ab_a.append(a+b)

sum_ab_a.sort(reverse=True)
sum_ab_a = sum_ab_a[0:K]

ans = []
for n in sum_ab_a:
    for c in ca:
        ans.append(n+c)
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
# Editorial solution 4
import sys

def f(a, b, c, border, cond):
    na, nb, nc = len(a), len(b), len(c)
    cnt = 0
    for i in range(na):
        for j in range(nb):
            for k in range(nc):
                if a[na-1-i] + b[nb-1-j] + c[nc-1-k] >= border:
                    cnt += nc-k
                    if cnt >= cond:
                        return True
                    break
    return False


def main():
    input = sys.stdin.readline
    X, Y, Z, K = map(int, input().split())
    A = sorted(list(map(int, input().split())), key=lambda x: -x)
    B = sorted(list(map(int, input().split())), key=lambda x: -x)
    C = sorted(list(map(int, input().split())), key=lambda x: -x)

    l, r = A[X-1] + B[Y-1] + C[Z-1], A[0] + B[0] + C[0]
    while r - l > 1:
        p = (l + r) // 2
        if f(A, B, C, p, K):
            l = p
        else:
            r = p

    deli = []
    for i in range(X):
        for j in range(Y):
            for k in range(Z):
                if A[i] + B[j] + C[k] < r:
                    break
                deli.append(A[i] + B[j] + C[k])

    num = len(deli)
    deli = sorted(deli, key=lambda x: -x)
    deli += [l] * (K - num)
    for i in range(K):
        print(deli[i])


if __name__ == '__main__':
    main()

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

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

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

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

for abc in ABC:
    print(abc)

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 = 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 a in ABC:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
# Editorial solution 4
import sys

def f(a, b, c, border, cond):
    cnt = 0
    for i in range(len(a)):
        for j in range(len(b)):
            for k in range(len(c)):
                if a[i] + b[j] + c[k] < border:
                    break
                cnt += 1
                if cnt >= cond:
                    return True
    return False


def main():
    input = sys.stdin.readline
    X, Y, Z, K = map(int, input().split())
    A = sorted(list(map(int, input().split())), key=lambda x: -x)
    B = sorted(list(map(int, input().split())), key=lambda x: -x)
    C = sorted(list(map(int, input().split())), key=lambda x: -x)

    l, r = A[X-1] + B[Y-1] + C[Z-1], A[0] + B[0] + C[0]
    while r - l > 1:
        p = (l + r) // 2
        if f(A, B, C, p, K):
            l = p
        else:
            r = p

    deli = []
    for i in range(X):
        for j in range(Y):
            for k in range(Z):
                if A[i] + B[j] + C[k] < r:
                    break
                deli.append(A[i] + B[j] + C[k])

    num = len(deli)
    deli = sorted(deli, key=lambda x: -x)
    deli += [l] * (K - num)
    for i in range(K):
        print(deli[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)

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

list1 = []
for i in range(len(list)):
    for j in range(z):
        list1.append(list[i]+c[j])
list1.sort(reverse = True)
list1 = list1[:k]

for i in range(k):
    print(list1[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()))
p = [x+y+z for x in a for y in b for z in c]

p.sort()
p.reverse()

for x in p[0:k]:
    print(x)

Submission status: Time Limit Exceeded

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

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

list1 = []
for i in range(len(list)):
    for j in range(z):
        list1.append(list[i]+c[j])
list1.sort(reverse = True)
list1 = list1[:k]

for i in range(k):
    print(list1[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 = sorted(list, reverse = True)[:k]

list1 = []
for i in range(len(list)):
    for j in range(z):
        list1.append(list[i]+c[j])
list1 = sorted(list1, reverse = True)

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


C.sort()
C.reverse()
AB =[0]*(X*Y)

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

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

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

a_list.sort(reverse = True)
b_list.sort(reverse = True)
c_list.sort(reverse = True)

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

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

Submission status: Time Limit Exceeded

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

Al = sorted(A,reverse=True)[:K]
Bl = sorted(B,reverse=True)[:K]
Cl = sorted(C,reverse=True)[:K]

ABl = []
for a in Al:
    for b in Bl:
        ABl.append(a+b)

result = []
ABl = sorted(ABl,reverse=True)[:K]
for ab in ABl:
    for c in Cl:
        result.append(ab+c)

result.sort(reverse=True)

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

Submission status: Time Limit Exceeded

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

	c_len = min(k, z)
	d_len = min(k, x*y)
	e = [0]*d_len*c_len
	for i in range(d_len):
		for j in range(c_len):
			e[i*c_len+j] = d[i] + c[j]
	e.sort(reverse=True)
	for i in range(k):
		print(e[i])


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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