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:
numbers = input().split()
x = input().split()
y = input().split()
z = input().split()

k = int(numbers[3])

x.sort(reverse=True)
if len(x) > k:
    del x[k::]
y.sort(reverse=True)
if len(y) > k:
    del y[k::]
z.sort(reverse=True)
if len(z) > k:
    del z[k::]

answer = []

for i in x:
    for j in y:
        for k in z:
            price = int(i)+int(j)+int(k)
            answer.append(price)

answer.sort(reverse=True)
del answer[int(numbers[3])::]

for l in answer:
    print(l)

Submission status: Time Limit Exceeded

Solution code:
numbers = input().split()
x = input().split()
y = input().split()
z = input().split()


x.sort(reverse=True)
y.sort(reverse=True)
z.sort(reverse=True)

answer = []

for i in x:
    for j in y:
        for k in z:
            price = int(i)+int(j)+int(k)
            answer.append(price)

answer.sort(reverse=True)
del answer[int(numbers[3])::]

for l in answer:
    print(l)

Submission status: Time Limit Exceeded

Solution code:
r=range;x,y,z,k=map(int,input().split())
a,b,c=eval("list(map(int,input().split())), "*3)
ab=sorted([a[i]+b[j]for i in r(x)for j in r(y)],reverse=True)
abc=sorted([ab[i]+c[j]for i in r(min(3000,x*y))for j in r(z)],reverse=True)
print(*[abc[i]for i in r(k)])

Submission status: Time Limit Exceeded

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools as it

X, Y, Z, K = [int(n) for n in input().strip().split(' ')]
A = sorted([int(s) for s in input().strip().split(' ')], reverse=True)
B = sorted([int(s) for s in input().strip().split(' ')], reverse=True)
C = sorted([int(s) for s in input().strip().split(' ')], reverse=True)

AB_best = sorted([sum(e) for e in it.product(A, B)], reverse=True)[:K]
best = sorted([sum(e) for e in it.product(AB_best, C)], reverse=True)[:K]
for s in best:
    print(s)

Submission status: Time Limit Exceeded

Solution code:
K = [int(n) for n in input().rstrip().split()][3]

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

List = []

for n in A:
    for m in B:
        List.append(n+m)

List2 =[]

for k in sorted(List,reverse=True)[:K]:
	for i in C:

		List2.append(k + i)
        
for i in sorted(List2,reverse=True)[:K]:
    print(i)

Submission status: Time Limit Exceeded

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

X=[]
Y=[]
Z=[]

a=map(int,input().split())
X=list(a)

a=map(int,input().split())
Y=list(a)

a=map(int,input().split())
Z=list(a)

S=[]
for i in range(0,z):
    for j in range(0,y):
        for n in range(0,x):
            S.append(X[n]+Y[j]+Z[i])

s=x*y*z
for i in range(0,s):
    for j in range(0,s):
        if S[j]<S[i]:
            m=S[i]
            S[i]=S[j]
            S[j]=m

for i in range(0,k):
    print(S[i])

Submission status: Time Limit Exceeded

Solution code:
def solve(p,q):
  return sorted(i+j for i in p for j in q)[-k:]
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()))
for i in solve(solve(a,b),c)[::-1]:
  print(i)

Submission status: Time Limit Exceeded

Solution code:
[XYZK,A,B,C] = [input() for i in range(4)]
[X,Y,Z,K] = [int(i) for i in XYZK.split()]
A = sorted([int(i) for i in A.split()],reverse=True)
B = sorted([int(i) for i in B.split()],reverse=True)
C = sorted([int(i) for i in C.split()],reverse=True)
A = A[:K]
B = B[:K]
C = C[:K]
Ans = [0 for i in range(K)]
for a in A:
    for b in B:
        for c in C:
            abc = a+b+c
            if min(Ans) < a + b + c:
                Ans[Ans.index(min(Ans))] = a+b+c
Ans = sorted(Ans,reverse=True)
for i in range(len(Ans)):
    print(Ans[i])

Submission status: Time Limit Exceeded

