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

cnt = 1
a = A[0]
b = B[0]
c = C[0]

re = []
for i in range(len(A)):
    for j in range(len(B)):
        for k in range(len(C)):
            re.append(A[i] + B[j] + C[k])
            
re = sorted(re, reverse=True)

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

Submission status: Time Limit Exceeded

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

D = []
for a, b, c in itertools.product(A, B, C):
    d = a + b + c
    D.append(d)
    
D.sort(reverse = True)
for d in D[:K]:
    print(d)

Submission status: Time Limit Exceeded

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

d = []
for i_a in range(len(a)):
  for i_b in range(len(b)):
    for i_c in range(len(c)):
      d.append(a[i_a] + b[i_b] + c[i_c])

for j in range(len(d)):
  if j < num[3]:
    n = max(d)
    print(n)
    d.remove(n)

Submission status: Time Limit Exceeded

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

def f(p,q):
    return [i+j for j in q for i in p]

if x+y<y+z:
    for i in sorted(f(c,f(a,b)))[::-1][:k]:
        print(i)
elif x+z<y+z:
    for i in sorted(f(b,f(a,c)))[::-1][:k]:
        print(i)
else:
    for i in sorted(f(a,f(b,c)))[::-1][:k]:
        print(i)

Submission status: Time Limit Exceeded

Solution code:
N=list(map(int,(input().split(" "))))
teast=[]
K = N[3]
total=[]
c=0
for i in range(3):
    teast.append(list(map(int,input().split(" "))))


for i in teast[0]:
    for j in teast[1]:
        for k in teast[2]:
            total.append(i+j+k)
total_s=sorted(total,reverse=True)
for i in total_s:
    print(int(i))
    c+=1

    if c ==K:
        break

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K=map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
cake=[]

for i in a:
    for j in b:
        for k in c:
            cake.append(i+j+k)

