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 = [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()]
m1 = []
m2 = []
for ai in a:
  for bi in b:
    m1.append(ai+bi)
m1.sort(reverse=True)
if x * y > k:
  l = k
else:
  l = x * y
for i in range(l):
  for ci in c:
    m2.append(m1[i] + ci)
for i in range(k):
  ans = max(m2)
  print(ans)
  m2.remove(ans)

Submission status: Time Limit Exceeded

Solution code:
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()]
m = []
for ai in a:
  for bi in b:
    for ci in c:
      m.append(ai+bi+ci)
for i in range(k):
  print(max(m))
  m.remove(max(m))

Submission status: Time Limit Exceeded

Solution code:
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()]
a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)
del a[k:]
del b[k:]
del c[k:]
m = []
for ai in a:
  for bi in b:
    for ci in c:
      m.append(ai+bi+ci)
m.sort(reverse = True)
for i in range(k):
  print(m[i])

Submission status: Time Limit Exceeded

Solution code:
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()]
m = []
for ai in a:
  for bi in b:
    for ci in c:
      m.append(ai+bi+ci)
m.sort(reverse = True)
for i in range(k):
  print(m[i])

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K=map(int,input().split())
A= [int(a) for a in input().split()]
B= [int(a) for a in input().split()]
C= [int(a) for a in input().split()]
minA=min(A)
minB=min(B)
minC=min(C)
normA=sorted([a-minA for a in A])
normB=sorted([a-minB for a in B])
normC=sorted([a-minC for a in C])
listXYZ=[]
for ai in range(min(X,3000)):
    for bi in range(min(Y,3000)):
        for ci in range(min(Z,3000)):
            listXYZ.append(normA[-ai-1]+normB[-bi-1]+normC[-ci-1])
listXYZ.sort()
for k in range(K):
    print(listXYZ[-k-1]+minA+minB+minC)

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K=map(int,input().split())
A= [int(a) for a in input().split()]
B= [int(a) for a in input().split()]
C= [int(a) for a in input().split()]
minA=min(A)
minB=min(B)
minC=min(C)
normA=sorted([a-minA for a in A])
normB=sorted([a-minB for a in B])
normC=sorted([a-minC for a in C])
normA.reverse()
normB.reverse()
normC.reverse()
listXYZ=[]
for ai in range(min(X,3000)):
    for bi in range(min(Y,3000)):
        for ci in range(min(Z,3000)):
            listXYZ.append(normA[ai]+normB[bi]+normC[ci])
listXYZ.sort()
listXYZ.reverse()
for k in range(K):
    print(listXYZ[k]+minA+minB+minC)

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K=map(int,input().split())
A= [int(a) for a in input().split()]
B= [int(a) for a in input().split()]
C= [int(a) for a in input().split()]
minA=min(A)
minB=min(B)
minC=min(C)
normA=[a-minA for a in A]
normB=[a-minB for a in B]
normC=[a-minC for a in C]
listXYZ=[]
for a in normA:
    for b in normB:
        for c in normC:
            listXYZ.append(a+b+c)
listXYZ.sort()
listXYZ.reverse()
for k in range(K):
    print(listXYZ[k]+minA+minB+minC)

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)

tmp = []
for x in range(X):
    for y in range(Y):
        tmp.append(A[x] + B[y])
        
tmp.sort(reverse=True)

res = []
for i in range(min(K, X*Y)):
    for z in range(Z):
        res.append(tmp[i] + C[z])
 
res.sort(reverse=True)
for i in range(K):
    print(res[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()))

D=[]
if K<X:
    for i in range(K):
        A=[A[i]]
if K<Y:
    for j in range(K):
        B=[B[j]]
if K<Z:
    for k in range(K):
        C=[C[k]]
for x in A:
    for y in B:
        for z in C:
            D.append(x+y+z)
D=sorted(D,reverse=True)

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

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)

ans = []

for j in range(X):
    flag2 = 0
    for k in range(Y):
        flag = 0
        for l in range(Z):
            if j*k*l+1 <= K:
                ans.append(A[j]+B[k]+C[l])
            else: 
                if l == 0:
                    flag = 1
                break
        if k == 0 and flag == 1:
            flag2 = 1
            break
    if flag2 == 1:
        break


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 = 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~Cは降順でソート済み
lenA = X
lenB = Y
lenC = Z #分かりにくいので名前を変えただけ

