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: Runtime Error

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)
AnsList =[]
for h in range(K):
    for i in range(K):
        for j in range(K):
            ans = A[h] + B[i] + C[j]
            AnsList += ans
            if len(AnsList) == K:
                break
AnsList.sort(reverse = True)
for i in range(K):
    print(AnsList[i])

Submission status: Runtime Error

Solution code:
X, Y, Z, K = map(int, input.().split())
A = list(map(int, sinput().split()))
B = list(map(int, sinput().split()))
C = list(map(int, sinput().split()))
A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
AnsList =[]
for h in range(K):
    for i in range(K):
        for j in range(K):
            ans = A[h] + B[i] + C[j]
            AnsList += ans
AnsList.sort(reverse = True)
for i in range(K):
    print(AnsList[i])

Submission status: Runtime Error

Solution code:
X, Y, Z, K = map(int, input.().split())
A = list(map(int, sinput().split()))
B = list(map(int, sinput().split()))
C = list(map(int, sinput().split()))
A.sort()
B.sort()
C.sort()
AnsList =[]
for h in range(K):
    for i in range(K):
        for j in range(K):
            ans = A[h] + B[i] + C[j]
            AnsList += ans
for i in range(K):
    print(AnsList[i])

Submission status: Runtime Error

Solution code:
X, Y, Z, K = map(int, input.().split())
A = list(map(int, sinput().split()))
B = list(map(int, sinput().split()))
C = list(map(int, sinput().split()))
A.sort()
B.sort()
C.sort()
AnsList =[]
for h in range(K):
    for i in range(K):
        for j in range(K):
            ans = A[h] + B[i] + C[j]
            AnsList += ans
            if len(AnsList) >= K:
                break
for i in range(K):
    print(AnsList[i])

Submission status: Runtime Error

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

for i in a:
	for l in b:
		ab_sum.append(a[i]+b[l])
		
ab_sum.sort()
c.sort()
ans = []
for i in range(min(k,len(ab_sum))):
	for l in range(min(k,len(c))):
		ans.append(ab_sum[i]+c[l])
		
ans.sort()

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

Submission status: Runtime Error

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

for i in len(a):
	for l in len(b):
		ab_sum.append(a[i]+b[l])
		
ab_sum.sort()
c.sort()
ans = []
for i in range(min(k,len(ab_sum))):
	for l in range(min(k,len(c))):
		ans.append(ab_sum[i]+c[l])
		
ans.sort()

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

Submission status: Runtime Error

Solution code:
import heapq

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

h = []

heapq.heappush(h, (A[0]+B[0]+C[0], 0,0,0))

result = []
used = set()

for _ in range(K):
    value, i,j,k = heapq.heappop(h)
    result.append(value)
    if i < X-1 and (i+1,j,k) not in used:
        heapq.heappush(h, (A[i+1]+B[j]+C[k],i,j,k))
		used.add((i+1,j,k))
    if j < Y-1 and (i,j+1,k) not in used:
        heapq.heappush(h, (A[i]+B[j+1]+C[k],i,j+1,k))
		used.add((i,j+1,k))
    if k < Z-1 and (i,j,k+1) not in used:
        heapq.heappush(h, (A[i]+B[j]+C[k+1],i,j,k+1))
		used.add((i,j,k+1))
        
for v in result:
    print(v)

Submission status: Runtime Error

Solution code:
import heapq

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

h = []

heapq.heappush(h, (A[0]+B[0]+C[0], 0,0,0))

result = []

for _ in range(K):
	value, i,j,k = heapq.heappop(h)
    result.append(value)
    if i < X-1:
    	heapq.heappush(h, (A[i+1]+B[j]+C[k],i,j,k))
    if j < Y-1 and i == 0:
      	heapq.heappush(h, (A[i]+B[j+1]+C[k],i,j+1,k))
    if k < Z-1 and i == 0 and j == 0:
      	heapq.heappush(h, (A[i]+B[j]+C[k+1],i,j,k+1))
        