cake.sort(reverse=True)
for i in range(K):
    print(cake[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)
useA = [a.pop(0)]
useB = [b.pop(0)]
useC = [c.pop(0)]
if len(a) == 0:
  a.append(0)
if len(b) == 0:
  b.append(0)
if len(c) == 0:
  c.append(0)
while True:
  if a[0] == b[0] == c[0] == 0:
    break
  if a[0] >= b[0] and a[0] >= c[0]:
    useA.append(a.pop(0))
    if len(a) == 0:
      a.append(0)
  elif b[0] >= a[0] and b[0] >= c[0]:
    useB.append(b.pop(0))
    if len(b) == 0:
      b.append(0)
  elif c[0] >= b[0] and c[0] >= a[0]:
    useC.append(c.pop(0))
    if len(c) == 0:
      c.append(0)
#  print( len(useA) * len(useB) * len(useC))
  if 1000*k**2 <= len(useA) * len(useB) * len(useC):
    break
ans = []
#print(useA, useB, useC)
for i in range(len(useA)):
  for j in range(len(useB)):
    for m in range(len(useC)):
      ans.append(useA[i] + useB[j] + useC[m])
ans.sort(reverse = True)
for i in range(k):
  print(ans[i])

Submission status: Time Limit Exceeded

Solution code:

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

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

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

ABC = [ab+c for ab in AB for c in C]

ABC.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
import numpy as np

X,Y,Z,K = map(int,input().split())
Alist = list(map(int,input().split()))
Blist = list(map(int,input().split()))
Clist = list(map(int,input().split()))
Alllist = [a+b+c for a in Alist for b in Blist for c in Clist]
Alllist.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush, heappop

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

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


def inv(v):
    return maxv - v


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

Submission status: Time Limit Exceeded

Solution code:
import bisect

x,y,z,k = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
cc = list(map(int, input().split()))

score = []

for a in aa:
    for b in bb:
        for c in cc:
            bisect.insort_right(score, a+b+c)
for s in score[::-1][:min(k,x*y*z)]:
    print(s)

Submission status: Time Limit Exceeded

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

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

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

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

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

ansList.sort()
ansList.reverse()

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

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K=map(int,input().split())
Ax=sorted(list(map(int,input().split())), reverse=True)
By=sorted(list(map(int,input().split())), reverse=True)
Cz=sorted(list(map(int,input().split())), reverse=True)
n = []
for a in range(min(K, len(Ax))):
    for b in range(min(K, len(By))):
        for c in range(min(K, len(Cz))):
            n.append(Ax[a] + By[b] + Cz[c])
n.sort(reverse=True)
for k in range(K):
    print(n[k])

Submission status: Time Limit Exceeded

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

p = [functools.reduce(operator.add, x) for x in itertools.product(A, B, C)]
p.sort(reverse=True)
for x in p[:min(3000, K)]:
    print(x)

Submission status: Time Limit Exceeded

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

import math

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

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

cnum = []

takadaka = math.ceil(k ** 0.7)

for i in range(min(takadaka,x)):
    for j in range(min(takadaka,y)):
        for l in range(min(takadaka,z)):
            cnum.append(a[i] + b[j] + c[l])

cnum.sort()
cnum.reverse()

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


x = []
for a in A:
    for b in B:
        for c in C:
            x.append(a + b + c)
x.sort(reverse=True)

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

Submission status: Time Limit Exceeded

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

# x=[int(input()) for i in range(nx)]
# y=[int(input()) for i in range(ny)]
# z=[int(input()) for i in range(nz)]

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

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

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

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


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

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

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

x=merge_sort(x)[::-1][:k]
y=merge_sort(y)[::-1][:k]
z=merge_sort(z)[::-1][:k]

idx=[]

for X in x:
    for Y in y:
        for Z in z:
            idx.append(X+Y+Z)

idx=merge_sort(idx)[::-1][:k]

for i in idx:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K=map(int,input().split())
As=sorted(map(int,input().split()),reverse=True)
Bs=sorted(map(int,input().split()),reverse=True)
Cs=sorted(map(int,input().split()),reverse=True)
s=[]
for a in As:
    for b in Bs:
        for c in Cs:
            s.append(a+b+c)
s=sorted(s,reverse=True)
for k in range(K):
    print(s[k])

Submission status: Time Limit Exceeded

Solution code:
import itertools
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
all_list = [a, b, c]
#print(all_list)
itr_list = []
for i in list(itertools.product(a, b, c)):
  #print(sum(i))
  itr_list.append(sum(i))
#print(sorted(itr_list))
for i in range(k):
  print(sorted(itr_list)[len(itr_list)-i-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()))

answer = []

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

answer.sort()
answer.reverse()

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

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K = map(int, input().split())
import itertools
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
U = sorted([sum(i) for i in list(itertools.product(A,B,C))])[::-1][:K]
for i in U:
  print(i)

Submission status: Time Limit Exceeded

Solution code:
X, Y, Z, K = list(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)

class Value():
  def __init__(self, A_list, B_list, C_list, a_idx, b_idx, c_idx):
    self.A = A_list[a_idx]
    self.B = B_list[b_idx]
    self.C = C_list[c_idx]
    self.a_idx = a_idx
    self.b_idx = b_idx
    self.c_idx = c_idx
    self.value = self.A + self.B + self.C
  def __eq__(self, another):
    return self.a_idx == another.a_idx and self.b_idx == another.b_idx and self.c_idx == another.c_idx  
    
que = []
que.append(Value(A_list, B_list, C_list, 0, 0, 0))
current_value = 10000000000 * 3
for _ in range(K):
  v = que.pop(0)
  print(v.value)
  if v.a_idx < X -1:
    new_v = Value(A_list, B_list, C_list, v.a_idx + 1, v.b_idx, v.c_idx)
    if not new_v in que:
      que.append(new_v)
  if v.b_idx < Y -1:
    new_v = Value(A_list, B_list, C_list, v.a_idx, v.b_idx + 1, v.c_idx)
    if not new_v in que:
      que.append(new_v)
  if v.c_idx < Z -1:
    new_v = Value(A_list, B_list, C_list, v.a_idx, v.b_idx, v.c_idx + 1)
    if not new_v in que:
      que.append(new_v)
  que.sort(key=lambda x: x.value, reverse=True)

Submission status: Time Limit Exceeded

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

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

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

bc = []

for b in B:
    for c in C:
        bc.append(b+c)

bc.sort(reverse=True)
t = min(len(bc), 3333)
bc = bc[:t]
cnt = 0
cand = []

for a in A:
    cnt = 0
    for i in bc:
        cnt += 1
        cand += [a + i]
        if cnt == 3000:
            break

cand.sort(reverse=True)
cnt = 0
for i in cand:
    print(i)
    cnt += 1
    if cnt == k:
        break

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)