AB = []

for i in range(0, min(K,lenA)):
  for j in range(0, min(K,lenB)):
      AB.append(A[i]+B[j])
AB.sort(reverse=True)

ABC = []

for j in range(0, min(K,len(AB))):
  for k in range(0, min(K,lenC)):
      ABC.append(AB[j]+C[k])
ABC.sort(reverse=True)

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

N = min(X,Y,Z)
ans = []
SUM = []
for i in range(N):
    SUM.append(A[i]+B[i]+C[i])

for i in range(N):
    ans = []
    for j in range(X):
        flag2 = 0
        for k in range(Y):
            flag = 0
            for l in range(Z):
                if A[j]+B[k]+C[l] >= SUM[i]:
                    ans.append(A[j]+B[k]+C[l])
                else: 
                    if l == 0:
                        flag = 1
                    break
            if k == 0 and flag == 1:
                flag2 = 1
                break
        if flag2 == 1:
            break
    if len(ans) >= K:
        break

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()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

N = min(X,Y,Z)
ans = []
SUM = []
for i in range(N):
    SUM.append(A[i]+B[i]+C[i])

for i in range(N):

    for j in range(X):
        flag2 = 0
        for k in range(Y):
            flag = 0
            for l in range(Z):
                if A[j]+B[k]+C[l] <= SUM[i]:
                    ans.append(A[j]+B[k]+C[l])
                elif l == 0:
                    flag = 1
                    break
            if k == 0 and flag == 1:
                flag2 = 1
                break
        if flag2 == 1:
            break
    if len(ans) >= K:
        break

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

Submission status: Time Limit Exceeded

Solution code:
x, y, z, o = [int(_) for _ in input().split()]
a = sorted([int(_) for _ in input().split()])[::-1]
b = sorted([int(_) for _ in input().split()])[::-1]
c = sorted([int(_) for _ in input().split()])[::-1]

def isBorder(p):
    l = []
    for i in range(x):
        for j in range(y):
            for k in range(z):
                if a[i]+b[j]+c[k] < p : break
                l.append(a[i]+b[j]+c[k])
    return l if len(l) >= o else []

l, r = 0, a[0]+b[0]+c[0]
while True:
    if r==l : break
    p = (l+r)//2
    q = isBorder(p)
    if q == []:
        r = p-1
    else:
        l = p+1
q.sort(reverse=True)
for i in range(o):
    print(q[i])

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

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

heap = []
heapq.heappush(heap, (-(A[0] + B[0] + C[0]), 0, 0, 0))
history = set()
while len(history) < K:
    d, a, b, c = heapq.heappop(heap)
    if a + 1 < X:
        heapq.heappush(heap, (-(A[a + 1] + B[b] + C[c]), a + 1, b, c))
    if b + 1 < Y:
        heapq.heappush(heap, (-(A[a] + B[b + 1] + C[c]), a, b + 1, c))
    if c + 1 < Z:
        heapq.heappush(heap, (-(A[a] + B[b] + C[c + 1]), a, b, c + 1))
    if (a, b, c) not in history:
        history.add((a, b, c))
        print(-d)

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()))
delicious=[]
for i in range(x):
  for j in range(y):
    for l in range(z):
      delicious.append(a[i]+b[j]+c[l])
delicious=sorted(delicious)[::-1]
for i in range(k):
  print(delicious[i])

Submission status: Time Limit Exceeded

Solution code:
x,y,z,kk = [int(s) for s in input().split()]
a = [[int(s) for s in input().split()] for i in range(3)]
r = []
for i in a[0]:
    for j in a[1]:
        for k in a[2]:
            r.append(i+j+k)
r = sorted(r,reverse=True)
for i in range(kk):
    print(r[i])

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
c = [int(_) for _ in input().split()]
ab = []
for i in range(x):
    for j in range(y):
        ab.append(a[i] + b[j])
ab.sort(reverse=True)
abc = []
for i in range(min(k, x*y)):
    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 = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
c = [int(_) for _ in input().split()]
ab = []
for i in range(x):
    for j in range(y):
        ab.append(a[i] + b[j])
ab = sorted(ab)[::-1][:k]
abc = []
for i in range(min(k, x*y)):
    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:
# coding: utf-8

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

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

a.reverse()
b.reverse()
c.reverse()