Solution code:
[XYZK,A,B,C] = [input() for i in range(4)]
[X,Y,Z,K] = [int(i) for i in XYZK.split()]
A = [int(i) for i in A.split()]
B = [int(i) for i in B.split()]
C = [int(i) for i in C.split()]
Ans = [0 for i in range(K)]
for a in A:
    for b in B:
        for c in C:
            abc = a+b+c
            if min(Ans) < a + b + c:
                Ans[Ans.index(min(Ans))] = a+b+c
Ans = sorted(Ans,reverse=True)
for i in range(len(Ans)):
    print(Ans[i])

Submission status: Time Limit Exceeded

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

if len(AB) > K:
    AB = AB[:K + 1]
ABC = []
for i in range(len(AB)):
    for j in range(Z):
        ABC.append(AB[i] + C[j])
ABC = sorted(ABC, reverse=True)
print(*ABC[:K])

Submission status: Time Limit Exceeded

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

if len(AB) > K:
    AB = AB[:K + 1]
ABC = []
for i in range(len(AB)):
    for j in range(Z):
        ABC.append(AB[i] + C[j])
ABC = sorted(ABC, reverse=True)
print(*ABC[:K])

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K = (int(num) for num in input().split())
a = [int(num) for num in input().split()]
b = [int(num) for num in input().split()]
c = [int(num) for num in input().split()]
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

l = [(0,0,0,a[0]+b[0]+c[0])]
unvisited = [[[True for i in range(X)] for j in range(Y)] for k in range(Z)]
unvisited[0][0][0] = False
for i in range(K):
    xt,yt,zt,pt = l.pop(0)
    print(pt)
    list_dx = [1,0,0]
    list_dy = [0,1,0]
    list_dz = [0,0,1]
    for j in range(3):
        dx = list_dx[j]
        dy = list_dy[j]
        dz = list_dz[j]
        if xt+dx<X and yt+dy<Y and zt+dz<Z and xt+yt+zt<=K-3 and unvisited[xt+dx][yt+dy][zt+dz]:
            l.append((xt+dx,yt+dy,zt+dz,a[xt+dx]+b[yt+dy]+c[zt+dz]))
            l.sort(key=lambda x:x[3], reverse=True)
            unvisited[xt+dx][yt+dy][zt+dz] = False

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K = (int(num) for num in input().split())
a = [int(num) for num in input().split()]
b = [int(num) for num in input().split()]
c = [int(num) for num in input().split()]
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

l = [(0,0,0,a[0]+b[0]+c[0])]
unvisited = [[[True for i in range(X)] for j in range(Y)] for k in range(Z)]
unvisited[0][0][0] = False
for i in range(K):
    xt,yt,zt,pt = l.pop(0)
    print(pt)
    list_dx = [1,0,0]
    list_dy = [0,1,0]
    list_dz = [0,0,1]
    for j in range(3):
        dx = list_dx[j]
        dy = list_dy[j]
        dz = list_dz[j]
        if xt+dx<X and yt+dy<Y and zt+dz<Z and unvisited[xt+dx][yt+dy][zt+dz]:
            l.append((xt+dx,yt+dy,zt+dz,a[xt+dx]+b[yt+dy]+c[zt+dz]))
            l.sort(key=lambda x:x[3], reverse=True)
            unvisited[xt+dx][yt+dy][zt+dz] = False

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int, input().split())
A = list(sorted(list(map(int, input().split())), reverse=True))
B = list(sorted(list(map(int, input().split())), reverse=True))
C = list(sorted(list(map(int, input().split())), reverse=True))
D = [A[a] + B[b] + C[c] for a in range(x) for b in range(y) for c in range(z) if (a + 1) * (b + 1) * (c + 1) <= k]
D.sort(reverse=True)
for i in range(k):
    print(D[i])

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k = [int(num) for num in input().split()]
a_cake,b_cake,c_cake = [sorted([int(num) for num in input().split()],reverse=True)[:k] for _ in range(3)]

sum_cake = sorted([a+b+c for a in a_cake for b in b_cake for c in c_cake],reverse=True)[:k]

for i in sum_cake:
    print(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)

delicious_list = []
for i in range(len(A)):
    for j in range(len(B)):
        for k in range(len(C)):
            if i*j*k>=K: continue
            delicious_list.append(A[i]+B[j]+C[k])
