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:
# -*- 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()))

bc = [i + j for i in b for j in c]
bc.sort(reverse=True)

abc = [i + j for i in a for j in bc[:min(k, len(bc))]]
abc.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
X, Y, Z, K = map(int, 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:
            if d in done:
                continue
            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
            if ta in kouho:
                continue
            kouho.add(ta)

        done.add(todel)
        print(temp)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 16 20:52:46 2019

@author: Owner
"""


import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy
import bisect

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

"""

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

A = [0]*X
A[:] = map(int, input().split())
B = [0]*Y
B[:] = map(int, input().split())
C = [0]*Z
C[:] = map(int, input().split())

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ABC = [0]*K
aX = 0
bX = 0
cX = 0
for x in range(X):
    for y in range(Y):
        if ABC[-1] > A[x]+B[y]+C[cX]:
            for z in range(cX):
                if ABC[-1] > A[x]+B[y]+C[z]:
                    cX = z
                    break
                else:
                    ABC[-1] = max(ABC[-1], A[x]+B[y]+C[z])    
                    ABC.sort(reverse=True)
        else:
            for z in range(Z):
                if ABC[-1] > A[x]+B[y]+C[z]:
                    cX = z
                    break
                else:
                    ABC[-1] = max(ABC[-1], A[x]+B[y]+C[z])    
                    ABC.sort(reverse=True)
        
for k in range(K):
    print(ABC[k])

Submission status: Time Limit Exceeded

Solution code:
import sys,re,copy
input = sys.stdin.readline
X,Y,Z,K=[int(x) for x in input().strip().split()]

Ax=[int(x) for x in input().strip().split()]
By=[int(x) for x in input().strip().split()]
Cz=[int(x) for x in input().strip().split()]

Ax.sort()
Ax.reverse()
By.sort()
By.reverse()
Cz.sort()
Cz.reverse()

s=[[0,0,0]]
def nextpattern(s,ss):
    
    if s[0]!=X-1:
        if [s[0]+1,s[1],s[2]] not in ss:
            ss.append([s[0]+1,s[1],s[2]])
    if s[1]!=Y-1:
        if [s[0],s[1]+1,s[2]] not in ss:
            ss.append([s[0],s[1]+1,s[2]])
    if s[2]!=Z-1:
        if [s[0],s[1],s[2]+1] not in ss:
            ss.append([s[0],s[1],s[2]+1])
    return ss

pre=0
for _ in range(K):
    max_i=0
    max_c=0
    for i,c in enumerate(s):
        g=Ax[c[0]]+By[c[1]]+Cz[c[2]]
        if g>max_c:
            max_i = i
            max_c = g
        if g+1==pre:
            break
    print(max_c)
    pre=max_c
    max_l=s.pop(max_i)
    s=nextpattern(max_l,copy.deepcopy(s))

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, other):
    return self.a_idx == other.a_idx and self.b_idx == other.b_idx and self.c_idx == other.c_idx
  def __gt__(self, other):
    return self.value > other.value
  def __ge__(self, other):
    return self.value >= other.value
    
que = []
que.append(Value(A_list, B_list, C_list, 0, 0, 0))

for _ in range(K):
  if que:
    v = que.pop(0)
    print(v.value)
  new_v_list = []
  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 = 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()
b.sort()
c.sort()

n = 0

sum = []
for ai in a:
	for bi in b:
		for ci in c:
			sum.append(ai+bi+ci)

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

Submission status: Time Limit Exceeded

Solution code:
import heapq

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
res = []
for i in range(0, X):
    for j in range(0, Y):
        for k in range(0, Z):    
            res.append(A[i] + B[j] + C[k])
 
ress = heapq.nlargest(K, res)
for i in range(0, K):
    print(ress[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()))

AB = []
for p in itertools.product(A, B):
    AB.append(sum(p))
AB.sort(reverse=True)
AB = AB[:K]

l = []
for p in itertools.product(AB, C):
    l.append(sum(p))