l = []

for i in a:
    for j in b:
        for m in c:
            l.append(i+j+m)

l.sort()
l.reverse()

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

Submission status: Time Limit Exceeded

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

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)

yam = []
for l in range(x):
    for m in range(y):
        for n in range(z):
            yam.append(a[l]+b[m]+c[n])
yam.sort(reverse=True)
#print(yam)

for l in range(k):
        print(yam[l])

Submission status: Time Limit Exceeded

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

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

yam = []
for l in range(x):
    for m in range(y):
        for n in range(z):
            yam.append(a[l]+b[m]+c[n])
yam.sort(reverse=True)
#print(yam)

for l in range(k):
        print(yam[l])

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k = map(int,input().split())
num_list = [list(map(int,input().split())) for i in range(3)]

sum_list = []
for i in range(len(num_list[0])):
    for j in range(len(num_list[1])):
        for l in range(len(num_list[2])):
            sum_list.append(num_list[0][i] + num_list[1][j] + num_list[2][l])

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

for i in range(len(a)):
  for l in range(len(b)):
    ab_sum.append(a[i]+b[l])
		
ab_sum.sort()
c.sort()
ab_sum.reverse()
c.reverse()
ans = []
for i in range(min(k,len(ab_sum))):
	for l in range(min(k,len(c))):
		ans.append(ab_sum[i]+c[l])
		
ans.sort()
ans.reverse()
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()))
L = []
for a in A:
  for b in B:
    L.append(a + b)
L.sort(reverse = True)
ans = []
for i, l in enumerate(L):
  if i == K:
    break
  else:
    for c in C:
      ans.append(l + c)
ans.sort(reverse = True)
for i, a in enumerate(ans):
  if i == K:
    break
  else:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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


AB = [x+y for x,y in itertools.product(A,B)]
AB.sort(reverse = True)
AB = AB[:3000]

ABC = [x+y for x,y in itertools.product(AB,C)]
ABC.sort(reverse=True)

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

l = []

for p in range(0,x):
    for q in range(0,y):
        for r in range(0,z):
            if len(l) > k:
                heapq.heappushpop(l,a[p]+b[q]+c[r])
            else:
                heapq.heappush(l,a[p]+b[q]+c[r])

l.sort()

