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 -*-
# なんかおかしい！！
import math
import sys
import itertools
import numpy as np


# なんこか入力
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()
b.sort()
c.sort()
#cake = [[0 for i in range(3)] for j in range(3000)]
#cake[0][0]=x-1
#cake[0][1]=y-1
#cake[0][2]=z-1
#print(a[x-1]+b[y-1]+c[z-1])
#print(a[cake[0][0]],b[cake[0][1]],c[cake[0][2]])
s = [[x-1,y-1,z-1]]
t = [[-1,-1,-1] for i in range(3*k)]
t[0] = [x-1,y-1,z-1]
t_a = 1
#print(s)

for i in range(0,k):
    ma = 0
    temp = [-1,-1,-1]
    for j in s:
        if ma <= a[j[0]]+b[j[1]]+c[j[2]] :
            temp = j
            ma = a[j[0]]+b[j[1]]+c[j[2]]
#    print(temp)
    print(a[temp[0]]+b[temp[1]]+c[temp[2]])
#    print(a[temp[0]],b[temp[1]],c[temp[2]])
    s.remove(temp)
#    print("s=",s)
#    print("t=",t)
#    print(temp)
    if temp[0] > 0:
        if [temp[0]-1,temp[1],temp[2]] in t:
            pass
        else:
            s.append([temp[0]-1,temp[1],temp[2]])
            t[t_a] = [temp[0]-1,temp[1],temp[2]]
            t_a += 1
    if temp[1] > 0:
        if [temp[0],temp[1]-1,temp[2]] in t:
            pass
        else:
            s.append([temp[0],temp[1]-1,temp[2]])
            t[t_a] = [temp[0],temp[1]-1,temp[2]]
            t_a += 1
    if temp[2] > 0:
        if [temp[0],temp[1],temp[2]-1] in t:
            pass
        else:
            s.append([temp[0],temp[1],temp[2]-1])
            t[t_a] = [temp[0],temp[1],temp[2]-1]
            t_a += 1

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from string import ascii_uppercase
import sys, bisect
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

X, Y, Z, K = read_int()
A = read_int()
A.sort(reverse=True)
B = sorted(read_int())
C = sorted(read_int())

maxd = max(A) + max(B) + max(C)
mind = min(A) + min(B) + min(C)

yz = []
def solve():
    for i in range(Y):
        for j in range(Z):
            yz.append(B[i] + C[j])
    yz.sort(reverse=True)

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

if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
import itertools


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

AB = [a + b for (a, b) in list(itertools.product(A, B))]
AB = sorted(AB)[::-1]
ans = [ab + c for (ab, c) in list(itertools.product(AB[:3000], C))]
ans = sorted(ans)[::-1]
for i in range(K):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
import itertools
x,y,z,t = 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 k in range(y):
        ans.append(a[i]+b[k])
ans.sort()
ans.reverse()
if x*y > t:
    ans = ans[0:t]
out = []
for i in range(len(ans)):
    for k in range(z):
        out.append(ans[i]+c[k])
out.sort()
out.reverse()
for i in range(t):
    print(out[i])

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int, input().split())
cs = list(map(int, input().split()))
bs = list(map(int, input().split()))
a_s = list(map(int, input().split()))
a_s.sort(reverse=True)
bs.sort(reverse=True)
cs.sort(reverse=True)

list = []
i = -1
flag = True
minlist = 0
for a in a_s:
    if minlist >= (a + bs[0] + cs[0]):
        break
    for b in bs:
        if minlist >= (a + b + cs[0]):
            break
        for c in cs:
            abc = a + b +c
            if minlist >= abc:
                break
            # if i >= k:
            if flag and i >= k:
                list.sort(reverse=True)
                minlist = list[k]
                flag = False

            list.append(abc)
            i += 1
list.sort(reverse=True)
for i in range(k):
    print(list[i])

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:
#n=int(input())
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#import math
#li=input().split()
#S=input()

lis=[]
A=[]
B=[]
C=[]
AB=[]
ABC=[]
lis=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
if len(C)<len(A):
    D=A
    A=C
    C=D
elif len(C)<len(B):
    D=B
    B=C
    C=D

for i in A:
    for j in B:
        AB.append(i+j)
AB.sort(reverse=True)
AB=AB[:lis[3]]
for i in AB:
    for j in C:
        ABC.append(i+j)