for v in result:
	print(v)

Submission status: Runtime Error

Solution code:
import heapq

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

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

h = []

heapq.heappush(h, (A[0]+B[0]+C[0], 0,0,0))

result = []

for _ in range(K):
	value, i,j,k = heapq.heappop(h)
    result.append(value)
    if i < X-1:
    	heapq.heappush(h, (A[i+1]+B[j]+C[k],i,j,k))
    if j < Y-1 and i == 0:
      	heapq.heappush(h, (A[i]+B[j+1]+C[k],i,j+1,k))
    if k < Z-1 and i == 0 and j == 0:
      	heapq.heappush(h, (A[i]+B[j]+C[k+1],i,j,k+1))
        
for v in result:
	print(v)

Submission status: Runtime Error

Solution code:
import heapq

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

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

h = []

heapq.heappush(h, (A[0]+B[0]+C[0], 0,0,0))

result = []

for _ in range(K):
	value, i,j,k = h.heappop()
    result.append(value)
    if i < X-1:
    	heapq.heappush(h, (A[i+1]+B[j]+C[k],i,j,k))
    if j < Y-1 and i == 0:
      	heapq.heappush(h, (A[i]+B[j+1]+C[k],i,j+1,k))
    if k < Z-1 and i == 0 and j == 0:
      	heapq.heappush(h, (A[i]+B[j]+C[k+1],i,j,k+1))
        
for v in result:
	print(v)

Submission status: Runtime Error

Solution code:
import heapq

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

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

h = []

h.heappush((A[0]+B[0]+C[0], 0,0,0))

result = []

for _ in range(K):
	value, i,j,k = h.heappop()
    result.append(value)
    if i < X-1:
    	h.heappush((A[i+1]+B[j]+C[k],i,j,k))
    if j < Y-1 and i == 0:
      	h.heappush((A[i]+B[j+1]+C[k],i,j+1,k))
    if k < Z-1 and i == 0 and j == 0:
      	h.heappush((A[i]+B[j]+C[k+1],i,j,k+1))
        
for v in result:
	print(v)

Submission status: Runtime Error

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


AB = [x+y for x,y in itertools.product(A,B)]
AB.sort(reverse = True)
AB = AB[:3000]

ABC = [x+y for x,y in itertools.product(AB,C)]
ABC.sort(reverse=True)

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

Submission status: Runtime Error

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

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

l = []

for p in range(0,x):
    for q in range(0,y):
        for r in range(0,z):
            if a[p]+b[q]+c[r] <= l[0]:
                break
            elif len(l) > k:
                heapq.heappushpop(l,a[p]+b[q]+c[r])
            else:
                heapq.heappush(l,a[p]+b[q]+c[r])

l.sort()

for i in range(1,k+1):
    print(l[-i])

Submission status: Runtime Error

Solution code:
x,y,z,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
a.insert(0,100000000000)
b.insert(0,100000000000)
c.insert(0,100000000000)
x_p = x-1
y_p = y-1
z_p = z-1
ans = []
x_d = a[x_p]-a[x_p-1]
y_d = b[y_p]-b[y_p-1]
z_d = c[z_p]-c[z_p-1]

if i in range(k):
	ans.append(a[x_p]+b[y_p]+c[z_p])
	if x_d > y_d:
		if y_d > z_d:
			z_p -= 1
			z_d = c[z_p]-c[z_p-1]
		else:
			y_p -= 1
			y_d = b[y_p]-b[y_p-1]
	else:
		if x_d > z_d:
			z_p -= 1
			z_d = c[z_p]-c[z_p-1]
		else:
			x_p -= 1
			x_d = a[x_p]-a[x_p-1]

print(ans)

Submission status: Runtime Error

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

sum_list = []
for a_i in range(x):
    for b_i in range(y):
        for c_i in range(z):
            if a_i*b_i*c_i > k:
                continue
            sum_list.append(a[a_i]+b[b_i]+c[c_i])