for i in range(1,k+1):
    print(l[-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)


# Priority QueueとしてHeapを使う
# Pythonのheapqは小さい順に取り出すので、-1を掛けて負数としてpushしていく
#   (-Ai-Bj-Ck, i, j, k)
# 取り出したi, j, kについて、(i+1, j, k), (i, j+1, k), (i, j, k+1)に対応するタプルをpushする
# ただし、すでにpushした値は入れないようにする

import heapq

def make(i, j, k):
    return (-A[i]-B[j]-C[k], i, j, k)


used = [[[False] * Z for i in range(Y)] for j in range(X)]
l = []

heapq.heappush(l, make(0, 0, 0))
used[0][0][0] = True

for cnt in range(K):
    V, i, j, k = heapq.heappop(l)
    
    if i < X - 1 and not used[i+1][j][k]:
        heapq.heappush(l, make(i+1, j, k))
        used[i+1][j][k] = True
    
    if j < Y - 1 and not used[i][j+1][k]:
        heapq.heappush(l, make(i, j+1, k))
        used[i][j+1][k] = True
    
    if k < Z - 1 and not used[i][j][k+1]:
        heapq.heappush(l, make(i, j, k+1))
        used[i][j][k+1] = True
    
    print(-V)

Submission status: Time Limit Exceeded

Solution code:
import heapq

X, Y, Z, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
A = [-a for a in A]
B = sorted(list(map(int, input().split())), reverse=True)
B = [-b for b in B]
C = sorted(list(map(int, input().split())), reverse=True)
C = [-c for c in C]

unchecked = {}

h = []
heapq.heappush(h, (A[0]+B[0]+C[0], 0, 0, 0))
counter = 0
while counter < K:
    val, i, j, k = heapq.heappop(h)
    if unchecked.setdefault("{},{},{}".format(i, j, k), True):
        unchecked["{},{},{}".format(i, j, k)] = False
        print(- val)
        counter += 1
    if i+1 < X:
        heapq.heappush(h, (A[i+1] + B[j] + C[k], i+1, j, k))
    if j+1 < Y:
        heapq.heappush(h, (A[i] + B[j+1] + C[k], i, j+1, k))
    if k+1 < Z:
        heapq.heappush(h, (A[i] + B[j] + C[k+1], i, j, k+1))

Submission status: Time Limit Exceeded

Solution code:
X, Y, Z, K = map(int, input().split())
A = list(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)


# Priority QueueとしてHeapを使う
# Pythonのheapqは小さい順に取り出すので、-1を掛けて負数としてpushしていく
#   (-Ai-Bj-Ck, i, j, k)
# 取り出したi, j, kについて、(i+1, j, k), (i, j+1, k), (i, j, k+1)に対応するタプルをpushする
# ただし、すでにpushした値は入れないようにする

import heapq



def make(i, j, k):
    return (-A[i]-B[j]-C[k], i, j, k)

# class flags:
#     def __init__(self, X, Y, Z):
#         self.ar = []
#         for k in range(X):
#             l = []
#             for j in range(Y):
#                 ll = []
#                 for i in range(Z):
#                     ll.append(False)
#                 l.append(ll)
#             self.ar.append(l)
        
#     def __getitem__(self, item):
#         return self.ar[item[0]][item[1]][item[2]]
    
#     def __setitem__(self, item, value):
#         self.ar[item[0]][item[1]][item[2]] = value
        

used = [[[False] * Z for i in range(Y)] for j in range(X)]

def push_next(l, i, j, k):
    if i < X - 1 and not used[i+1][j][k]:
        heapq.heappush(l, make(i+1, j, k))
        used[i+1][j][k] = True
    
    if j < Y - 1 and not used[i][j+1][k]:
        heapq.heappush(l, make(i, j+1, k))
        used[i][j+1][k] = True
    
    if k < Z - 1 and not used[i][j][k+1]:
        heapq.heappush(l, make(i, j, k+1))
        used[i][j][k+1] = True



l = []

heapq.heappush(l, make(0, 0, 0))
used[0][0][0] = True

for cnt in range(K):
    V, i, j, k = heapq.heappop(l)
    push_next(l, i, j, k)
    
    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()))

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


# Priority QueueとしてHeapを使う
# Pythonのheapqは小さい順に取り出すので、-1を掛けて負数としてpushしていく
#   (-Ai-Bj-Ck, i, j, k)
# 取り出したi, j, kについて、(i+1, j, k), (i, j+1, k), (i, j, k+1)に対応するタプルをpushする
# ただし、すでにpushした値は入れないようにする

import heapq



def make(i, j, k):
    return (-A[i]-B[j]-C[k], i, j, k)

# class flags:
#     def __init__(self, X, Y, Z):
#         self.ar = []
#         for k in range(X):
#             l = []
#             for j in range(Y):
#                 ll = []
#                 for i in range(Z):
#                     ll.append(False)
#                 l.append(ll)
#             self.ar.append(l)
        
#     def __getitem__(self, item):
#         return self.ar[item[0]][item[1]][item[2]]
    
#     def __setitem__(self, item, value):
#         self.ar[item[0]][item[1]][item[2]] = value
        

used = []
for i in range(X):
    l = []
    for j in range(Y):
        ll = []
        for k in range(Z):
            ll.append(False)
        l.append(ll)
    used.append(l)

def push_next(l, i, j, k):
    if i < X - 1 and not used[i+1][j][k]:
        heapq.heappush(l, make(i+1, j, k))
        used[i+1][j][k] = True
    
    if j < Y - 1 and not used[i][j+1][k]:
        heapq.heappush(l, make(i, j+1, k))
        used[i][j+1][k] = True
    
    if k < Z - 1 and not used[i][j][k+1]:
        heapq.heappush(l, make(i, j, k+1))
        used[i][j][k+1] = True



l = []

heapq.heappush(l, make(0, 0, 0))
used[0][0][0] = True

for cnt in range(K):
    V, i, j, k = heapq.heappop(l)
    push_next(l, i, j, k)
    
    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()))

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


# Priority QueueとしてHeapを使う
# Pythonのheapqは小さい順に取り出すので、-1を掛けて負数としてpushしていく
#   (-Ai-Bj-Ck, i, j, k)
# 取り出したi, j, kについて、(i+1, j, k), (i, j+1, k), (i, j, k+1)に対応するタプルをpushする
# ただし、すでにpushした値は入れないようにする