ABC.sort(reverse=True)
for i in range(lis[3]):
    print(ABC[i])

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
import heapq
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 j in range(Z):
        for i in range(Y):

            BC[count] = ((B[i] + C[j]))
            count += 1
            #heapq.heappush(BC, -long(B[i] + C[j]))

    BC.sort(reverse = True)

    #T = [0 for i in range(min(K, len(BC)) * K)]
    T=[]
    count = 0
    for i in range(X):
        for j in range(min(K, len(BC))):
            T.append(A[i] + BC[j])
            #T[count] = A[i] + BC[j]
            #count += 1
            #heapq.heappush(T, -(A[i] + BC[j]))
    T.sort(reverse = True)
    for i in range(K):
        #t = -heapq.heappop(T)
        print T[i]

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
import heapq
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 j in range(Z):
        for i in range(Y):

            BC[count] = ((B[i] + C[j]))
            count += 1
            #heapq.heappush(BC, -long(B[i] + C[j]))

    BC.sort(reverse = True)

    #T = [0 for i in range(min(K, len(BC)) * K)]
    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.append(A[i] + BC[j])
            T[count] = A[i] + BC[j]
            count += 1
            #heapq.heappush(T, -(A[i] + BC[j]))
    T.sort(reverse = True)
    for i in range(K):
        #t = -heapq.heappop(T)
        print T[i]

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# なんかおかしい！！
import math
import sys
import itertools
import numpy as np


# なんこか入力
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()
b.sort()
c.sort()
#cake = [[0 for i in range(3)] for j in range(3000)]
#cake[0][0]=x-1
#cake[0][1]=y-1
#cake[0][2]=z-1
#print(a[x-1]+b[y-1]+c[z-1])
#print(a[cake[0][0]],b[cake[0][1]],c[cake[0][2]])
s = [[x-1,y-1,z-1]]
t = [[x-1,y-1,z-1]]
#print(s)

for i in range(0,k):
    ma = 0
    temp = [-1,-1,-1]
    for j in s:
        if ma <= a[j[0]]+b[j[1]]+c[j[2]] :
            temp = j
            ma = a[j[0]]+b[j[1]]+c[j[2]]
#    print(temp)
    print(a[temp[0]]+b[temp[1]]+c[temp[2]])
#    print(a[temp[0]],b[temp[1]],c[temp[2]])
    s.remove(temp)
#    print("s=",s)
#    print("t=",t)
#    print(temp)
    if temp[0] > 0:
        if [temp[0]-1,temp[1],temp[2]] in t:
            pass
        else:
            s.append([temp[0]-1,temp[1],temp[2]])
            t.append([temp[0]-1,temp[1],temp[2]])
    if temp[1] > 0:
        if [temp[0],temp[1]-1,temp[2]] in t:
            pass
        else:
            s.append([temp[0],temp[1]-1,temp[2]])
            t.append([temp[0],temp[1]-1,temp[2]])
    if temp[2] > 0:
        if [temp[0],temp[1],temp[2]-1] in t:
            pass
        else:
            s.append([temp[0],temp[1],temp[2]-1])
            t.append([temp[0],temp[1],temp[2]-1])

Submission status: Time Limit Exceeded

Solution code:
#n=int(input())
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#import math
#li=input().split()
#S=input()

lis=[]
A=[]
B=[]
C=[]
AB=[]
ABC=[]
lis=list(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 A:
    for j in B:
        AB.append(i+j)
AB.sort()
AB=AB[-lis[3]:]
for i in AB:
    for j in C:
        ABC.append(i+j)
ABC.sort()
for i in range(lis[3]):
    print(ABC[-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()))

r=[]
out=[]

for i in range(X):
    for j in range(Y):
        r.append(A[i]+B[j])

r.sort(reverse=True)

if len(r)>K:
    for i in range(K):
        for j in range(Z):
            out.append(r[i]+C[j])
else:
    for i in range(len(r)):
        for j in range(Z):
            out.append(r[i]+C[j])

out.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
import heapq
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 j in range(Z):
        for i in range(Y):

            BC[count] = ((B[i] + C[j]))
            count += 1
            #heapq.heappush(BC, -long(B[i] + C[j]))

    A.sort(reverse = True)
    BC.sort(reverse = True)

    #T = [0 for i in range(min(K, len(BC)) * K)]
    T=[]
    count = 0
    for i in range(X):
        for j in range(min(K, len(BC))):
            T.append(A[i] + BC[j])
            #T[count] = A[i] + BC[j]
            #count += 1
            #heapq.heappush(T, -(A[i] + BC[j]))
    T.sort(reverse = True)
    for i in range(K):
        #t = -heapq.heappop(T)
        print T[i]

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int, input().split())
cs = list(map(int, input().split()))
bs = list(map(int, input().split()))
a_s = list(map(int, input().split()))
a_s.sort(reverse=True)
bs.sort(reverse=True)
cs.sort(reverse=True)