delicious_list.sort(reverse=True)
for i in range(K):
    print(delicious_list[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)

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

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

delicious_list = []
for a in A:
    for b in B:
        for c in C:
            delicious_list.append(a+b+c)
delicious_list.sort(reverse=True)
for i in range(K):
    print(delicious_list[i])

Submission status: Time Limit Exceeded

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

ans = []
for ai in range(len(a)):
    for bi in range(len(b)):
        if (ai+1)*(bi+1) > k:
            continue
        for ci in range(len(c)):
            if (ai+1)*(bi+1)*(ci+1) >k:
                continue
            ans.append(a[ai] + b[bi] +c[ci])

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

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k = [int(num) for num in input().split()]
a_cake,b_cake,c_cake = [sorted([int(num) for num in input().split()],reverse=True) for _ in range(3)]

sum_cake = sorted([a+b+c for a in a_cake for b in b_cake for c in c_cake],reverse=True)[:k]

for i in sum_cake:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import numpy as np

xn,yn,zn,K = map(int,stdin.readline().strip().split())
X = np.array(list(map(int,stdin.readline().strip().split())),dtype=np.int64)
Y = np.array(list(map(int,stdin.readline().strip().split())),dtype=np.int64)
Z = np.array(list(map(int,stdin.readline().strip().split())),dtype=np.int64)

xy = np.zeros(X.size * Y.size,dtype=np.int64)

cnt = 0
for i in X:
    for j in Y:
        xy[cnt] = i + j
        cnt += 1

xy = np.sort(xy)
if xy.size > K:
    xy = xy[(-1*K):]

xyz = np.zeros(xy.size * Z.size,dtype=np.int64)

cnt = 0
for i in xy:
    for j in Z:
        xyz[cnt] = i + j
        cnt += 1

xyz = np.sort(xyz)

for i in range(K):
    print(xyz[-1-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()))
sum = 0
ans = []
ans2 = []

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

for i in range(min(K,len(ans))):
    for j in range(Z):
        sum = ans[i] + C[j]
        ans2.append(sum)
ans2.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
#from collections import deque
#import copy

x,y,z,ansk=(int(i) for i in input().split())
#print(x,y,z,k)

a=list(int(i) for i in input().split())
a.sort(reverse=True)
b=list(int(i) for i in input().split())
b.sort(reverse=True)
c=list(int(i) for i in input().split())
c.sort(reverse=True)
#print(a,b,c)

l=0
mylist=[0 for i in range(x*y*z)]
for i in range(x):
  for j in range(y):
    if (i+1)*(j+1) <= ansk:
      for k in range(z):
        if (i+1)*(j+1)*(k+1) <= ansk:      
          mylist[l]=a[i]+b[j]+c[k]
          l+=1
mylist.sort(reverse=True)

#print(mylist)

for i in range(ansk):
  print(mylist[i])

Submission status: Time Limit Exceeded

Solution code:
a,b,c,d = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
br = list(map(int,input().split(" ")))
cr = list(map(int,input().split(" ")))
dr = []
for x in ar:
    for y in br:
        for z in cr:
            dr.append(x+y+z)
dr = sorted(dr,reverse=True)
er = []
for i in range(d):
    print(dr[i])

Submission status: Time Limit Exceeded

Solution code:
X, Y, Z, K = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
m_list = []
for i in a_list:
    for j in b_list:
        m = i+j
        m_list.append(m)
m_list.sort(reverse = True)
if len(m_list) >= K:
    K_list = m_list[0:K]
else:
    K_list = m_list
ans_list = []
for i in K_list:
    for j in c_list:
        ans = i + j
        ans_list.append(ans)
ans_list.sort(reverse = True)
for i in range(K):
    print(ans_list[i])

Submission status: Time Limit Exceeded

Solution code:
#from collections import deque
#import copy

x,y,z,ansk=(int(i) for i in input().split())
#print(x,y,z,k)

a=list(int(i) for i in input().split())
a.sort(reverse=True)
b=list(int(i) for i in input().split())
b.sort(reverse=True)
c=list(int(i) for i in input().split())
c.sort(reverse=True)
#print(a,b,c)

mylist=[0 for i in range(x*y)]
k=0
for i in range(x):
  for j in range(y):
    mylist[k]=a[i]+b[j]
    k+=1
mylist.sort(reverse=True)
if len(mylist)>3001:
  mylist=mylist[:3001]
#print(mylist)

k=0
mylist1=[0 for i in range(x*y*z)]
for i in range(x*y):
  for j in range(z):
    mylist1[k]=mylist[i]+c[j]
    k+=1
mylist1.sort(reverse=True)

if len(mylist1) > 3001:
  mylist1 = mylist1[:3001]
  
for i in range(ansk):
  print(mylist1[i])

Submission status: Time Limit Exceeded

Solution code:
#from collections import deque
#import copy

x,y,z,ansk=(int(i) for i in input().split())
#print(x,y,z,k)

a=list(int(i) for i in input().split())
a.sort(reverse=True)
b=list(int(i) for i in input().split())
b.sort(reverse=True)
c=list(int(i) for i in input().split())
c.sort(reverse=True)
#print(a,b,c)

mylist=[0 for i in range(x*y)]
k=0
for i in range(x):
  for j in range(y):
    mylist[k]=a[i]+b[j]
    k+=1
mylist.sort(reverse=True)
#print(mylist)

k=0
mylist1=[0 for i in range(x*y*z)]
for i in range(x*y):
  for j in range(z):
    mylist1[k]=mylist[i]+c[j]
    k+=1
mylist1.sort(reverse=True)

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

data=[]
N=0
while N<K:
  for i in range(0,X):
  
    for j in range(0,Y):
    
      for k in range(0,Z):
        data.append(int(A[i]+B[j]+C[k]))
        N=N+1
    
data.sort()
data.reverse()

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

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

data=[]

for i in range(0,X):
  
  for j in range(0,Y):
    
    for k in range(0,Z):
      data.append(int(A[i]+B[j]+C[k]))
    
data.sort()
data.reverse()

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

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

data=[]

for i in range(0,X):
  a=int(A[i])
  
  for j in range(0,Y):
    b=int(B[j])
    
    for k in range(0,Z):
      c=int(C[k])
      data.append(int(a+b+c))
    
data.sort()
data.reverse()

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

Submission status: Time Limit Exceeded

Solution code:
import sys

x, y, z, k = map(int, sys.stdin.readline().split())

xlist = sorted(list([int(i)
                     for i in sys.stdin.readline().split()]), reverse=True)[:min(x, k)]
ylist = sorted(list([int(i)
                     for i in sys.stdin.readline().split()]), reverse=True)[:min(y, k)]
zlist = sorted(list([int(i)
                     for i in sys.stdin.readline().split()]), reverse=True)[:min(z, k)]


anslist = [0]
for i in range(min(x, k)):
    for j in range(min(y, k)):
        for l in range(min(z, k)):
            if (i+1)*(j+1)*(l+1) <= k:
                anslist.append(xlist[i]+ylist[j]+zlist[l])

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

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


sum0.sort(reverse = True)

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

Submission status: Time Limit Exceeded

Solution code:
import sys

x, y, z, k = map(int, sys.stdin.readline().split())

xlist = sorted(list([int(i)
                     for i in sys.stdin.readline().split()]), reverse=True)[:min(x, k)]
ylist = sorted(list([int(i)
                     for i in sys.stdin.readline().split()]), reverse=True)[:min(y, k)]
zlist = sorted(list([int(i)
                     for i in sys.stdin.readline().split()]), reverse=True)[:min(z, k)]


anslist = [0]
for i in range(min(x, k)):
    for j in range(min(y, k)):
        for l in range(min(z, k)):
            if i*j*l <= k:
                anslist.append(xlist[i]+ylist[j]+zlist[l])

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

sum0 = []

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


sum0.sort(reverse = True)

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

Submission status: Time Limit Exceeded

Solution code:
import sys

x, y, z, k = map(int, sys.stdin.readline().split())

xlist = sorted(list([int(i)
                     for i in sys.stdin.readline().split()]), reverse=True)[:min(x, k)]
ylist = sorted(list([int(i)
                     for i in sys.stdin.readline().split()]), reverse=True)[:min(y, k)]
zlist = sorted(list([int(i)
                     for i in sys.stdin.readline().split()]), reverse=True)[:min(z, k)]


anslist = [0]
for i in range(min(x, k)):
    for j in range(min(y, k)):
        for l in range(min(z, k)):
            anslist.append(xlist[i]+ylist[j]+zlist[l])

anslist = sorted(anslist, reverse=True)
for i in range(k):
    print(anslist[i])

Submission status: Time Limit Exceeded

Solution code:
init_data = [int(c) for c in input().split(' ')]

cake_value = []
for i in range(3):
    cake_value.append([int(c) for c in input().split(' ')])

result_list = []
for i in range(init_data[0]):
    for j in range(init_data[1]):
        for k in range(init_data[2]):
            result_list.append(cake_value[0][i] + cake_value[1][j] + cake_value[2][k])

result_list.sort(reverse=True)
for result in result_list[:init_data[3]]:
    print(result)

Submission status: Time Limit Exceeded

Solution code:
import copy

init_data = [int(c) for c in input().split(' ')]

cake_value = []
for i in range(3):
    cake_value.append(sorted([int(c) for c in input().split(' ')], reverse=True))

itr = [0, 0, 0]
candidate_list = [[0, 0, 0, sum([cake_value[i][0] for i in range(3)])], [0, 0, 0, -1]]
never_candidate_list = [[[True for k in range(init_data[2])] for j in range(init_data[1])] for i in range(init_data[0])]
never_candidate_list[0][0][0] = True
for i in range(init_data[3]):
    for j in range(3):
        buffer = copy.copy(itr)
        buffer[j] += 1
        if buffer[j] == init_data[j]:
            continue
        buffer.append(sum([cake_value[cake][k] for cake, k in enumerate(buffer)]))
        if never_candidate_list[buffer[0]][buffer[1]][buffer[2]]:
            candidate_list.append(buffer)
            never_candidate_list[buffer[0]][buffer[1]][buffer[2]] = False
    candidate_list.sort(key=lambda x: x[3], reverse=True)
    print(candidate_list[0][-1])
    del candidate_list[0]
    itr = candidate_list[0][:-1]

Submission status: Time Limit Exceeded

Solution code:
import copy

init_data = [int(c) for c in input().split(' ')]

cake_value = []
for i in range(3):
    cake_value.append(sorted([int(c) for c in input().split(' ')], reverse=True))

itr_number = 0
candidate_list = [[0, 0, 0, sum([cake_value[i][0] for i in range(3)])]]
for i in range(init_data[3]):
    for j in range(3):
        buffer = copy.copy(candidate_list[itr_number][:-1])
        buffer[j] += 1
        if buffer[j] == init_data[j]:
            continue
        buffer.append(sum([cake_value[cake][k] for cake, k in enumerate(buffer)]))
        if buffer not in candidate_list:
            candidate_list.append(buffer)
    candidate_list.sort(key=lambda x: x[3], reverse=True)
    print(candidate_list[itr_number][-1])
    itr_number += 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()))

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