cnt = 1
a = A[0]
b = B[0]
c = C[0]

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

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

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

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

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

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

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(200,x)):
    for j in range(min(200,y)):
        for t in range(min(200,z)):
            l.append(a[i] + b[j] + c[t])
l = sorted(l,reverse=True)
for i in range(k):
    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()))

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

result = []
for i in range(len(Al)):
    for j in range(len(Bl)):
        for k in range(len(Cl)):
            result.append(Al[i]+Bl[j]+Cl[k])

result.sort(reverse=True)

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

Submission status: Time Limit Exceeded

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

import math

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

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

cnum = []

takadaka = math.ceil(k ** 0.67)

for i in range(min(takadaka,x)):
    for j in range(min(takadaka,y)):
        for l in range(min(takadaka,z)):
            cnum.append(a[i] + b[j] + c[l])

cnum.sort()
cnum.reverse()

for i in range(k):
    print(cnum[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 = [int(x) for x in str(input()).split(' ')]
B = [int(x) for x in str(input()).split(' ')]
C = [int(x) for x in str(input()).split(' ')]

out = sorted([sum(x) for x in itertools.product(A, B, C)], reverse=True)

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

Submission status: Time Limit Exceeded

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

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

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

bc = []

for b in B:
    for c in C:
        bc.append(b+c)

bc.sort(reverse=True)
cnt = 0
cand = []

for a in A:
    cnt = 0
    for i in bc:
        cnt += 1
        cand += [a + i]
        if cnt == 3000:
            break

cand.sort(reverse=True)
cnt = 0
for i in cand:
    print(i)
    cnt += 1
    if cnt == k:
        break

Submission status: Time Limit Exceeded

Solution code:
x = 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()
a.reverse()

b.sort()
b.reverse()

c.sort()
c.reverse()

l = []

for i in range(x[0]):
    for j in range(x[1]):
        for k in range(x[2]):
            l.append(a[i]+b[j]+c[k])

l.sort()
l.reverse()

for i in range(x[3]):
    print(l[i])

Submission status: Time Limit Exceeded

Solution code:
arr = []
arr.append(input())
arr.append(input())
arr.append(input())
arr.append(input())


xyzk = arr[0].split()
arrA = arr[1].split()
arrB = arr[2].split()
arrC = arr[3].split()

xyzk = [int(i) for i in xyzk]
arrA = [int(i) for i in arrA]
arrB = [int(i) for i in arrB]
arrC = [int(i) for i in arrC]
arrA.sort(reverse=True)
arrB.sort(reverse=True)
arrC.sort(reverse=True)

result = []
for i in range(len(arrA)):
    for j in range(len(arrB)):
        for k in range(len(arrC)):
            result.append(arrA[i]+arrB[j]+arrC[k])

result.sort(reverse=True)


for x in result[0:xyzk[3]]:
    print(x)

Submission status: Time Limit Exceeded

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random
import bisect #bisect_left　これで二部探索の大小検索が行える

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


A.sort()
A.reverse()
B.sort()
B.reverse()
C.sort()
C.reverse()
ak = A[0:k]
bk = B[0:k]
ck = C[0:k]

anss = []
for i in ak:
    for j in bk:
        for l in ck:
            anss.append(i+j+l)

anss.sort()
anss.reverse()

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

Submission status: Time Limit Exceeded

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


ans=[]
for c in range(Z):
    for b in range(Y):
        for a in range(X):
            kari=A[a]+B[b]+C[c]
            ans.append(kari)
            
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()
b.sort()
c.sort()
d = []
for i in range(max(0,len(a)-200), len(a)):
    for j in range(max(0,len(b)-200), len(b)):
        for l in range(max(0,len(c)-200), len(c)):
            d.append(a[i]+b[j]+c[l])
d.sort()
for i in range(1,k+1):
    print(d[-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(500,x)):
    for j in range(min(500,y)):
        for t in range(min(500,z)):
            l.append(a[i] + b[j] + c[t])
l = sorted(l,reverse=True)
for i in range(k):
    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)

def m():
    a = A[:1000]
    b = B[:1000]
    c = C[:1000]
    ans = []
    l = len(a)
    for i in range(l):
        for j in range(l):
            for p in range(l):
                ans.append(a[i]+b[j]+c[p])
    ans.sort(reverse=True)
    for i in range(k):
        print(ans[i])

m()

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush, heappop

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

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


def inv(v):
    return maxv - v


cnt = 0
visited = [[[False] * Z for _ in range(Y)] for _ in range(X)]
heappush(h, (0, 0, 0, 0))
while cnt < K:
    invv, i, j, k = heappop(h)
    if visited[i][j][k]:
        continue
    visited[i][j][k] = True
    cnt += 1
    print(inv(invv))
    if i + 1 < X:
        heappush(h, (inv(A[i + 1] + B[j] + C[k]), i + 1, j, k))
    if j + 1 < Y:
        heappush(h, (inv(A[i] + B[j + 1] + C[k]), i, j + 1, k))
    if k + 1 < Z:
        heappush(h, (inv(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())
candy = [[],[],[]]
for i in range(3):
    temp = list(map(int, input().split()))
    candy[i] = temp

for i in range(3):
    candy[i] = sorted(candy[i], reverse=True)

output = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            output.append(candy[0][i] + candy[1][j] + candy[2][k])
output = sorted(output, reverse=True)
for i in range(K):
    print(output[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()
b.sort()
c.sort()
d = []
for i in range(max(0,len(a)-300), len(a)):
    for j in range(max(0,len(b)-300), len(b)):
        for l in range(max(0,len(c)-300), len(c)):
            d.append(a[i]+b[j]+c[l])
d.sort()
for i in range(1,k+1):
    print(d[-i])

Submission status: Time Limit Exceeded

Solution code:
import itertools as itr

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

INF_DUMMY = 30000000000
Xs = list(map(int,input().split(" ")))
Ys = list(map(int,input().split(" ")))
Zs = list(map(int,input().split(" ")))
"""
Xs.sort()
Ys.sort()
Zs.sort()

Xs.reverse()
Ys.reverse()
Zs.reverse()


Xs.append(-INF_DUMMY)
Ys.append(-INF_DUMMY)
Zs.append(-INF_DUMMY)

ind_x,ind_y,ind_z = 0,0,0
for _ in range(K):
	print(Xs[ind_x]+Ys[ind_y]+Zs[ind_z])
	
	diff_x = Xs[ind_x] - Xs[ind_x+1]
	diff_y = Ys[ind_y] - Ys[ind_y+1]
	diff_z = Zs[ind_z] - Zs[ind_z+1]
	
	print([diff_x,diff_y,diff_z])
	diff_min = min([diff_x,diff_y,diff_z])
	if diff_x == diff_min:
		ind_x += 1
	elif diff_y == diff_min:
		ind_y += 1
	else:
		ind_z += 1
"""

sum_vals = [sum(ls) for ls in itr.product(Xs,Ys,Zs)]

sum_vals.sort()
sum_vals.reverse()


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

import itertools

data=list(itertools.product(a,b,c))

data_=[sum(i) for i in data]
data_.sort(reverse=True)


for j in range(k):
    print(data_[j])

Submission status: Time Limit Exceeded

Solution code:
import heapq

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

def diff(l):
    m = max(l)
    return sorted(m - v for v in l)[1:]

s = sum(map(max, [a, b, c]))
sa, sb, sc = map(diff, [a, b, c])
da, db, dc = [0], [0], [0]
q = [0]
while k > 0:
    while True:
        if len(sa) > 0 and (len(q) == 0 or q[0] >= sa[0]):
            for v in [sa[0] + bb + cc for bb in db for cc in dc]:
                heapq.heappush(q, v)
            da.append(sa[0])
            sa = sa[1:]
        elif len(sb) > 0 and (len(q) == 0 or q[0] >= sb[0]):
            for v in [sb[0] + aa + cc for aa in da for cc in dc]:
                heapq.heappush(q, v)
            db.append(sb[0])
            sb = sb[1:]
        elif len(sc) > 0 and (len(q) == 0 or q[0] >= sc[0]):
            for v in [sc[0] + aa + bb for aa in da for bb in db]:
                heapq.heappush(q, v)
            dc.append(sc[0])
            sc = sc[1:]
        else:
            break
    v = heapq.heappop(q)
    print s - v
    k -= 1

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k=map(int,input().split())
lists_1=list(map(int,input().split()))
lists_2=list(map(int,input().split()))
lists_3=list(map(int,input().split()))
lists=[]
for i in range (x):
  a=lists_1[i]
  for j in range (y):
    b=a+lists_2[j]
    for l in range (z):
      c=b+lists_3[l]
      lists.append(c)
lists.sort()
for t in range (k):
  print(lists[x*y*z-t-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)

x = []
for a in A:
    for b in B:
        for c in C:
            x.append(a + b + c)
x.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

X, Y, Z, K = map(int, input().split())
Ax=list(map(int, input().split()))
By=list(map(int, input().split()))
Cz=list(map(int, input().split()))

comb=itertools.product(Ax,By,Cz)

L=[]

for c in comb:
  L.append(c[0]+c[1]+c[2])
  
L=sorted(L, reverse=True)
for l in L[:K]:
  print(l)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys
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()))

comb = itertools.product(A, B, C)
arr = [sum(t) for t in comb]
arr.sort()
arr.reverse()
for i, v in enumerate(arr, 1):
  print(v)
  if i == K:
    sys.exit()

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 = []
AC = []
BC = []
for a in A:
    for b in B:
        AB.append(a+b)
    for c in C:
        AC.append(a+c)
for b in B:
    for c in C:
        BC.append(b+c)
AB.sort(reverse=True)
AC.sort(reverse=True)
BC.sort(reverse=True)

arr = []
for a in A:
    for bc in BC[:K]:
        arr.append(a+bc)
for b in B:
    for ac in AC[:K]:
        arr.append(b+ac)
for c in C:
    for ab in AB[:K]:
        arr.append(c+ab)

arr.sort(reverse=True)
ans = arr[:K*3:3]
print(*ans, sep='\n')

Submission status: Time Limit Exceeded

Solution code:
x,y,z,n=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)
ge=[]
for i in range(0,min(x,300)):
  for j in range(0,min(y,300)):
    for k in range(0,min(z,300)):
      ge.append(a[i]+b[j]+c[k])

ge.sort(reverse=True)
for i in range(n):
  print(ge[i])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import os
import itertools
from math import *

x,y,z,k = [int(i) for i in input().split(' ')]
#print(x,y,z,k)
    
xi = [int(i) for i in input().split()]
yi = [int(i) for i in input().split()]
zi = [int(i) for i in input().split()]

xi.sort(reverse=True)
yi.sort(reverse=True)
zi.sort(reverse=True)

xi = xi[:k]
yi = yi[:k]
zi = zi[:k]

nlist = []
for n in list(itertools.product(xi, yi, zi)):
    nlist.append(n[0] + n[1] + n[2])

nlist.sort(reverse=True)

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