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=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
aa=sorted(a,reverse=True)
bb=sorted(b,reverse=True)
cc=sorted(c,reverse=True)
n=0
l=[]
while n<=k:
    for i in range(k//3):
        for j in range(k//3):
            for x in range(k//3):
                ll=l.append(aa[i]+bb[j]+cc[x])
ll.sort(reverse=True)
for i in range(k):
    print(ll[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)
AA = []
BB = []
CC = []
for i in range(X):
    AA.append(A[i])
for i in range(Y):
    BB.append(B[i])
for i in range(Z):
    CC.append(C[i])

ans = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            ans.append(AA[i] + BB[j] + CC[k])
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()))

d=[]
for i in a:
  for j in b:
    d.append(i+j)
d.sort(reverse=1)
ans=[]
if x+y>k:
  for i in d[:k]:
    for j in c:
      ans.append(i+j)
else:
  for i in d:
    for j in c:
      ans.append(i+j)
ans.sort(reverse=1)
if x+y+z>k:
  for i in ans[:k]:
    print(i)
else:
  for i in ans:
    print(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()))
extend_list = sorted(a)[len(a)-k:].copy()
extend_list.extend(sorted(b)[len(b)-k:])
extend_list.extend(sorted(c)[len(c)-k:])
extend_list = sorted(extend_list)[len(extend_list)-k:]
extend_list.extend(max([a]))
extend_list.extend(max([b]))
extend_list.extend(max([c]))
#print(all_list)
itr_list = []
for i in list(itertools.product([k for k in a if k in extend_list],
                                [k for k in b if k in extend_list],
                                [k for k in c if k in extend_list])):
  #print(sum(i))
  itr_list.append(sum(i))
#print(sorted(itr_list))
for i in range(k):
  print(sorted(itr_list)[len(itr_list)-i-1])

Submission status: Time Limit Exceeded

Solution code:
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()
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:
X, Y, Z, K = list(map(int, input().split(" ")))
xs = list(map(int, input().split(" ")))
ys = list(map(int, input().split(" ")))
zs = list(map(int, input().split(" ")))
lst = [x + y + z for x in xs for y in ys for z in zs]
lst_s = sorted(lst)
for i in range(K):
    print(lst_s[-(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.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

apb =  []

for a in A:
    for b in B:
        apb.append(a+b)
apb.sort(reverse=True)

apb = apb[:K]
ans = []

for k in apb:
    for c in (C):
        ans.append(k+c)
ans.sort(reverse=True)

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

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)>3000:
    yz=yz[:3000]


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:
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=map(int,input().split())
B=map(int,input().split())
C=map(int,input().split())
A=list(A)
B=list(B)
C=list(C)
s=[]
count=0
mx=0
for i in range(len(A)):
    for j in range(len(B)):
        for k in range(len(C)):
            count+=1
            if count>3000:
                if A[i]+B[j]+C[k]<mx:
                    s+=[A[i]+B[j]+C[k]]
                    s.remove(max(s))
                    mx=max(s)
            else:
                s+=[A[i]+B[j]+C[k]]
                if mx<A[i]+B[j]+C[k]:
                    mx=A[i]+B[j]+C[k]
s.sort(reverse=True)
for i in range(K):
    print(s[i])

Submission status: Time Limit Exceeded

Solution code:
"""
python3 main.py < input.txt
"""
import math
import itertools as it

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

def abc(x): return A[x[0]]+B[x[1]]+C[x[2]]
def cand(c): 
    x,y,z=c[0],c[1],c[2]
    return [(x+1,y,z),(x,y+1,z),(x,y,z+1)]
dp={1:(0,0,0)}
dpV={(0,0,0)}
def f(k):
    if k in dp:
        return abc(dp[k])
    candidates=list(it.chain.from_iterable([cand(dp[i]) for i in range(1,k)]))
    #print(candidates)
    candidates=list(filter(lambda x: (x not in dpV) and x[0]<X and x[1]<Y and x[2]<Z, candidates))
    #print(candidates)
    dp[k]=max(candidates,key=abc)
    dpV.add(dp[k])
    return abc(dp[k])
    
for i in range(1,K+1):
    print(f(i))

Submission status: Time Limit Exceeded

Solution code:
line = input().split(sep=" ")
x = int(line[0])
y = int(line[1])
z = int(line[2])
in_k = int(line[3])


in_x = sorted(list(map(int,input().split(sep=" "))))
in_y = sorted(list(map(int,input().split(sep=" "))))
in_z = sorted(list(map(int,input().split(sep=" "))))

ans_arr = []

if(x > in_k ): x =in_k
if(y > in_k ): y =in_k
if(z > in_k ): z =in_k

for i in range(x):
	for j in range(y):
		for k in range(z):
			ans_arr.append(in_x[i] + in_y[j] + in_z[k])

ans_arr = sorted(ans_arr,reverse=True)

for i in range(in_k):
	print(ans_arr[i])

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 xy>3000:
        break
    for z in range(Z):
        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,=map(int,input().split())
*b,=map(int,input().split())
*c,=map(int,input().split())
l=[0]*3000
r=[0]*3000
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)
for i in range(y):
    l=merge(l,list(map(lambda w:w+b[i],a)))
for i in range(z):
    r=merge(r,list(map(lambda w:w+c[i],l)))
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()))