sum_list.sort(reverse=True)
for i in range(k):
    print(sum_list[i])

Submission status: Runtime Error

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

ab_list = []
for a_i in range(x):
    for b_i in range(y):
        ab_list.append(a[a_i]+b[b_i])
ab_list.sort(reverse=True)
sum_list = []
for ab_i in range(k):
    for c_i in range(z):
        sum_list.append(ab_list[ab_i]+c[c_i])
sum_list.sort(reverse=True)
for i in range(k):
    print(sum_list[i])

Submission status: Runtime Error

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

ab_list = []
for a_i in range(x):
    for b_i in range(y):
        ab_list.append(a[a_i]+b[b_i])
ab_list.sort().reverse()
sum_list = []
for ab_i in range(k):
    for c_i in range(z):
        sum_list.append(ab_list[ab_i]+c[c_i])
sum_list.sort().reverse()
#sum_list = []
#for a_i in range(x):
#    for b_i in range(y):
#        for c_i in range(z):
#            sum_list.append(a[a_i]+b[b_i]+c[c_i])
#sum_list.sort()
for i in range(k):
    print(sum_list[i])

Submission status: Runtime Error

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

ab_list = []
for a_i in range(x):
    for b_i in range(y):
        ab_list.append(a[a_i]+b[b_i])
ab_list.sort()
sum_list = []
for ab_i in range(k):
    for c_i in range(z):
        sum_list.append(ab_list[ab_i]+c[c_i])
sum_list.sort()
#sum_list = []
#for a_i in range(x):
#    for b_i in range(y):
#        for c_i in range(z):
#            sum_list.append(a[a_i]+b[b_i]+c[c_i])
#sum_list.sort()
for i in range(k):
    print(sum_list[i])

Submission status: Runtime Error

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

sum_list = []
for a_i in range(x):
    for b_i in range(y):
        for c_i in range(z):
            sum_list.append(a[a_i]+b[b_i]+c[c_i])
sum_list.sort
for i in range(k):
    print(sum_list(i))

Submission status: Runtime Error

Solution code:
_=input()
A=map(lambda x:("A", int(x)), input())
B=map(lambda x:("B", int(x)), input())
C=map(lambda x:("C", int(x)), input())
S = sorted(A, cmp=lambda x, y:-x[1] + y[1])

A=None
B=None
C=None
for i in len(S):
  if A==None and x[0]=="A":
    A=i
  elif B==None and x[0]=="B":
    B=i
  elif C==None and x[0]=="C":
  	C=i

for i in [A, B, C].sort()[::-1]:
  del S[i]

print(S)

Submission status: Runtime Error

Solution code:
x,y,z,K = map(int,input().split())
abc = [sorted(list(map(int,input().split())), reverse=True) for i in range(3)]

ans=[]
ab=[]

for i in range(x):
    for j in range(y):
        if (i+1)*(j+1) <= K:
            ab.append(abc[0][i]+abc[1][j])

ab.sort(reverse=True)

for i in range(ab):
    for j in range(z):
        if (i+1)*(j+1) <= K:
            ans.append(ab[i]+abc[2][j])
    
ans.sort(reverse=True)

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

Submission status: Runtime Error

Solution code:
x,y,z,K = map(int,input().split())
abc = [sorted(list(map(int,input().split())), reverse=True) for i in range(3)]

ans=[]
ab=[]

for i in range(x):
    for j in range(y):
        if (i+1)*(j+1) <= K:
            ab.append(abc[0][i]+abc[1][j])

ab.sort(reverse=True)

for i in range(K):
    for j in range(z):
        if (i+1)*(j+1) <= K:
            ans.append(ab[i]+abc[2][j])
    
ans.sort(reverse=True)

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

Submission status: Runtime Error

Solution code:
x,y,z,K = map(int,input().split())
abc = [sorted(list(map(int,input().split())), reverse=True) for i in range(3)]

