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

x_list = list(map(int,input().split()))
x_list.sort(reverse=True)
  
y_list = list(map(int,input().split()))
y_list.sort(reverse=True)

z_list = list(map(int,input().split()))
z_list.sort(reverse=True)

vals = dict()
max_list = [x_list[0] + y_list[0] + z_list[0]]
max_cand = [(0, 0, 0)]
cand_list = []
vals[(0, 0, 0)] = x_list[0] + y_list[0] + z_list[0]
K -= 1

print(vals[(0, 0, 0)])

for i in range(K):
  max_key = max(vals, key=vals.get)  
  del vals[max_key]
  max_cand.remove(max_key)
  
  new_cand = [(min(max_key[0] + 1, X -1), max_key[1], max_key[2]), 
              (max_key[0], min(max_key[1] + 1, Y -1),  max_key[2]),
              (max_key[0], max_key[1], min(max_key[2] + 1, Z-1))]

  new_cand = [x for x in new_cand if x not in cand_list]
  max_cand.extend(new_cand)
  
  for cand in new_cand:
    vals[cand] = x_list[cand[0]] + y_list[cand[1]] + z_list[cand[2]]
    
  cand_list.append(max(vals, key=vals.get))
  print(max(vals.values()))

Submission status: Time Limit Exceeded

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

aabb = [a + b for a in aaa for b in bbb]
aabb.sort(reverse=True)
aabb = aabb[:k]

aabbcc = [ab + c for ab in aabb for c in ccc]
aabbcc.sort(reverse=True)
aabbcc = aabbcc[:k]

print('\n'.join(map(str, aabbcc)))

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 s in a:
    for t in b:
        l.append(s+t)
l.sort()
l.reverse()
n=[]
for s in l[:k+1]:
    for t in c:
        n.append(s+t)