list = []
i = -1
# flag = True
minlist = 0
for a in a_s:
    if minlist >= (a + bs[0] + cs[0]):
        break
    for b in bs:
        if minlist >= (a + b + cs[0]):
            break
        for c in cs:
            abc = a + b +c
            if minlist >= abc:
                break
            if i >= k:
            # if flag and i >= k:
                list.sort(reverse=True)
                minlist = list[k]
                # flag = False

            list.append(abc)
            i += 1
list.sort(reverse=True)
for i in range(k):
    print(list[i])

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
import heapq
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
            #heapq.heappush(BC, -long(B[i] + C[j]))

    A.sort(reverse = True)
    BC.sort(reverse = True)

    #T = [0 for i in range(min(K, len(BC)) * K)]
    T=[]
    count = 0
    for i in range(X):
        for j in range(min(K, len(BC))):
            T.append(A[i] + BC[j])
            #T[count] = A[i] + BC[j]
            #count += 1
            #heapq.heappush(T, -(A[i] + BC[j]))
    T.sort(reverse = True)
    for i in range(K):
        #t = -heapq.heappop(T)
        print T[i]

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# なんかおかしい！！
import math
import sys
import itertools
import numpy as np


# なんこか入力
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()
b.sort()
c.sort()
#cake = [[0 for i in range(3)] for j in range(3000)]
#cake[0][0]=x-1
#cake[0][1]=y-1
#cake[0][2]=z-1
#print(a[x-1]+b[y-1]+c[z-1])
#print(a[cake[0][0]],b[cake[0][1]],c[cake[0][2]])
s = [[x-1,y-1,z-1]]
t = [[x-1,y-1,z-1]]
#print(s)

for i in range(0,k):
    ma = 0
    temp = [-1,-1,-1]
    for j in s:
        if ma <= a[j[0]]+b[j[1]]+c[j[2]] :
            temp = j
            ma = a[j[0]]+b[j[1]]+c[j[2]]
#    print(temp)
    print(a[temp[0]]+b[temp[1]]+c[temp[2]])
#    print(a[temp[0]],b[temp[1]],c[temp[2]])
    s.remove(temp)
#    print("s=",s)
#    print("t=",t)
#    print(temp)
    f = 0
    if temp[0] > 0:
        for j in t:
            if temp[0]-1 == j[0] and temp[1]== j[1] and temp[2]==j[2]:
                f=1
                break
        if f==0:
            s.append([temp[0]-1,temp[1],temp[2]])
            t.append([temp[0]-1,temp[1],temp[2]])
    f = 0
    if temp[1] > 0:
        for j in t:
            if temp[0] == j[0] and temp[1]-1== j[1] and temp[2]==j[2]:
                f=1
                break
        if f==0:
            s.append([temp[0],temp[1]-1,temp[2]])
            t.append([temp[0],temp[1]-1,temp[2]])
    f = 0
    if temp[2] > 0:
        for j in t:
            if temp[0] == j[0] and temp[1]== j[1] and temp[2]-1==j[2]:
                f=1
                break
        if f==0:
            s.append([temp[0],temp[1],temp[2]-1])
            t.append([temp[0],temp[1],temp[2]-1])

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
import heapq
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(X):
        for j in range(Z):
            BC[count] = ((B[i] + C[j]))
            count += 1
            #heapq.heappush(BC, -long(B[i] + C[j]))

    A.sort(reverse = True)
    BC.sort(reverse = True)

    #T = [0 for i in range(min(K, len(BC)) * K)]
    T=[]
    count = 0
    for i in range(X):
        for j in range(min(K, len(BC))):
            T.append(A[i] + BC[j])
            #T[count] = A[i] + BC[j]
            #count += 1
            #heapq.heappush(T, -(A[i] + BC[j]))
    T.sort(reverse = True)
    for i in range(K):
        #t = -heapq.heappop(T)
        print T[i]

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k = map(int,input().split())
A = list(map(int , input().split()))
B = list(map(int , input().split()))
C = list(map(int , input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True) 
AB = []
ABC = []
for i in A:
        for j in B:
                AB.append(i+j)
AB.sort(reverse = True)
AB = AB[:min(3001,x*y*z+1)]
for i in AB:
        for j in C:
                ABC.append(i+j)
ABC.sort(reverse = True)
for i in range(k):
        print(ABC[i])

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
import heapq
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(X):
        for j in range(Z):
            BC[count] = ((B[i] + C[j]))
            count += 1
            #heapq.heappush(BC, -long(B[i] + C[j]))

    A.sort(reverse = True)
    BC.sort(reverse = True)

    #T = [0 for i in range(min(K, len(BC)) * K)]
    T=[]
    count = 0
    for j in range(min(K, len(BC))):
        for i in range(X):
            T.append(A[i] + BC[j])
            #T[count] = A[i] + BC[j]
            #count += 1
            #heapq.heappush(T, -(A[i] + BC[j]))
    T.sort(reverse = True)
    for i in range(K):
        #t = -heapq.heappop(T)
        print T[i]

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
la = len(A)
lb = len(B)
lc = len(C)
AB = [0 for _ in range(la*lb)]
for i in range(la):
    for j in range(lb):
        AB[i*lb+j] = A[i] + B[j]
AB = sorted(AB, reverse=True)[:K]
lab = len(AB)
ABC = [0 for _ in range(lab*lc)]
for i in range(lab):
    for j in range(lc):
        ABC[i*lc+j] = AB[i] + C[j]
ABC = sorted(ABC, 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())
cs = list(map(int, input().split()))
bs = list(map(int, input().split()))
a_s = list(map(int, input().split()))
a_s.sort(reverse=True)
bs.sort(reverse=True)
cs.sort(reverse=True)

list = []
i = -1
# flag = True
minlist = 0
for a in a_s:
    if minlist >= (a + bs[0] + cs[0]):
        break
    for b in bs:
        if minlist >= (a + b + cs[0]):
            break
        for c in cs:
            abc = a + b +c
            if i >= k:
            # if flag and i >= k:
                list.sort(reverse=True)
                minlist = list[k]
                # flag = False
            if minlist >= abc:
                break
            list.append(abc)
            i += 1
list.sort(reverse=True)
for i in range(k):
    print(list[i])

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

X, Y, Z, K = MAP()
A = LIST()
B = LIST()
C = LIST()

A=sorted(A)[::-1]
B=sorted(B)[::-1]
C=sorted(C)[::-1]

D = []
#解法1
for i in range(len(A)):
	for j in range(len(B)):
		D.append(A[i]+B[j])
D.sort(reverse=True)
ans = []
for i in range(len(C)):
	for j in range(len(D[0:K])):
		ans.append(C[i]+D[j])
ans.sort(reverse=True)
for i in ans[0:K]:
	print(i)

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):
		if (a+b)>K: break
		AB.append(A[a]+B[b])

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