import heapq



def make(i, j, k):
    return (-A[i]-B[j]-C[k], i, j, k)

class flags:
    def __init__(self, X, Y, Z):
        self.ar = []
        for k in range(X):
            l = []
            for j in range(Y):
                ll = []
                for i in range(Z):
                    ll.append(False)
                l.append(ll)
            self.ar.append(l)
        
    def __getitem__(self, item):
        return self.ar[item[0]][item[1]][item[2]]
    
    def __setitem__(self, item, value):
        self.ar[item[0]][item[1]][item[2]] = value
        

used = flags(X,Y,Z)
def push_next(l, i, j, k):
    if i < X - 1 and not used[i+1, j, k]:
        heapq.heappush(l, make(i+1, j, k))
        used[i+1, j, k] = True
    
    if j < Y - 1 and not used[i, j+1, k]:
        heapq.heappush(l, make(i, j+1, k))
        used[i, j+1, k] = True
    
    if k < Z - 1 and not used[i, k, k+1]:
        heapq.heappush(l, make(i, j, k+1))
        used[i, j, k+1] = True



l = []

heapq.heappush(l, make(0, 0, 0))
used[0, 0, 0] = True

for cnt in range(K):
    V, i, j, k = heapq.heappop(l)
    push_next(l, i, j, k)
    
    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()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
sum_list = []
for a_i in range(x):
    for b_i in range(y):
        for c_i in range(z):
            if a_i*b_i*c_i > k:
                continue
            sum_list.append(a[a_i]+b[b_i]+c[c_i])
sum_list.sort(reverse=True)
for i in range(k):
    print(sum_list[i])

Submission status: Time Limit Exceeded

Solution code:
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
AB = []
for i in A:
    for j in B:
        AB.append(i + j)


AB = sorted(AB, reverse=True)[:K]
C = sorted(C, reverse=True)
ans = []
for i in C:
    for j in AB:
        ans.append(i + j)

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

Submission status: Time Limit Exceeded

Solution code:
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)
ABC=[]
for ab in sorted(AB, reverse=True)[:K]:
	for c in C:
		ABC.append(ab+c)
for abc in sorted(ABC, reverse=True)[:K]:
	print(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()))
AB=[]
for a in A:
	for b in B:
		AB.append(a+b)
ABC=[]
for ab in sorted(AB, reverse=True)[:K]:
	for c in C:
		ABC.append(ab+c)
for abc in sorted(ABC, reverse=True)[:K]:
	print(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()))
AB=[]
for a in A[:K]:
	for b in B[:K]:
		AB.append(a+b)
AB.sort(reverse=True)
ABC=[]
for ab in AB[:K]:
	for c in C[:K]:
		ABC.append(ab+c)
ABC.sort(reverse=True)
for abc in ABC[:K]:
	print(abc)

Submission status: Time Limit Exceeded

Solution code:
import heapq as hq
x, y, z, k = map(int,input().split())
arr_a = sorted(list(map(int,input().split())) ,reverse = True)
arr_b = sorted(list(map(int,input().split())) ,reverse = True)
arr_c = sorted(list(map(int,input().split())) ,reverse = True)

cnt = [[[0 for i in range(z)] for j in range(y)] for k in range(x)]
P_q = [[-(arr_a[0] + arr_b[0] + arr_c[0]),0,0,0]]