n.sort()
n.reverse()
for i in range(k):
    print(n[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)
A_B=[]
SUM=[]
for i in range(min(K,X)):
  for j in range(min(K,Y)):
    A_B.append(A[i]+B[j])
A_B.sort(reverse=True)
for i in range(min(K,X*Y)):
  for j in range(min(K,Z)):
    SUM.append(A_B[i]+C[j])
SUM.sort(reverse=True)
for i in range(K):
  print(SUM[i])

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K = map(int,input().split())
l_a = list(map(int,input().split()))
l_b = list(map(int,input().split()))
l_c = list(map(int,input().split()))
l_a.sort(reverse = True)  
l_b.sort(reverse = True)  
l_c.sort(reverse = True)
l_d = [a + b for a in l_a for b in l_b]
l_d.sort(reverse = True)
l_d[:3000]
l_e = [ab + c for ab in l_d for c in l_c]
l_e.sort(reverse = True)

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
x, y, z, k = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
B = list(map(int, input().split()))
B.sort(reverse=True)
C = list(map(int, input().split()))
C.sort(reverse=True)
D = []
E = []
for b in B:
    for c in C:
        D.append(b+c)
D.sort(reverse=True)
for a in A:
    for d in D[:k]:
       E.append(a+d)
E.sort(reverse=True)
for e in E[:k]:
    print(e)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
input = sys.stdin.readline

# bisect_left(lists, 3)
# bisect_right(lists, 3)

def main():
	X, Y, Z, K = map(int, input().split(" "))
	As = []
	Bs = []
	Cs = []
	As = input().split()
	As = [int(s) for s in As]
	Bs = input().split()
	Bs = [int(s) for s in Bs]
	Cs = input().split()
	Cs = [int(s) for s in Cs]

	As.sort(reverse=True)
	Bs.sort(reverse=True)
	Cs.sort(reverse=True)

	As = As[:K]
	Bs = Bs[:K]
	Cs = Cs[:K]

	ans = []
	for i, val in enumerate(As):
		for j, vol in enumerate(Bs):
			for k, ogi in enumerate(Cs):
				ans.append(val+vol+ogi)

	ans.sort(reverse=True)
	for i in range(K):
		print(ans[i])
	
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

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

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

C.sort(reverse=True)
tmp = []
ans = []

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

for i in range(min(X*Y, K)):
	for j in range(Z):
		ans.append(tmp[i]+C[j])

ans.sort(reverse=True)

for i in range(min(K, X*Y*Z)):
	print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
k = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
z = [int(i) for i in input().split()]

x.sort()
y.sort()
z.sort()

e = []

for i in x:
  for j in y:
    e.append(i+j)

e.sort()

f = []

for i in e:
  for j in z:
    f.append(i+j)

f.sort()
f.reverse()

for i in range(k[3]):
  print(f[i])

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 sorted([i+j for j in q for i in p])[::-1][:k]
 
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:
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 range(X):
    for j in range(Y):
        AB.append(A[i]+B[j])
        
AB.sort(reverse=True)
tmp=AB[0:min(3001,len(AB))]

ABC=[]
for i in range(len(tmp)):
    for j in range(Z):
        ABC.append(tmp[i]+C[j])

ABC.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
lis = []
for i in range(x):
    for j in range(y):
        lis.append([a[i] + b[j], a[i], b[j]])
lis.sort(reverse=True)
lis2 = []
m = min(k, len(lis))
for i in range(m):
    for j in range(z):
        lis2.append(lis[i][0] + c[j])
lis2.sort(reverse=True)

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

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

# A,Bでソート
score_ab = []
for a in aa:
    for b in bb:
            bisect.insort_right(score_ab, a+b)
# print(score_ab[::-1])
# A,B合計値の上位K個とCでソート
score = []
for s in score_ab[::-1][:k]:
    for c in cc:
            bisect.insort_right(score, s+c)
for s in score[::-1][:k]:
    print(s)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

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

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



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

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

yz.sort(reverse=True)

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


n=len(yz)
ans=[]

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

ans.sort(reverse=True)


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

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left as bi
x,y,z,k=map(int,input().split())
a=sorted(list(map(int,input().split())))[::-1]
b=sorted(list(map(int,input().split())))[::-1]
c=sorted(list(map(int,input().split())))[::-1]
for i in sorted([j+i for j in c for i in sorted([i+j for i in a for j in b])[::-1][:k]])[::-1][:k]:
    print(i)

Submission status: Time Limit Exceeded

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

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

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

summs_ab = []
summs = []
for a in A:
    for b in B:
        summs_ab.append(a+b)
summs_ab.sort(reverse=True)
summs_ab = summs_ab[0:min(3001, X*Y*Z+1)]

for c in C:
    for sab in summs_ab:
        summs.append(sab+c)
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,b,c=list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split()))
aa=[]
for i in a:
  for j in b:aa.append(i+j)
aa.sort(reverse=1)
aa=aa[:k+1]
s=[]
for i in aa:
  for j in c:s.append(i+j)
s.sort(reverse=1)
for i in range(k):print(s[i])

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
x, y, z, k = map(int, input().split())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))
zs = list(map(int, input().split()))

xy_list = []
for i,xy in enumerate(list(product(xs,ys))):
    xy_list.append(sum(xy))

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

ans_list = []
for i,xyz in enumerate(list(product(xy_list,zs))):
    ans_list.append(sum(xyz))
    
ans_list.sort(reverse=True)
ans_list = ans_list[:k]

for ans in ans_list:
    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()))

a_plus_b = []
for i in a:
    for j in b:
        a_plus_b.append(i + j)
a_plus_b.sort(reverse=True)

a_plus_b_plus_c = []
for i in a_plus_b[:k]:
    for j in c:
        a_plus_b_plus_c.append(i + j)
a_plus_b_plus_c.sort(reverse=True)