ans=[]
ab=[]

for i in range(x):
    for j in range(y):
        if (i+1)*(j+1) <= K:
            ab.append(abc[0][i]+abc[1][j])

ab.sort(reverse=True)

for i in range(K):
    for j in range(z):
        if (i+1)*(j+1)> <= K:
            ans.append(ab[i]+abc[2][j])
    
ans.sort(reverse=True)

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

Submission status: Runtime Error

Solution code:
x,y,z,k=map(int, input().split())#=3,3,3,5
a=list(map(int, input().split()))#=[1,10,100]#
b=list(map(int, input().split()))#=[2,20,200]#
c=list(map(int, input().split()))#=[1,10,100]
a=sorted(a)[::-1]
b=sorted(b)[::-1]
c=sorted(c)[::-1]
que=[(a[0]+b[0]+c[0],0,0,0)]
ans=[]
while True:
    que.sort(key=lambda x:x[0])
    max_item=que.pop()
    ans.append(max_item[0])
    if len(ans)==k+5:
        break
    else:
        if max_item[1]+1<len(a):
            add=(a[max_item[1]+1]+b[max_item[2]]+c[max_item[3]],max_item[1]+1,max_item[2],max_item[3])
            if add not in que:
                que.append(add)
        if max_item[2]+1<len(b):
            add = (a[max_item[1]]+b[max_item[2]+1]+c[max_item[3]],max_item[1],max_item[2]+1,max_item[3])
            if add not in que:
                que.append(add)
        if max_item[3]+1<len(c):
            add = (a[max_item[1]]+b[max_item[2]]+c[max_item[3]+1],max_item[1],max_item[2],max_item[3]+1)
            if add not in que:
                que.append(add)
ans=sorted(ans)[::-1]
for i in range(k):
    print(ans[i])

Submission status: Runtime Error

Solution code:
x,y,z,k=map(int, input().split())#=3,3,3,5
a=list(map(int, input().split()))#=[1,10,100]#
b=list(map(int, input().split()))#=[2,20,200]#
c=list(map(int, input().split()))#=[1,10,100]
a=sorted(a)[::-1]
b=sorted(b)[::-1]
c=sorted(c)[::-1]
que=[(a[0]+b[0]+c[0],0,0,0)]
ans=[]
while True:
    que.sort(key=lambda x:x[0])
    max_item=que.pop()
    ans.append(max_item[0])
    if len(ans)==k:
        break
    else:
        if max_item[1]+1<len(a):
            add=(a[max_item[1]+1]+b[max_item[2]]+c[max_item[3]],max_item[1]+1,max_item[2],max_item[3])
            if add not in que:
                que.append(add)
        if max_item[2]+1<len(b):
            add = (a[max_item[1]]+b[max_item[2]+1]+c[max_item[3]],max_item[1],max_item[2]+1,max_item[3])
            if add not in que:
                que.append(add)
        if max_item[3]+1<len(c):
            add = (a[max_item[1]]+b[max_item[2]]+c[max_item[3]+1],max_item[1],max_item[2],max_item[3]+1)
            if add not in que:
                que.append(add)
p_que(que)
for i in range(k):
    print(ans[i])

Submission status: Runtime Error