out=[]

for i in range(X):
    for j in range(Y):
        for k in range(Z):
            out.append(A[i]+B[j]+C[k])

out.sort(reverse=True)

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

cal = []

def a(X,K):
  if X > K:
  	return K
  else:
    return X
  
for i in range(a(X,K)):
  for j in range(a(Y,K)):
    for k in range(a(Z,K)):
      cal.append(A[i]+B[j]+C[k])

cal.sort()
cal.reverse()

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

Submission status: Time Limit Exceeded

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

x,y,z,K=rl()
A=rl()
B=rl()
C=rl()
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
X=[]
for a,b,c in zip(A,B,C):
    X.append([a,0])
    X.append([b,1])
    X.append([c,2])
X.sort(reverse=True)

ca=0
cb=0
cc=0
xl = len(X)
if x*y*z>=3000:
    for i in range(len(X)):
        _,a = X[i]
        if a == 0:
            ca += 1
        elif a == 1:
            cb += 1
        else:
            cc += 1 
        if ca*cb*cc>=3000:
            xl=i
            break
else:
    ca=x
    cb=y
    cc=z

ans = []
import itertools
for a,b,c in itertools.product(A[:ca],B,C):
    ans.append(a+b+c)
if ca < x:
    for a,b,c in itertools.product(A[ca:],B[:cb],C):
        ans.append(a+b+c)
    if cb < y:
        for a,b,c in itertools.product(A[ca:],B[cb:],C[:cc]):
            ans.append(a+b+c)