for i in range(k):
    print(a_plus_b_plus_c[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 = [0 for _ in range(x * y)]
t = 0
for ai in a:
    for bi in b:
        p[t] = ai + bi
        t += 1
p.sort(reverse=True)
q = [0 for _ in range(k * z)]
t = 0
for pi in p[:k]:
    for ci in c:
        q[t] = pi + ci
        t += 1
q.sort(reverse=True)
for qi in q[:k]:
    print(qi)

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import product
X, Y, Z, K = map(int, input().split(" "))
a= map(int, input().split(" "))
b = map(int, input().split(" "))
c = map(int, input().split(" "))

d = list(product(a, b, c))

e = [x+y+z for x, y, z in d]
f = sorted(e)
for i in f[::-1][:K]:
  print(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()]

ab = []
for a_ in a:
    for b_ in b:
        ab.append(a_+b_)

res = []
for ab_ in sorted(ab, reverse=True)[:k]:
    for c_ in sorted(c, reverse=True)[:k]:
        res.append(ab_+c_)

for x in sorted(res, reverse=True)[: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()))
e = []
for i in a:
    for j in b:
        e.append(i + j)
e = sorted(e, reverse=True)[:k]
ans = []
for i in e:
    for j in c:
        ans.append(i + j)
ans = sorted(ans, reverse=True)[:k]
for i in ans:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
inf = float("INF")
x,y,z,k=map(int,input().split())
dp=[0]*3000
l =[]
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
for i in a:
  for j in b:
    l.append(i+j)
l.sort()
l = l[::-1]
t =[]
for i in l[:k]:
  for j in c:
    t.append(i+j)
t.sort()
t = t[::-1]
for i ,n in enumerate(t):
  print(n)
  if i == k-1: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(' ')))
taste = []
tastexy = []
for i in set(range(x - k if x - k > 0 else 0, x)):
    for j in set(range(y - k if y - k > 0 else 0, y)):
        tastexy.append(a[i] + b[j])
tastexy.sort()
tindex = len(tastexy)-k if len(tastexy)-k > 0 else 0
tastez = tastexy[tindex:]
for t in tastez:
    for l in set(range(z - k if z - k > 0 else 0, z)):
        taste.append(t + c[l])
taste.sort()
for i in range(k):
    print(taste[-1-i])

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k=map(int,input().split())
*a,=map(int,input().split())
*b,=map(int,input().split())
*c,=map(int,input().split())
 
def merge_sort(array):
    if len(array) <= 1:
        return array
    cnt=len(array)//2
    left=array[:cnt]
    right=array[cnt:]
    left = merge_sort(left)
    right = merge_sort(right)
    return merge(left, right)
 
 
def merge(left, right):
    array = [0]*3000
    l,r,ind=0,0,0
    while l < len(left) and r < len(right):
        if left[l] >= right[r]:
            array[ind]=left[l]
            l+=1
            ind+=1
        else:
            array[ind]=right[r]
            r+=1
            ind+=1
        if ind>=3000:
            return array
    if l < len(left):
        return array[:ind]+left[l:]
    if r < len(right):
        return array[:ind]+right[r:]

a=merge_sort(a)
b=merge_sort(b)
c=merge_sort(c)
l,r=[],[]
for i in a:
  for j in b:
    l.append(i+j)
l=merge_sort(l)
for i in l:
  for j in c:
    r.append(i+j)
r=merge_sort(r)
for i in range(k):
    print(r[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()))

d = []

for e1 in a:
  for e2 in b:
    d.append(e1+e2)

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

e = []

for e1 in d:
  for e2 in c:
    e.append(e1+e2)

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 = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

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

ab = []
for ai in a:
    for bi in b:
        ab.append(ai + bi)
ab.sort(reverse=True)
if k < len(ab):
    ab = ab[:k]

ans = []
for abi in ab:
    for ci in c:
        ans.append(abi + ci)
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k = (int(x) for x in input().split())
a = list(reversed(sorted([int(x) for x in input().split()])))
b = list(reversed(sorted([int(x) for x in input().split()])))
c = list(reversed(sorted([int(x) for x in input().split()])))
ra = [a[0]-x for x in a]
rb = [b[0]-x for x in b]
rc = [c[0]-x for x in c]
ia = 0
ib = 0
ic = 0
while (ia+1)*(ib+1)*(ic+1) < k:
    na = ra[ia+1] if ia+1<x else 10000000001
    nb = rb[ib+1] if ib+1<y else 10000000001
    nc = rc[ic+1] if ic+1<z else 10000000001
    if na <= nb and na <= nc:
        ia += 1
    if nb <= na and nb <= nc:
        ib += 1
    if nc <= na and nc <= nb:
        ic += 1