Solution code:
x,y,z,k=map(int, input().split())#=3,3,3,5
a=list(map(int, input().split()))#=[1,10,100]#
b=list(map(int, input().split()))#=[2,20,200]#
c=list(map(int, input().split()))#=[1,10,100]
a=sorted(a)[::-1]
b=sorted(b)[::-1]
c=sorted(c)[::-1]
que=[(a[0]+b[0]+c[0],0,0,0)]
ans=[]
def p_que(que):
    que.sort(key=lambda x:x[0])
    max_item=que.pop()
    ans.append(max_item[0])
    if len(ans)==k:
        return 0
    else:
        if max_item[1]+1<len(a):
            add=(a[max_item[1]+1]+b[max_item[2]]+c[max_item[3]],max_item[1]+1,max_item[2],max_item[3])
            if add not in que:
                que.append(add)
        if max_item[2]+1<len(b):
            add = (a[max_item[1]]+b[max_item[2]+1]+c[max_item[3]],max_item[1],max_item[2]+1,max_item[3])
            if add not in que:
                que.append(add)
        if max_item[3]+1<len(c):
            add = (a[max_item[1]]+b[max_item[2]]+c[max_item[3]+1],max_item[1],max_item[2],max_item[3]+1)
            if add not in que:
                que.append(add)
        p_que(que)
p_que(que)
for i in range(k):
    print(ans[i])

Submission status: Runtime Error

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 = []
for i,j in itertools.product(A,B):
	ab.append(i+j)
ab_K = sorted(ab)[-K:]

abc = []
for i,j in itertools.product(ab_k,C):
	abc.append(i+j)
abc_k = sorted(abc,reverse=True)

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

Submission status: Runtime Error

Solution code:
x,y,z,k=map(int, input().split())#=3,3,3,5
a=list(map(int, input().split()))#=[1,10,100]#
b=list(map(int, input().split()))#=[2,20,200]#
c=list(map(int, input().split()))#=[1,10,100]
a=sorted(a)[::-1]
b=sorted(b)[::-1]
c=sorted(c)[::-1]
que=[(a[0]+b[0]+c[0],0,0,0)]
ans=[]
def p_que(que):
    que.sort(key=lambda x:x[0])
    max_item=que.pop()
    ans.append(max_item[0])
    if len(ans)==k:
        return 0
    else:
        if max_item[1]+1<len(a):
             add=(a[max_item[1]+1]+b[max_item[2]]+c[max_item[3]],max_item[1]+1,max_item[2],max_item[3])
             if add not in que:
                 que.append(add)
        if max_item[2]+1<len(b):
             add = (a[max_item[1]]+b[max_item[2]+1]+c[max_item[3]],max_item[1],max_item[2]+1,max_item[3])
             if add not in que:
                 que.append(add)
        if max_item[3]+1<len(c):
             add = (a[max_item[1]]+b[max_item[2]]+c[max_item[3]+1],max_item[1],max_item[2],max_item[3]+1)
             if add not in que:
                 que.append(add)
        p_que(que)
p_que(que)
for i in range(k):
    print(ans[i])

Submission status: Runtime Error

Solution code:
import itertools
X,Y,Z,K = 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)
abc = []
count = 0
for l,m,n in itertools.product(A,B,C):
	if count<=K:
		count+=1
		abc.append(l+m+n)
	else:
		break:
for i in range(K):
	print(abc[i])

Submission status: Runtime Error

Solution code:
import itertools
X,Y,Z,K = 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)
abc = []
count = 0
for i,j,k in itertools.product(A,B,C):
	if count<K:
		count+=1
		abc.append(i+j+k)
	else:
		break:
for i in range(K):
	print(abc[i])

Submission status: Runtime Error

Solution code:
import math
xyzk = list(map(int,input().split()))
abc = [list(map(int,input().split())) for a in range(3)]
ab=[]
for a in abc[0]:
    for b in abc[1]:
        ab.append(a+b)
ab.sort()
ab.reverse()
abc[2].sort()
abc[2].reverse()
abc2=[]
for c in range(len(abc[2])):
    for a in range(min([xyzk[3]/(c+1),len(ab)])):
        abc2.append(abc[2][c]+ab[a])
abc2.sort()
abc2.reverse()
for a in range(xyzk[3]):
    print(abc2[a])

Submission status: Runtime Error

Solution code:
import math
xyzk = list(map(int,input().split()))
abc = [list(map(int,input().split())) for a in range(3)]
ab=[]
for a in abc[0]:
    for b in abc[1]:
        ab.append(a+b)