l.sort(reverse=True)
for i in range(K):
    print(l[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()))
# xs.sort(reverse=True)
# ys.sort(reverse=True)
# zs.sort(reverse=True)
ans_list = []
for i,a in enumerate(list(product(xs,ys,zs))):
    ans_list.append(sum(a))
    
ans_list.sort(reverse=True)
for i,ans in enumerate(ans_list):
    print(ans)
    if i == k - 1:
        break

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [X, Y, Z, K] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2]), int(input_raw[3])]

    input_raw = read_func().strip().split()
    A = [long(input_raw[i]) for i in range(X)]
    input_raw = read_func().strip().split()
    B = [long(input_raw[i]) for i in range(Y)]
    input_raw = read_func().strip().split()
    C = [long(input_raw[i]) for i in range(Z)]

    count = 0
    BC = [0 for i in range(Y * Z)]
    for i in range(Y):
        for j in range(Z):
            BC[count] = B[i] + C[j]
            count += 1

    A.sort(reverse = True)
    BC.sort(reverse = True)
    T = [0 for i in range(X * min(K, len(BC)))]
    count = 0
    for i in range(X):
        for j in range(min(K, len(BC))):
            T[count] = (A[i] + BC[j])
            count += 1


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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
X, Y, Z, K = map(int, input().rstrip().split())
A = list(map(int, input().rstrip().split()))
B = list(map(int, input().rstrip().split()))
C = list(map(int, input().rstrip().split()))
A.sort()
B.sort()
C.sort()
if X*Y*Z != K:
    if X >= 200:
        A = A[:200]
    if Y >= 200:
        B = B[:200]
    if Z >= 200:
        C = C[:200]
combinations = list(itertools.product(A, B, C))
total = []
for combination in combinations:
    total.append(sum(combination))
total.sort(reverse=True)
for i in range(K):
    print(total[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()))
xs.sort(reverse=True)
ys.sort(reverse=True)
zs.sort(reverse=True)
ans_list = []
for i,a in enumerate(list(product(xs,ys,zs))):
    ans_list.append(sum(a))
    
ans_list.sort(reverse=True)
for i,ans in enumerate(ans_list):
    print(ans)
    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()))
ans=[]
for i in range(x):
    for j in range(y):
        for n in range(z):
            ans.append(a[i]+b[j]+c[n])
ans.sort()
ans=ans[::-1]
cnt=0
while cnt!=k:
    print(ans[cnt])
    cnt+=1

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
sum_AB = []
k = 0
for x in range(X):
    for y in range(Y):
        sum_AB.append(A[x]+B[y])
sum_AB.sort(reverse=True) #10**6
sum_count = []
for xy in range(X*Y):
    if k==1:
        break
    for z in range(Z):
        if xy>4000 and z>500:
            k=1
            break
        sum_count.append(sum_AB[xy]+C[z])