ans.sort(reverse=True)
for i in range(K):
    print(ans[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 = []
    for i in range(X):
        for j in range(Z):
            BC.append(B[i] + C[j])

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


    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 as itr

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

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

Xs.sort()
Ys.sort()
Zs.sort()

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

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


def seek_max(xrange,yrange,zrange):
	val = -1 
	for ind in itr.product(range(xrange+1),range(yrange+1),range(zrange+1)):
		if ind not in used:
			if Xs[ind[0]] + Ys[ind[1]] + Zs[ind[2]] > val:
				val = Xs[ind[0]] + Ys[ind[1]] + Zs[ind[2]]
				indexes = ind
	
	return indexes,val


used = set()
Xrange = 0
Yrange = 0
Zrange = 0
for _ in range(K):
	
	if len(used) > 0:
		Xrange = max([ind[0] for ind in used])
		Yrange = max([ind[1] for ind in used])
		Zrange = max([ind[2] for ind in used])

	ind,val = seek_max(Xrange+1,Yrange+1,Zrange+1)
	used.add(ind)
	print(val)

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(-10,10):
        for dy in range(-10,10):
            for dz in range(-10,10):
                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:
# -*- 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)
            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:
def main(m):
    x, y, z, k = list(map(int, m[0].split(' ')))
    a = list(map(int, m[1].split(' ')))
    b = list(map(int, m[2].split(' ')))
    c = list(map(int, m[3].split(' ')))
    l = []
    for i in range(x):
        for j in range(y):
            for h in range(z):
                l.append(a[i] + b[j] + c[h])
    
    sl = list(reversed(sorted(l)))
    for i in range(k):
        print(sl[i])
                

if __name__ == '__main__':
    try:
        m = []
        for i in range(4):
            m.append(input().strip())
        main(m)
    except EOFError:
        pass

Submission status: Time Limit Exceeded

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

sums = []

for i in range(x):
    for j in range(y):
        for l in range(z):
            sums.append(a[i] + b[j] + c[l])
sums.sort()
ans = sums[::-1]

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())
l_a = list(map(int,input().split()))
l_b = list(map(int,input().split()))
l_c = list(map(int,input().split()))
p = itertools.product(l_a,l_b,l_c)
ans = []
for i in p:
    ans.append(sum(i))
ans.sort(reverse = True)
for j in range(K):
    print(ans[j])

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(-30,30):
        for dy in range(-30,30):
            for dz in range(-30,30):
                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:
a = []
b = []
c = []
l = 300
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()

a2 = a[max(0,len(a)-l):]
b2 = b[max(0,len(b)-l):]
c2 = c[max(0,len(c)-l):]

oisi = []
for i in range(min(len(a2),l)):
  for j in range(min(len(b2),l)):
    for m in range(min(len(c2),l)):
      oisi.append(a2[i]+b2[j]+c2[m])

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3



def solv(x, y, z, k, a, b, c):
    a = sorted(a, reverse=True)
    b = sorted(b, reverse=True)
    c = sorted(c, reverse=True)

    m = max(a[0] - a[-1], b[0] - b[-1], c[0] - c[-1])

    while True:
        aa = list(filter(lambda v: v > a[0] - m, a))
        bb = list(filter(lambda v: v > b[0] - m, b))
        cc = list(filter(lambda v: v > c[0] - m, c))

        if len(aa) * len(bb) * len(cc) < 10000:
            break

        m = m * 0.9

    aa = a
    bb = b
    cc = c

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

    all = sorted(all, reverse=True)

    return all[:k]


if __name__ == '__main__':

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

    ans = solv(x, y, z, k, a, b, c)

    for ans_i in ans:
        print(ans_i)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

import sys
input = sys.stdin.readline

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)

bimi = []
cnt = -100000000

def roop():
        global cnt
        for a in range(X):
                for b in range(Y):
                        for c in range(Z):
                                bimi.append(A[a] + B[b] + C[c])
                                cnt += 1

                                if cnt == K:
                                        return

roop()
bimi.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

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 = [sum(i) for i in product(A, B, C)]

for i in sorted(l, reverse=True)[: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()))
array = []

for a in A:
  for b in B:
    for c in C:
      array.append(a+b+c)

array.sort()
array.reverse()
for i in range(K):
  print(array[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)

dp = dict()


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


def main():
    done = []

    for k in range(K):
        if done == []:
            t = (0, 0, 0)
            done.append(t)
            print (f(t))
            continue

        temp = 0
        for d in done:
            x, y, z = d
            KOUHO = [(x, y, z+1), (x, y+1, z), (x+1, y, z)]
            for kouho in KOUHO:
                if kouho[0] == X:
                    continue
                if kouho[1] == Y:
                    continue
                if kouho[2] == Z:
                    continue
                if kouho in done:
                    continue
                if f(kouho) > temp:
                    toadd = kouho
                    temp = f(kouho)

        done.append(toadd)
        print(temp)


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

a.sort(reverse=1)
b.sort(reverse=1)
c.sort(reverse=1)
d=[]
for i in a:
  for j in b:
    d.append(i+j)
d.sort(reverse=1)
ans=[]
if x+y>k:
  for i in d[:k]:
    for j in c:
      ans.append(i+j)
else:
  for i in d:
    for j in c:
      ans.append(i+j)
ans.sort(reverse=1)
if x+y+z>k:
  for i in ans[:k]:
    print(i)
else:
  for i in ans:
    print(i)

Submission status: Time Limit Exceeded

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

# 1整数
# n = int(input())

# 空白区切り2変数
from queue import Queue
from operator import mul
from functools import reduce
from queue import Queue
from operator import mul
from functools import reduce
from functools import lru_cache

input = sys.stdin.readline

# N個整数
x, y, z, kk = list(map(int, input().split()))

# 1整数
# n = int(input())

# 空白区切りリスト整数
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)