ans = []
for i in range(min(x * y, k)):
    for j in c:
        ans.append(li[i] + j)
ans.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int, input().split())
a = 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)

final_ans = sorted([a[ai] + b[bi] +c[ci] for ai in range(len(a)) for bi in range(len(b)) for ci in range(len(c)) if (ai+1)*(bi+1)*(ci+1) <=k],reverse=True)[:k]

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

d = []
for i in range(len(a)):
    for j in range(len(b)):
        d.append(a[i]+b[j])

tmp = sorted(d, reverse=True)
if len(tmp) < k:
    use_tmp = tmp
else:
    use_tmp = tmp[0:k]
    
ans = []
for i in range(len(use_tmp)):
    for j in range(len(c)):
        ans.append(use_tmp[i]+c[j])
final_ans = sorted(ans, reverse=True)

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

# 美味しさ P 以上の組が K 個以上あるか
def is_exist_K_tuples(P):
    cnt = 0
    for i in range(X):
        for j in range(Y):
            for k in range(Z):
                if A[i] + B[j] + C[k] >= P:
                    cnt += 1
                if cnt >= K:
                    return True
    return False

# 二部探索で K 個以上の組がギリギリ存在する美味しさのラインをサーチ
left = 0
right = A[0] + B[0] + C[0]
while left <= right:
    border = (left + right) // 2
    if is_exist_K_tuples(border):
        left = border + 1
    else:
        right = border - 1