cp = ra[ia]+rc[ib]+rc[ic]
ca = len([n for n in ra if n <= cp])
cb = len([n for n in rb if n <= cp])
cc = len([n for n in rc if n <= cp])
nums = []
for va in ra[0:ca]:
    for vb in rb[0:cb]:
        for vc in rc[0:cc]:
            nums.append(va+vb+vc)
nums.sort()
mx = a[0]+b[0]+c[0]
for num in nums[0:k]:
    print(mx-num)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
l=[]
L=[]
for ix in range(x):
  for iy in range(y):
    l.append(a[ix]+b[iy])
l.sort()
l.reverse()
if len(l)>k:
  l=l[0:k]
for iz in range(z):
  for i in range(len(l)):
    L.append(c[iz]+l[i])
L.sort()
L.reverse()
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)
tot = []
for i in range(X):
   for j in range(Y):
      for k in range(Z):
         if(i*j*k > K): break
         else: tot.append(a[i] + b[j] + c[k])
tot.sort()
for i in range(K):
   print(tot[-(i+1)])

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

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

F = []
for i in range(min(X * Y, K)):
    for j in range(Z):
        F.append(E[i] + C[j])
F.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]
    ans = []
    X, Y, Z, K = (int(_) for _ in input().split())
    A = list(int(_) for _ in input().split())

    B = list(int(_) for _ in input().split())

    C = list(int(_) for _ in input().split())
    for a in A:
        for b in B:
            for c in C:
                ans.append(a + b + c)
    ans.sort()
    ans = ans[::-1]
    ans = ans[:K]
    print('\n'.join(map(str,ans)))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

l=[]
for s in a:
    for t in b:
        l.append(s+t)
l.sort()
l.reverse()
m=l[:k]
n=[]
for s in m:
    for t in c:
        n.append(s+t)
n.sort()
n.reverse()
for i in range(k):
    print(n[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 = []
for ai in a:
    for bi in b:
        p.append(ai + bi)
p.sort(reverse=True)
q = []
for pi in p[:k]:
    for ci in c:
        q.append(pi + ci)
q.sort(reverse=True)
for qi in q[:k]:
    print(qi)

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

A = A[::-1]
B = B[::-1]
C = C[::-1]

anslist = []

for i in range(len(A)):
    if i > k:
        break
    for j in range(len(B)):
        if i * j > k:
            break
        for l in range(len(C)):
            if i * j * l > k:
                break
            anslist.append(A[i] + B[j] + C[l])

anslist.sort()

anslist = anslist[::-1]

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

Submission status: Time Limit Exceeded

Solution code:

import itertools

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

    p = itertools.product(A, B)
    data = [i + j for i, j in p]
    data.sort(reverse=True)
    data = data[:min(len(data), K)]

    p = itertools.product(data, C)
    data = [i + j for i, j in p]
    data.sort(reverse=True)
    # data = data[:K]

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

if __name__ == '__main__':
    main()

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

v = []
count = 0


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

v = sorted(v, reverse=True)
c = sorted(c, reverse=True)

vv = []
for i in range(len(v)):
    for j in range(z):
        vv.append(v[i]+c[j])

vv = sorted(vv, reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
x, y, z, n = map(int, input().split())
a = list(map(int, input().split()))
A = sorted(a, reverse=True)
b = list(map(int, input().split()))
B = sorted(b, reverse=True)
c = list(map(int, input().split()))
C = sorted(c, reverse=True)
l = [-1 for _ in range(n)]

for i in range(x):
  flag = 0
  for j in range(y):
    cur = 0
    for k in range(z):
      s = A[i] + B[j] + C[k]
#      print(s)
      while cur < n:
#        print(s, cur, l[cur])
        if s > l[cur]:
#          print("insert", cur, l[cur], s)
          l.insert(cur, s)
          l.pop()
          flag = 1
          break
        cur += 1
  if flag == 0:
    break

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

Submission status: Time Limit Exceeded

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

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

sum = []

for i in range(x):
	for j in range(y):
		for jj in range(z):
			sum.append(a[i]+b[j]+c[jj])
sum.sort()
sum.reverse()

#print(sum)
summ = 0

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

Submission status: Time Limit Exceeded

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

li=[]
dp=[[0 for i in range(1000*1000+1)] for j in range(1000*1000+1)]


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

w=0
for l in range(k):
    maxtemp=0
    for i in range(len(li)):

        
        for j2 in range(z):
            if dp[i][j2]==0:
                con=li[i]+c[j2]
                
                if con>maxtemp:
                    x1=i
                    y1=j2
                    maxtemp=con
                break
    

    dp[x1][y1]=l+1
    
    print(maxtemp)

Submission status: Time Limit Exceeded

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

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

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

F = []
for i in range(min(X * Y, K)):
    for j in range(Z):
        F.append(E[i] + C[j])
F.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K=map(int,input().split())
A=[int(x) for x in input().split()]
A.sort(reverse=True)
B=[int(x) for x in input().split()]
B.sort(reverse=True)
C=[int(x) for x in input().split()]
C.sort(reverse=True)
D=[a+b for a in A for b in B]
D.sort(reverse=True)
D=D[:K]
E=[ab+c for ab in D for c in C]
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=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=sorted(AB,reverse=True)[:k]
ABC=[]
for ab in AB:
    for c in C:
        ABC.append(ab+c)
ABC.sort(reverse=True)
for abc in ABC[:k]:
    print(abc)

Submission status: Time Limit Exceeded

Solution code:
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())]
select = k

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

ab.sort()
ab.reverse()
if len(ab) > select:
    ab_sel = ab[0:select]
else:
    ab_sel = ab

anss = []
for i in ab_sel:
    for j in C:
        anss.append(i+j)

anss.sort()
anss.reverse()

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

Submission status: Time Limit Exceeded

Solution code:
from heapq import *
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, n = map(int, input().split())
a = list(map(int, input().split()))
A = sorted(a, reverse=True)
b = list(map(int, input().split()))
B = sorted(b, reverse=True)
c = list(map(int, input().split()))
C = sorted(c, reverse=True)
l = [-1 for _ in range(n)]

for i in range(x):
  for j in range(y):
    cur = 0
    for k in range(z):
      s = A[i] + B[j] + C[k]
#      print(s)
      while cur < n:
#        print(s, cur, l[cur])
        if s > l[cur]:
#          print("insert", cur, l[cur], s)
          l.insert(cur, s)
          break
        cur += 1
#      print(l)

for i in range(n):
  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)