ab.sort()
ab.reverse()
abc[2].sort()
abc[2].reverse()
abc2=[]
for c in range(abc[2]):
    for a in range(min([xyzk[3]/(c+1),len(ab)])):
        abc2.append(abc[2][c]+ab[a])
abc2.sort()
abc2.reverse()
for a in range(xyzk[3]):
    print(abc2[a])

Submission status: Runtime Error

Solution code:
import math
xyzk = list(map(int,input().split()))
abc = [list(map(int,input().split())) for a in range(3)]
ab=[]
for a in abc[0]:
    for b in abc[1]:
        ab.append(a+b)
ab.sort()
ab.reverse()
abc[2].sort()
abc[2].reverse()
abc2=[]
for c in range(abc[2]):
    for a in range(min([xyzk[3]/(c+1),len(ab)])):
        abc2.append(abc[2][b]+ab[a])
abc2.sort()
abc2.reverse()
for a in range(xyzk[3]):
    print(abc2[a])

Submission status: Runtime Error

Solution code:
x,y,z,k=map(int,input().split())
a_li=list(map(int,input().split()))
b_li=list(map(int,input().split()))
c_li=list(map(int,input().split()))
t=[]
for i in range(0,x):
  for j in range(0,y):
    t.append(a_li[i]+b_li[j])
t.sort()
c_li.sort()
li=[]
for k in range(0,k):
  for l in range(0,k):
    li.append(t[k]+c_li[k])
li.sort()
for m in range (0,k):
  print(li[m])

Submission status: Runtime Error

Solution code:
l = []
w = []
x,y,z,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
for i in range(len(a)):
    for j in range(len(b)):
        l.append(a[i]+b[j])
        l = sorted(l)[::-1]
for i in range(k):
    for j in range(len(c)):
        w.append(l[i]+c[j])
        w = sorted(w)[::-1]
for i in range(k):
    print(w[i])

Submission status: Runtime Error

Solution code:
X, Y, Z, K = (int(n) for n in input().split())
nums_x = [int(x) for x in input().split()]
nums_y = [int(y) for y in input().split()]
nums_z = [int(z) for z in input().split()]

nums_x = sorted(nums_x, reverse=True)
nums_y = sorted(nums_y, reverse=True)
nums_z = sorted(nums_z, reverse=True)

ans = []
    
for x in s_x:
  for y in s_y:
    for z in s_z:
      if x * y * z < K:
      	ans.append(z+y+x)
      else:
        break

for v in sorted(ans, reverse=True)[:K]:
  print(v)

Submission status: Runtime Error

Solution code:
X, Y, Z, K = [int(i) for i in input().split()]
A = sorted([int(i) for i in input().split()],reverse=True)
B = sorted([int(i) for i in input().split()],reverse=True)
C = sorted([int(i) for i in input().split()],reverse=True)
def set_tuple(A,B,C,x,y,z):
    return (-(A[x]+B[y]+C[z]),x,y,z)
Q = []
heapq.heappush(Q,set_tuple(A,B,C,0,0,0))
Ans = []
memo = {(0,0,0):True}
for _ in range(K):
    e,x,y,z = heapq.heappop(Q)
    Ans.append(-e)
    if x+1 < X and (x+1,y,z) not in memo:
        heapq.heappush(Q,set_tuple(A,B,C,x+1,y,z))
        memo[(x+1,y,z)] = True
    if y+1 < Y and (x,y+1,z) not in memo:
        heapq.heappush(Q,set_tuple(A,B,C,x,y+1,z))
        memo[(x,y+1,z)] = True
    if z+1 < Z and (x,y,z+1) not in memo:
        heapq.heappush(Q,set_tuple(A,B,C,x,y,z+1))
        memo[(x,y,z+1)] = True
for i in Ans[:K]:print(i)

Submission status: Runtime Error

Solution code:
# TODO D - Cake 123
# https://atcoder.jp/contests/abc123/tasks/abc123_d

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