ll = [0] * 10000000
count = 0
for i in range(len(a)):
    for j in range(len(b)):
        if i * j > kk:

            break
        for k in range(len(c)):
            if i * j * k > kk:
                break
            ll[count] = a[i] + b[j] + c[k]
            count += 1
ll.sort(reverse=True)

for i in range(kk):
    print(ll[i])

# 空白区切り文字列
# t, d = input().split()

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()))
lisa.sort(reverse=True)
lisb.sort(reverse=True)
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(-100,100):
        for dy in range(-100,100):
            for dz in range(-100,100):
                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 = input().split(" ")
A = [int(i) for i in A]
B = input().split(" ")
B = [int(i) for i in B]
C = input().split(" ")
C = [int(i) for i in C]
A = sorted(A,reverse = True)
B = sorted(B,reverse = True)
C = sorted(C,reverse = True)
#print(A,B,C)

list = []
for i in range(X):
    for j in range(Y):
        for l in range(Z):
            list.append(A[i]+B[j]+C[l])
list = sorted(list,reverse = True)

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

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

def taste(x):
    return A[x[0]] + B[x[1]] + C[x[2]]

p = [0,0,0]
print(taste(p))
n = 1
l=[[0,0,0]]

maxA=0
maxB=0
maxC=0

while n < K:
    cand = []
    for a in range(maxA+10):
        for b in range(maxB+10):
            for c in range(maxC+10):
                if a<X and b<Y and c<Z:  
                    cand.append([a,b,c])
    cand.sort(key = lambda x: taste(x), reverse=True)
    for x in cand:
        if x not in l:
            l.append(x)
            print(taste(x))
            n += 1
            maxA = x[0]
            maxB = x[1]
            maxC = x[2]
            break

Submission status: Time Limit Exceeded

Solution code:
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,20)]+b[min(Y-1,20)]+c[min(Z-1,20)]
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:
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()))
extend_list = a.copy()
extend_list.extend(b)
extend_list.extend(c)
extend_list = sorted(extend_list)[len(extend_list)-k:]
extend_list.extend(max([a]))
extend_list.extend(max([b]))
extend_list.extend(max([c]))
#print(all_list)
itr_list = []
for i in list(itertools.product([k for k in a if k in extend_list],
                                [k for k in b if k in extend_list],
                                [k for k in c if k in extend_list])):
  #print(sum(i))
  itr_list.append(sum(i))
#print(sorted(itr_list))
for i in range(k):
  print(sorted(itr_list)[len(itr_list)-i-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

K = int(input().split()[-1])

A = sorted([int(e) for e in input().split()], reverse=True)
B = sorted([int(e) for e in input().split()], reverse=True)
C = sorted([int(e) for e in input().split()], reverse=True)

A = A[:min(len(A) + 1, K)]
B = B[:min(len(B) + 1, K)]
C = C[:min(len(C) + 1, K)]

values = []

# prev_a = A[0]
# prev_b = B[0]
# prev_c = C[0]
# value = A[0] + B[0] + C[0]
# print(value)
# ia = 0
# ib = 0
# ic = 0

for a, b, c in itertools.product(A, B, C):
    values.append(a + b + c)
values = sorted(values, reverse=True)

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

#
# for i in range(K - 1):
#     if len(a) > ia + 1:
#
#         if A[ia] - A[ia + 1]:
#
#
#     a = max(A)
#     b = max(B)
#     c = max(C)
#
#     sub_a = prev_a - a
#     sub_b = prev_b - b
#     sub_c = prev_c - c
#
#     if sub_a < sub_b and sub_a < sub_c:
#         A.remove(a)
#     if sub_b < sub_a and sub_b < sub_c:
#         B.remove(b)
#     if sub_c < sub_a and sub_c < sub_b:
#         B.remove(c)
#
#     value -= min(sub_a, sub_b, sub_c)
#     print(value)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

x, y, z, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
n = 0
mn = -1
r = [0] * k
for i in range(x):
  for j in range(y):
    for l in range(z):
      s = a[i] + b[j] + c[l]
      if n < k:
        r[n] = s
      else:
        if n == k:
        	mn = np.argmin(r)
        if r[mn] < s:
          r[mn] = s
          mn = np.argmin(r)
      n += 1
r.sort()
for i in range(k):
  print(r[-(i+1)])