kouho = set()
done = set()


def f(t):
    x, y, z = t
    return A[x] + B[y] + C[z]


def main():
    kouho.add((0, 0, 0))

    for k in range(K):
        temp = 0
        for d in (kouho - done):
            if f(d) > temp:
                todel = d
                temp = f(d)

        x, y, z = todel
        toadd = [(x, y, z+1), (x, y+1, z), (x+1, y, z)]
        for ta in toadd:
            if ta[0] == X:
                continue
            if ta[1] == Y:
                continue
            if ta[2] == Z:
                continue
            kouho.add(ta)

        done.add(todel)
        print(temp)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
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)
D = []
E = []
for b in B:
    for c in C:
        D.append(b+c)
D.sort(reverse=True)
n = 0
for a in A:
    for d in D[:k]:
       E.append(a+d)
E.sort(reverse=True)
for e in E[:k]:
    print(e)

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int, input().split())
ABC = [list(map(int, input().split())) + [-10**10] for _ in range(3)]
for i in range(3):
    ABC[i].sort(reverse = True)
yum = []
for i in range(x):
    for j in range(y):
        for l in range(z):
            if i + j + l > k:
                continue
            yum.append(ABC[0][i]+ABC[1][j]+ABC[2][l])
for i in range(k):
    ans = max(yum)
    print(ans)
    yum.remove(ans)

Submission status: Time Limit Exceeded

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

tmp =input().split(' ')
lx =[int(x) for x in tmp]
lx.sort
lx =lx[::-1]
tmp =input().split(' ')
ly =[int(y) for y in tmp]
ly.sort
ly =ly[::-1]
tmp =input().split(' ')
lz =[int(z) for z in tmp]
lz.sort
lz =lz[::-1]
total=[]
for x in lx:
    for y in ly:
        for z in lz:
            s = int(x)+int(y)+int(z)
            total.append(s)
total.sort()
total=total[::-1]

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