A = sorted(int(x) for x in raw_input().split(), reverse=True)
B = sorted(int(y) for y in raw_input().split(), reverse=True)
C = sorted(int(z) for z in raw_input().split(), reverse=True)

AB = sorted([a+b for a in A for b in B], reverse=True)
ABC = sorted([ab + c for ab in AB[:K] for c in C], reverse=True)

for i in ABC[:K]:
    print '{}'.format(i)

Submission status: Runtime Error

Solution code:
#abc123d
 
x,y,z,k=map(int,raw_input().split())
a=sorted(map(int,raw_input().split()),reverse=True)
b=sorted(map(int,raw_input().split()),reverse=True)
c=sorted(map(int,raw_input().split()),reverse=True)
 
ab=sorted([i+j for i in a for j in b],reverse=True)
res=sorted([ij+l for ij in ab[:k] for l in c],reverse=True)
for i in res[:k]:
 print i

Submission status: Runtime Error

Solution code:
N = list(map(int, input().split()))[-1]
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

first = [i+j for i in A for j in B]
first = sorted(first)[::-1]
second = [i+j for i in first for j in C if i >= first[N]]

print("\n".join([str(value) for value in sorted(second)[::-1][:N]]))

Submission status: Runtime Error

Solution code:
x,y,z,k=map(int,input().split())
a=sorted(list(map(int,input().split())),reverse=True)
b=sorted(list(map(int,input().split())),reverse=True)
c=sorted(list(map(int,input().split())),reverse=True)
d=[0]*(x*y)
e=[0]*(x*y*z)
m,n=0,0

for i in range(x):
  for j in range(y):
    d[m]=a[i]+b[j]
    m += 1

d=sorted(d,reverse=True)
for i in range(x*y):
  for j in range(z):
    e[n]=d[i]+c[j]
    n += 1
    
e=sorted(e,reverse=True)
for i in range(k):
  print(e[i])

Submission status: Runtime Error

Solution code:
def transport(n,a,b,c,d,e):
    s = [a,b,c,d,e]
    x = min(s)
    return 5+int(1/x*(n-1))
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
print(transport(n,a,b,c,d,e))

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int, input().split())

s1=list(map(int, input().split()))
s2=list(map(int, input().split()))
s3=list(map(int, input().split()))

ans1 = sorted(i+j for i in s1 for j in s2)
ans2 = sorted(i+j for i in ans1 for j in s3)
res = sorted(ans2,reverse=True)
print(*res[:k+1], sep="\n")

Submission status: Runtime Error

Solution code:
def cake(s1,s2,s3):
    ans1 = sorted(i+j for i in s1 for j in s2)
    ans2 = sorted(i+j for i in ans1 for j in s3)
    return ans2    
    
a,b,c,d = map(int, input().split())

s1=list(map(int, input().split()))
s2=list(map(int, input().split()))
s3=list(map(int, input().split()))

ans1 = sorted(i+j for i in s1 for j in s2)
ans2 = sorted(i+j for i in ans1 for j in s3)
res = sorted(ans2,reverse=True)
print(*res[:k+1], sep="\n")

Submission status: Runtime Error

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

ab=[]

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

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

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

Submission status: Runtime Error

Solution code:

def solver2(a, b, c, k):
    d = deque()
    n = len(a)
    for p in range(n):
        for q in range(n):
            for r in range(n):
                if (p + 1) * (q + 1) * (r + 1) > k:
                    continue
                d.append(a[-p - 1] + b[-q - 1] + c[-r - 1])
    it = reversed(sorted(d))
    for _ in range(k):
        print(next(it))


if __name__ == "__main__":
    x, y, z, k = list(map(int, input().split(" ")))
    a = sorted(list(map(int, input().split(" "))))
    b = sorted(list(map(int, input().split(" "))))
    c = sorted(list(map(int, input().split(" "))))
    solver2(a, b, c, k)