else:
    # 最後の border で K 個あるかは保証されていないので再チェックしてダメなら補正
    if not is_exist_K_tuples(border):
        border -= 1

# 枝刈り全探索で border + 1 以上の美味しさを列挙
result = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if A[i] + B[j] + C[k] >= border + 1:
                result.append(A[i] + B[j] + C[k])
            else:
                break

# 残りがあればそれはすべて border のはず
remains = K - len(result)
for _ in range(remains):
    result.append(border)

result.sort(reverse=True)
for r in result:
    print(r)

Submission status: Time Limit Exceeded

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

sumAB = sorted([ai + bi for ai in a for bi in b],reverse=True)
sumABC = sorted([ci + abi for ci in c for abi in sumAB],reverse = True)

for i in range(k):
    print(sumABC[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()))
ans = []
for r in itertools.product(a,b,c):
    ans.append(r[0] + r[1] + r[2])
ans.sort()
for i in range(k):
    print(ans[-i-1])

Submission status: Time Limit Exceeded

Solution code:
# import sys
# def p(*a):
#   s=" ".join(map(str,a))
#   #print(s)
#   sys.stderr.write(s+"\n")

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

A = sorted(list( map(int, input().split()) ), reverse=True)	# 1 2 3 4 5 ...(ソート付き)
B = sorted(list( map(int, input().split()) ), reverse=True)	# 1 2 3 4 5 ...(ソート付き)
C = sorted(list( map(int, input().split()) ), reverse=True)	# 1 2 3 4 5 ...(ソート付き)