sum_count.sort(reverse=True)
for i in range(K):
    print(sum_count[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()
A.reverse()
B.sort()
B.reverse()
C.sort()
C.reverse()


array = []

for a in range(min(K,len(A))):
  for b in range(min(K,len(B))):
    for c in range(min(K,len(C))):
      array.append(A[a]+B[b]+C[c])

array.sort()
array.reverse()
for i in range(K):
  print(array[i])

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

# A.sort()
# A.reverse()
# B.sort()
# B.reverse()
C.sort()
C.reverse()
if len(C)>select:
    C = C[0:select]


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:
import bisect
a,b,c,k = map(int,input().split())

aa = list(map(int,input().split()))
bb = list(map(int,input().split()))
cc = list(map(int,input().split()))
aa.sort(reverse = True)
bb.sort(reverse = True)
cc.sort(reverse = True)
al = []

for i in range(a):
    for j in range(b):
        for l in range(c):
            kk = aa[i]+bb[j]+cc[l]
            bisect.insort_left(al,kk)
al.reverse()
for i in range(k):
    print(al[i])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr  6 20:40:01 2019

@author: Yamazaki Kenichi
"""

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,b,c = [],[],[]
for i in range(X):
    a.append(A[-1] - A[-i-1])
for i in range(Y):
    b.append(B[-1] - B[-i-1])
for i in range(Z):
    c.append(C[-1] - C[-i-1])
s1,s2,s3 = X,Y,Z
#while s1*s2*s3 < K:
#    if s1 + 1 <X and a[s1+1]-a[s1] == min(a[s1+1]-a[s1],c[s3+1]-c[s3],b[s2+1]-b[s2]):
#        s1 += 1
#    elif s2 + 1 <Y and  a[s2+1]-a[s2] == min(c[s3+1]-c[s3],b[s2+1]-b[s2]):
#        s2 += 1
#    elif s3 + 1 <Z:
#        s3 += 1 
ans = []
for i in range(s1):
    for j in range(s2):
        for k in range(s3):
            ans.append(A[-i-1]+B[-j-1]+C[-k-1])
ans.sort()
for i in range(K):
    print(ans[-i-1])

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:
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()))
A_.sort(reverse=True)
B_.sort(reverse=True)
C_.sort(reverse=True)

comb = list(itertools.product(A_,B_,C_))
sum_ = []
for i in range(len(comb)):
  sum_.append(sum(comb[i]))
sum_.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
from heapq import heapify, heappop, heappush
from collections import defaultdict

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 = list(sorted(a, reverse=True))
b = list(sorted(b, reverse=True))
c = list(sorted(c, reverse=True))

t = a[0] + b[0] + c[0]
t *= -1
d = defaultdict(list)
d[t] = [(0, 0, 0)]

q = list()
heapify(q)
heappush(q, t)

a_j = (1, 0, 0)
b_j = (0, 1, 0)
c_j = (0, 0, 1)

st = set()
for i in range(K):
    t = heappop(q)
    print(-t)
    for v in d[t]:
        a_i, b_i, c_i = v
        for j in range(3):
            na_i = a_i + a_j[j]
            if na_i >= X: continue
            nb_i = b_i + b_j[j]
            if nb_i >= Y: continue
            nc_i = c_i + c_j[j]
            if nc_i >= Z: continue

            nt = a[na_i] + b[nb_i] + c[nc_i]
            nt *= -1
            nv = (na_i, nb_i, nc_i)

            # print(nt, nv)

            if nv in st: continue
            d[nt].append(nv)
            st.add(nv)
            heappush(q, nt)

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

Dtotal = []

for i in range(x):
    for f in range(y):
        for g in range(z):
            Dtotal.append(A[i]+B[f]+C[g])

#Dtotalをソートする
while True:
    flg = 0
    for i in range(len(Dtotal)- 1):
        num1 = Dtotal[i]
        num2 = Dtotal[i+1]
        if num1 < num2:
            Dtotal[i] = num2
            Dtotal[i+1] = num1
            flg = flg + 1
    if flg == 0:
        break


#結果を出力する
for i in range(k):
    print(Dtotal[i])

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k=map(int,input().split())
A=sorted(list(map(int,input().split())),reverse=True)
B=sorted(list(map(int,input().split())),reverse=True)
C=sorted(list(map(int,input().split())),reverse=True)
a=1
b=1
c=1
A.append(-10**11)
B.append(-10**11)
C.append(-10**11)
A.insert(0,-10**11)
B.insert(0,-10**11)
C.insert(0,-10**11)
print(A[a]+B[b]+C[c])

memo=[[[False]*(z+2) for _ in range(y+2)] for _ in range(x+2)]
memo[a][b][c]=True

for _ in range(k-1):
    keepv=0
    for a2 in range(1,x+2):
        for b2 in range(1,y+2):
            for c2 in range(1,z+2):
                if not memo[a2][b2][c2]:
                    if A[a2]+B[b2]+C[c2]>keepv:
                        keepv=A[a2]+B[b2]+C[c2]
                        keepa=a2
                        keepb=b2
                        keepc=c2
    a=keepa
    b=keepb
    c=keepc
    print(A[a]+B[b]+C[c])
    #print(a,b,c)
    #print(memo[2][1][1])
    memo[a][b][c]=True

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()))
lisc.sort(reverse=True)
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()))
a = sorted(a)
b = sorted(b)
c = sorted(c)
memory = []
ai = x-1
bi = y-1
ci = z-1
p = 10**11
while k>0:
    ps = []
    abc = []
    for dx in range(-8,8):
        for dy in range(-8,8):
            for dz in range(-8,8):
                if not (ai+dx>=0 and ai+dx<x and bi+dy>=0 and bi+dy<y and ci+dz>=0 and ci+dz<z):
                    continue
                tmp = a[ai+dx]+b[bi+dy]+c[ci+dz]
                if p >= tmp and not (ai+dx,bi+dy,ci+dz) in memory:
                    ps.append(tmp) 
                    abc.append((ai+dx, bi+dy, ci+dz))
    p = max(ps)
    i = ps.index(p)
    memory.append(abc[i])
    print(p)
    k -= 1

Submission status: Time Limit Exceeded

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


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

scores.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
if __name__=="__main__":
    import sys
    readline = sys.stdin.readline
    X,Y,Z,K = map(int, readline().split())
    a = sorted(list(map(int, readline().split())), reverse=True)
    b = sorted(list(map(int, readline().split())), reverse=True)
    c = sorted(list(map(int, readline().split())), reverse=True)

    sums = []
    lower = a[min(X-1,14)]+b[min(Y-1,14)]+c[min(Z-1,14)]
    b_max,c_max = max(b),max(c)
    for i in range(X):
        if a[i]+b_max+c_max<lower:
            break
        for j in range(Y):
            if a[i]+b[j]+c_max<lower:
                break
            for k in range(Z):
                s = a[i]+b[j]+c[k]
                if s<lower:
                    break
                sums.append(s)
    sums.sort(reverse=True)
    for si in sums[:K]:
        print(si)

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:
       E.append(a+d)
E.sort(reverse=True)
for e in E[:k]:
    print(e)

Submission status: Time Limit Exceeded

Solution code:
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]


X,Y,Z,K = (int(x) for x in 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)

abc = [[0,0,0,A[0]+B[0]+C[0]]]
#next_abc = [[1,0,0],[0,1,0],[0,0,1]]
#print(A[abc[0][0]]+B[abc[0][1]]+C[abc[0][2]])

for i in range(K):
    max_v = 0
    for j in range(len(abc)):
        if abc[j][3] > max_v:
            max_v = abc[j][3]
            temp_j = j
            
    max_abc = abc.pop(temp_j)
    #print(max_abc)
    #print(A[max_abc[0]]+B[max_abc[1]]+C[max_abc[2]])
    print(max_v)
    
    if max_abc[0]<X-1:
        abc.append([max_abc[0]+1,max_abc[1],max_abc[2],A[max_abc[0]+1]+B[max_abc[1]]+C[max_abc[2]]])
    if max_abc[1]<Y-1:
        abc.append([max_abc[0],max_abc[1]+1,max_abc[2],A[max_abc[0]]+B[max_abc[1]+1]+C[max_abc[2]]])
    if max_abc[2]<Z-1:
        abc.append([max_abc[0],max_abc[1],max_abc[2]+1,A[max_abc[0]]+B[max_abc[1]]+C[max_abc[2]+1]])
    abc = get_unique_list(abc)
    #print(abc)

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

r = 0
li = []
for i in range(x):
    r += a[i]
    for j in range(y):
        r += b[j]
        for l in range(z):
            r += c[l]
            li.append(r)
            if len(li)>k:
                li.sort(reverse=True)
                li = li[:k]
            r -= c[l]
        r -= b[j]
    r -= a[i]

li.sort(reverse=True)

for f in li[:k]:
    print(f)

Submission status: Time Limit Exceeded

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

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

s = []
for l in a:
    for m in b:
        for n in c:
            s.append(l+m+n)
s.sort()
s.reverse()
for kk in range(k):
    print(s[kk])

Submission status: Time Limit Exceeded

Solution code:
n = list(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)

res = []

for i0 in range(n[0]):
    for i1 in range(n[1]):
        for i2 in range(n[2]):
            res.append(a[i0]+b[i1]+c[i2])

res = sorted(res,reverse=True)

for i in range(n[3]):
    print(res[i])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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)

AB = []
for p in itertools.product(A, B):
    AB.append(sum(p))
AB.sort(reverse=True)
AB = AB[:K]

l = []
for p in itertools.product(AB, C):
    l.append(sum(p))
l.sort(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)

a = 0
b = 0
c = 0

r = []

for x in range(X):
    for y in range(Y):
        for z in range(Z):
            r.append(A[x] + B[y] + C[z])

r.sort(reverse=True)

for i in range(K):
    print(r[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 = []
f = []
for i in range(max(0,len(a)-5), len(a)):
    for j in range(max(0,len(b)-5), len(b)):
        for l in range(max(0,len(c)-120), len(c)):
            if not [i,j,l] in f:
                e = a[i]+b[j]+c[l]
                d.append(e)
                f.append([i,j,l])
for i in range(max(0,len(a)-5), len(a)):
    for j in range(max(0,len(b)-120), len(b)):
        for l in range(max(0,len(c)-5), len(c)):
            if not [i,j,l] in f:
                e = a[i]+b[j]+c[l]
                d.append(e)
                f.append([i,j,l])
for i in range(max(0,len(a)-120), len(a)):
    for j in range(max(0,len(b)-5), len(b)):
        for l in range(max(0,len(c)-5), len(c)):
            if not [i,j,l] in f:
                e = a[i]+b[j]+c[l]
                d.append(e)
                f.append([i,j,l])
for i in range(max(0,len(a)- 20), len(a)):
    for j in range(max(0,len(b)-20), len(b)):
        for l in range(max(0,len(c)-20), len(c)):
            if not [i,j,l] in f:
                e = a[i]+b[j]+c[l]
                d.append(e)
                f.append([i,j,l])
d.sort()
for i in range(1,k+1):
    print(d[-i])

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [X, Y, Z, K] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2]), int(input_raw[3])]

    input_raw = read_func().strip().split()
    A = [long(input_raw[i]) for i in range(X)]
    input_raw = read_func().strip().split()
    B = [long(input_raw[i]) for i in range(Y)]
    input_raw = read_func().strip().split()
    C = [long(input_raw[i]) for i in range(Z)]

    count = 0
    BC = [0 for i in range(X * Z)]
    for i in range(X):
        for j in range(Z):
            BC[count] = B[i] + C[j]
            count += 1

    A.sort(reverse = True)
    BC.sort(reverse = True)
    T = [0 for i in range(X * min(K, len(BC)))]
    count = 0
    for i in range(X):
        for j in range(min(K, len(BC))):
            T[count] = (A[i] + BC[j])
            count += 1


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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

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

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



#L=[A[i]+B[j]+C[k] for i, j, k in zip(range(X),range(Y),range(Z))]
L=[A[i]+B[j]+C[k] for i in range(X) for j in range(Y) for k in range(Z)]
L.sort()
L.reverse()
i=0
for l in L:
	if(i==K):
		break
	print(l)
	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())

A_list = sorted(A_list, reverse=True)
B_list = sorted(B_list, reverse=True)
C_list = sorted(C_list, reverse=True)

import itertools
val_list = []

for a, b, c in itertools.product(A_list, B_list, C_list):
    val_list.append(a + b + c)
    
val_list = sorted(val_list, reverse=True)
for i in range(K):
    print(val_list[i])

Submission status: Time Limit Exceeded

Solution code:
xyzk = [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()]

o = []

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

o.sort(reverse=True)
for i in range(xyzk[3]):
    print(o[i])