cnt[0][0][0] = 1
for _ in range(k):
    tmp = hq.heappop(P_q)
    t, i, j, k = -tmp[0],tmp[1],tmp[2],tmp[3]
    print(t)
    if i + 1 < x and cnt[i+1][j][k] == 0:
        hq.heappush(P_q,[-(arr_a[i+1] + arr_b[j] + arr_c[k]) ,i + 1,j,k])
        cnt[i+1][j][k] = 1
    if j + 1 < y and cnt[i][j + 1][k] == 0:
        hq.heappush(P_q,[-(arr_a[i] + arr_b[j+1] + arr_c[k]) ,i ,j + 1,k])
        cnt[i][j+1][k] = 1
    if k + 1 < z and cnt[i][j][k + 1] == 0:
        hq.heappush(P_q,[-(arr_a[i] + arr_b[j] + arr_c[k + 1]) ,i,j,k + 1])
        cnt[i][j][k + 1] = 1

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k=map(int,input().split())
list_a=list(map(int,input().split()))
list_b=list(map(int,input().split()))
list_c=list(map(int,input().split()))
list_a.sort(reverse=True)
list_b.sort(reverse=True)
list_c.sort(reverse=True)
dict_p={}
dict_p[(0,0,0)]=list_a[0]+list_b[0]+list_c[0]
pop_list=[]
for i in range(0,k):
    Max=max(dict_p.values())
    print(Max)
    for j in dict_p:
        if dict_p[j]==Max:
            now=j
            dict_p.pop(now)
            pop_list.append(now)
            break
    x_t=1
    y_t=1
    z_t=1
    for i in pop_list:
            if (now[0]+1,now[1],now[2])==i:
                x_t=0
            if (now[0],now[1]+1,now[2])==i:
                y_t=0
            if (now[0],now[1],now[2]+1)==i:
                z_t=0
    if now[0]+1<x:
        if x_t==1:
            dict_p[(now[0]+1,now[1],now[2])]=list_a[now[0]+1]+list_b[now[1]]+list_c[now[2]]
    if now[1]+1<y:
        if y_t==1:
            dict_p[(now[0],now[1]+1,now[2])]=list_a[now[0]]+list_b[now[1]+1]+list_c[now[2]]
    if now[2]+1<z:
        if z_t==1:
            dict_p[(now[0],now[1],now[2]+1)]=list_a[now[0]]+list_b[now[1]]+list_c[now[2]+1]

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k=map(int,input().split())
list_a=list(map(int,input().split()))
list_b=list(map(int,input().split()))
list_c=list(map(int,input().split()))
list_a.sort(reverse=True)
list_b.sort(reverse=True)
list_c.sort(reverse=True)
dict_p={}
dict_p[(0,0,0)]=list_a[0]+list_b[0]+list_c[0]
pop_list=[]
for i in range(0,k):
    Max=max(dict_p.values())
    print(Max)
    for j in dict_p:
        if dict_p[j]==Max:
            now=j
            dict_p.pop(now)
            pop_list.append(now)
            break
    if now[0]+1<x:
        x_t=1
        for i in pop_list:
            if (now[0]+1,now[1],now[2])==i:
                x_t=0
        if x_t==1:
            dict_p[(now[0]+1,now[1],now[2])]=list_a[now[0]+1]+list_b[now[1]]+list_c[now[2]]
    if now[1]+1<y:
        y_t=1
        for i in pop_list:
            if (now[0],now[1]+1,now[2])==i:
                y_t=0
        if y_t==1:
            dict_p[(now[0],now[1]+1,now[2])]=list_a[now[0]]+list_b[now[1]+1]+list_c[now[2]]
    if now[2]+1<z:
        z_t=1
        for i in pop_list:
            if (now[0],now[1],now[2]+1)==i:
                z_t=0
        if z_t==1:
            dict_p[(now[0],now[1],now[2]+1)]=list_a[now[0]]+list_b[now[1]]+list_c[now[2]+1]

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc123
# -*- coding: utf-8 -*-

import heapq

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

a = heapq.nlargest(k, a)
b = heapq.nlargest(k, b)
c = heapq.nlargest(k, c)

oisisa = []
for l in a:
    for m in b:
        for n in c:
            oisisa.append(l+m+n)

oisisa.sort(reverse = True)
for v in oisisa[0:k]:
    print(v)

Submission status: Time Limit Exceeded

Solution code:
x,y,z,K = map(int,input().split())
abc = [sorted(list(map(int,input().split())), reverse=True) for i in range(3)]

ans=[]
ab=[]

for i in range(x):
    for j in range(y):
        if (i+1)*(j+1) <= K:
            ab.append(abc[0][i]+abc[1][j])

ab.sort(reverse=True)

for i in range(len(ab)):
    for j in range(z):
        if (i+1)*(j+1) <= K:
            ans.append(ab[i]+abc[2][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())
abc = [sorted(list(map(int,input().split())), reverse=True) for i in range(3)]

ans=[0]*K

for i in range(x):
    for j in range(y):
        for l in range(z):
            if i*j*l < K:
                if min(ans) < abc[0][i]+abc[1][j]+abc[2][l]:
                    ans[ans.index(min(ans))] = abc[0][i]+abc[1][j]+abc[2][l]
            
ans.sort(reverse=True)

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