# p(X,Y,Z,K)
# p(A)
# p(B)
# p(C)

#ABC=[]
#for a in range(X):
#	for b in range(Y):
#		if (a+b)>K: break
#		for c in range(Z):
#			if (a+b+c)>K: break
#			ABC.append(A[a]+B[b]+C[c])
#
#ABC.sort(reverse=True)

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

AB.sort(reverse=True)
# p("AB=",AB)

ABC=[]
for ab in range(min(K,len(AB))):
  for c in range(Z):
    ABC.append(AB[ab]+C[c])

ABC.sort(reverse=True)
# p("ABC=",ABC)

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

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() ]
s = []
for i in a:
    for j in b:
        s.append(i+j)
s = sorted(s,reverse=True)
nw = []
for i in c:
    for j in range(min(k,len(s))):
        nw.append( i + s[j] )
nw = sorted(nw,reverse=True)
for i in range(k):
    print(nw[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()))

E = [r[0]+r[1] for r in itertools.product(sorted(A), sorted(B))]
Final = [r[0]+r[1] for r in itertools.product(sorted(E), sorted(C))]

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

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int, input().split())
Lis = []
for _ in range(3):
    L = list(map(int, input().split()))
    L.sort(reverse=True)
    Lis.append(L)

Li = [[0, 0, 0]]
def search():
    global dic
    L = []
    for a, b, c in Li:
        for d, e, f in [[1, 0, 0], [0, 1, 0], [0, 0, 1]]:
            if a+d < x and b+e < y and c+f < z and [a+d, b+e, c+f] not in Li:
                re = Lis[0][a+d] + Lis[1][b+e] + Lis[2][c+f]
                L.append([re, a+d, b+e, c+f])
    L.sort(reverse=True)
    Li.append([L[0][1], L[0][2], L[0][3]])
    return L[0][0]
    

for i in range(k):
    if i == 0:
        ans = Lis[0][0] + Lis[1][0] + Lis[2][0]
        print(ans)
    else:
        print(search())

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k=map(int,input().split())
a=sorted(map(int,input().split()))[::-1]
b=sorted(map(int,input().split()))[::-1]
c=sorted(map(int,input().split()))[::-1]

ab=sorted([i+j for i in a[:k] for j in b[:k]])[::-1]
abc=sorted([i+j for i in ab[:k] for j in c[:k]])[::-1]

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