ABC=[]
for ab in range(len(AB)):
	if ab>K: break
	for c in range(Z):
		if (ab+c)>K: break
		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 = list(map(int , input().split()))
B = list(map(int , input().split()))
C = list(map(int , input().split()))
A = sorted(A,reverse = True)
B = sorted(B,reverse = True)
C = sorted(C,reverse = True)
AB = []
ABC = []
for i in A:
        for j in B:
                AB.append(i+j)
AB.sort(reverse = True)
AB = AB[:min(3001,x*y*z+1)]
for i in AB:
        for j in C:
                ABC.append(i+j)
ABC.sort(reverse = True)
for i in range(k):
        print(ABC[i])

Submission status: Time Limit Exceeded

Solution code:
#n=int(input())
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#import math
#li=input().split()
#S=input()

lis=[]
A=[]
B=[]
C=[]
AB=[]
ABC=[]
lis=list(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 A:
    for j in B:
        AB.append(i+j)
AB.sort(reverse=True)
AB=AB[:lis[3]]
for i in AB:
    for j in C:
        ABC.append(i+j)
ABC.sort(reverse=True)
for i in range(lis[3]):
    print(ABC[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()))


import itertools
val_list = []


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

#print(A_list)
#print(B_list)
#print(C_list)

for a in range(len(A_list)):
    if a + 1 > K:
        break
    for b in range(len(B_list)):
        if b + 1 > K:
            break
        if (a+1) * (b+1) > K:
            continue
            
        for c in range(len(C_list)):
            if c + 1 > K:
                break
            if (a+1) * (b+1) * (c+1) > K:
                continue
        
            val_list.append(A_list[a] + B_list[b] + C_list[c])

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

Submission status: Time Limit Exceeded

Solution code:
def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int,ss_raw()))

X,Y,Z,K = ints_raw()

A = ints_raw()
B= ints_raw()
C= ints_raw()
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
def main():
    D = []
    for a in A:
        for b in B:
            D.append(a+b)
    D.sort(reverse=True)
    D = D[:K]
    E =[]
    for d in D:
        for c in C:
            E.append(d+c)
    E.sort(reverse=True)
    for e in E[:K]:
        print (e)

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

out=[]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)


for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if i*j*k<=k:
                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:
import sys
from collections import deque
import heapq
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] = (long(B[i] + C[j]))
            count += 1
            #heapq.heappush(BC, -long(B[i] + C[j]))

    A.sort(reverse = True)
    BC.sort(reverse = True)

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

if __name__ == '__main__':
    main()