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: Wrong Answer

Solution code:
xyzk = list(map(int, input().split()))
x = xyzk[0]
y = xyzk[1]
z = xyzk[2]
k = xyzk[3]

a = list(map(int, input().split()))
a.sort(reverse=True)
b = list(map(int, input().split()))
b.sort(reverse=True)
c = list(map(int, input().split()))
c.sort(reverse=True)

queue = []

queue.append([a[0] + b[0] + c[0], 0, 0, 0])
for i in range(k):
    print(max(queue)[0])
    aa = max(queue)[1]
    bb = max(queue)[2]
    cc = max(queue)[3]
    queue.remove(max(queue))
    FlagA = False
    FlagB = False
    FlagC = False
    for j in range(len(queue)):
        if queue[j][1] == aa + 1 and queue[j][2] == bb and queue[j][3] == cc:
            FlagA = True
        elif queue[j][1] == aa and queue[j][2] == bb + 1 and queue[j][3] == cc:
            FlagB = True
        elif queue[j][1] == aa and queue[j][2] == bb and queue[j][3] == cc + 1:
            FlagC = True

    if not FlagA and len(a) > aa + 1:
        queue.append([a[aa + 1] + b[bb] + c[cc], aa + 1, bb, cc])
    if not FlagB and len(b) > bb + 1:
        queue.append([a[aa] + b[bb + 1] + c[cc], aa, bb + 1, cc])
    if not FlagC and len(c) > cc + 1:
        queue.append([a[aa] + b[bb] + c[cc + 1], aa, bb, cc + 1])

Submission status: Wrong Answer

Solution code:
from heapq import *

Q=[]
teast=[]
X,Y,Z,K=list(map(int,input().split(" ")))

for i in range(3):
    teast.append(list(map(int,input().split(" "))))

A=sorted(teast[0],reverse=True)
B=sorted(teast[1],reverse=True)
C=sorted(teast[2],reverse=True)

arg_hash={}
heappush(Q,(-A[0]-B[0]-C[0],0,0,0))
arg_hash[(0,0,0)]=1

for k in range(K):
    print(Q)
    ans=heappop(Q)
    a,b,c=ans[1:]
    print(-ans[0])
    argA=(a+1,b,c)
    if a <X-1 and( not argA in arg_hash):
        arg_hash[argA]=1
        heappush(Q,(-A[a+1]-B[b]-C[c],)+argA)
    argB=(a,b+1,c)
    if b <Y-1 and( not argB in arg_hash):
        arg_hash[argB]=1
        heappush(Q,(-A[a]-B[b+1]-C[c],)+argB)
    argC=(a,b,c+1)
    if c <Z-1 and( not argC in arg_hash):
        arg_hash[argC]=1
        heappush(Q,(-A[a]-B[b]-C[c+1],)+argC)

Submission status: Wrong Answer

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

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

ABC = []
for x, a in enumerate(A):
    if x+1 >= 3000:
        break
        
    for y, b in enumerate(B):
        if (x+1)*(y+1) >= 3000:
            break
    
        for z, c in enumerate(C):
            if (x+1)*(y+1)*(z+1) >= 3000:
                break
            
            ABC.append(a+b+c)
            
ABC.sort(reverse=True)
ABC = ABC[:k]

for abc in ABC:
    print(abc)

Submission status: Wrong Answer

Solution code:
import itertools

X, Y, Z, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
 
list_ = [b+c for (b,c) in itertools.product(B, C)]
list_.sort(reverse=True)
 
list__ = [ab+c for (ab,c) in itertools.product(list_[:1000], A)]
list__.sort(reverse=True)
for N in list__[:K]:
  print(N)

Submission status: Wrong Answer

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

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

ABC = []
for i, a in enumerate(A):
    if i+1 >= 3000:
        break
        
    for j, b in enumerate(B):
        if (i+1)*(j+1) >= 3000:
            break
    
        for k, c in enumerate(C):
            if (i+1)*(j+1)*(k+1) >= 3000:
                break
            
            ABC.append(a+b+c)
            
ABC.sort(reverse=True)
ABC = ABC[:k]

for abc in ABC:
    print(abc)

Submission status: Wrong Answer

Solution code:
import math
import random as rd
import numpy as np

x,y,z,k=map(int,input().split( ))
Aline=list(map(int,input().split( )))
Bline=list(map(int,input().split( )))
Cline=list(map(int,input().split( )))
Aline.sort(reverse=True)
Bline.sort(reverse=True)
Cline.sort(reverse=True)

M=Aline[0]+Bline[0]+Cline[0]
queue=[(M,0,0,0)]

for i in range(k):
    queue.sort(reverse=True)
    if not queue:
        break
    (M,a,b,c)=queue.pop(0)
    print(M)
    if a+1<=x-1:
        s=Aline[a+1]+Bline[b]+Cline[c]
        if (s,a+1,b,c) not in queue:
            queue.append((s,a+1,b,c))
    if b+1<=y-1:
        t=Aline[a]+Bline[b+1]+Cline[c]
        if (t,a,b+1,c) not in queue:
            queue.append((t,a,b+1,c))
    if c+1<=z-1:
        u=Aline[a]+Bline[b]+Cline[c+1]
        if (u,a,b,c+1) not in queue:
            queue.append((u,a,b,c+1))

Submission status: Wrong Answer

Solution code:
import itertools

X, Y, Z, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
A.sort(reverse=True)
B = [int(x) for x in input().split()]
B.sort(reverse=True)
C = [int(x) for x in input().split()]
C.sort(reverse=True)
 
list_ = [b+c for (b,c) in itertools.product(B, C)]
list_.sort(reverse=True)
 
list__ = [ab+c for (ab,c) in itertools.product(list_[:K], A)]
list_.sort(reverse=True)
for N in list__[:K]:
  print(N)

Submission status: Wrong Answer

Solution code:
xyzk = list(map(int, input().split()))
x = xyzk[0]
y = xyzk[1]
z = xyzk[2]
k = xyzk[3]

a = list(map(int, input().split()))
a.sort(reverse=True)
a = a[0:min(k, len(a))]
b = list(map(int, input().split()))
b.sort(reverse=True)
b = b[0:min(k, len(b))]
c = list(map(int, input().split()))
c.sort(reverse=True)
c = c[0:min(k, len(c))]

queue = []

queue.append([a[0] + b[0] + c[0], 0, 0, 0])
for i in range(k):
    print(max(queue)[0])
    aa = max(queue)[1]
    bb = max(queue)[2]
    cc = max(queue)[3]
    queue.remove(max(queue))
    FlagA = False
    FlagB = False
    FlagC = False
    for j in range(len(queue)):
        if queue[j][1] == aa + 1 and queue[j][2] == bb and queue[j][3] == cc:
            FlagA = True
        if queue[j][1] == aa and queue[j][2] == bb + 1 and queue[j][3] == cc:
            FlagB = True
        if queue[j][1] == aa and queue[j][2] == bb and queue[j][3] == cc + 1:
            FlagC = True

    if not FlagA and len(a) > aa + 1:
        queue.append([a[aa + 1] + b[bb] + c[cc], aa + 1, bb, cc])
    if not FlagB and len(b) > bb + 1:
        queue.append([a[aa] + b[bb + 1] + c[cc], aa, bb + 1, cc])
    if not FlagC and len(c) > cc + 1:
        queue.append([a[aa] + b[bb] + c[cc + 1], aa, bb, cc + 1])

Submission status: Wrong Answer

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

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

ABC = []
for i, a in enumerate(A):
    if i+1 > 3000:
        break
        
    for j, b in enumerate(B):
        if (i+1)*(j+1) > 3000:
            break
    
        for k, c in enumerate(C):
            if (i+1)*(j+1)*(k+1) > 3000:
                break
            
            ABC.append(a+b+c)
            
ABC.sort(reverse=True)
ABC = ABC[:3000]
for abc in ABC:
    print(abc)

Submission status: Wrong Answer

Solution code:
import math
import random as rd
import numpy as np

x,y,z,k=map(int,input().split( ))
Aline=list(map(int,input().split( )))
Bline=list(map(int,input().split( )))
Cline=list(map(int,input().split( )))
Aline.sort(reverse=True)
Bline.sort(reverse=True)
Cline.sort(reverse=True)

M=Aline[0]+Bline[0]+Cline[0]
queue=[(M,0,0,0)]

for i in range(k):
    queue.sort(reverse=True)
    if not queue:
        break
    (M,a,b,c)=queue.pop(0)
    print(M)
    if a+1<=x-1 and b<=y-1 and c<=z-1:
        s=Aline[a+1]+Bline[b]+Cline[c]
        if (s,a+1,b,c) not in queue:
            queue.append((s,a+1,b,c))
    if a<=x-1 and b+1<=y-1 and c<=z-1:
        t=Aline[a]+Bline[b+1]+Cline[c]
        if (t,a,b+1,c) not in queue:
            queue.append((t,a,b+1,c))
    if a<=x-1 and b<=y-1 and c+1<=z-1:
        u=Aline[a]+Bline[b]+Cline[c+1]
        if (u,a,b,c+1) not in queue:
            queue.append((u,a,b,c+1))

Submission status: Wrong Answer

Solution code:

x,y,z,k=map(int,input().split( ))
Aline=list(map(int,input().split( )))
Bline=list(map(int,input().split( )))
Cline=list(map(int,input().split( )))
Aline.sort(reverse=True)
Bline.sort(reverse=True)
Cline.sort(reverse=True)

M=Aline[0]+Bline[0]+Cline[0]
queue=[(M,0,0,0)]

for i in range(k):
    queue.sort(reverse=True)
    (M,a,b,c)=queue.pop(0)
    print(M)
    if a+1<=x-1 and b<=y-1 and c<=z-1:
        s=Aline[a+1]+Bline[b]+Cline[c]
        if (s,a+1,b,c) not in queue:
            queue.append((s,a+1,b,c))
    if a<=x-1 and b+1<=y-1 and c<=z-1:
        t=Aline[a]+Bline[b+1]+Cline[c]
        if (t,a,b+1,c) not in queue:
            queue.append((t,a,b+1,c))
    if a<=x-1 and b<=y-1 and c+1<=z-1:
        u=Aline[a]+Bline[b]+Cline[c+1]
        if (u,a,b,c+1) not in queue:
            queue.append((u,a,b,c+1))

Submission status: Wrong Answer

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

ab = []
for i in range(X):
    for j in range(Y):
        ab.append(A[i] + B[j])
print(ab)
del ab[K-1:]

Submission status: Wrong Answer

Solution code:
x, y, z, k = list(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()))

ab_li = []
for a in a_li:
    for b in b_li:
        ab_li.append(a+b)
ab_li.sort(reverse=True)
ab_li = ab_li[:3000]

abc_li = []
for ab in ab_li:
    for c in c_li:
        abc_li.append(ab+c)
abc_li.sort(reverse=True)
abc_li = abc_li[:3000]

for ans in abc_li:
    print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop

X, Y, Z, K = [int(a) for a in input().split()]
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
C = [int(a) for a in input().split()]

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

def total(x, y, z):
    return A[x] + B[y] + C[z]

def expand(p, q, r):
    result = []
    if p + 1 < X:
        result.append((p+1, q, r))
    if q + 1 < Y:
        result.append((p, q+1, r))
    if r + 1 < Z:
        result.append((p, q, r+1))
    return result

h = []
ind = None
heappush(h, (-total(0,0,0), (0,0,0)))

for i in range(K):
    val, _ind = heappop(h)
    
    if not _ind == ind:
        ind = _ind
        print(-val)
        for new_ind in expand(*ind):
            new_val = total(*new_ind)
            heappush(h, (-new_val, new_ind))

Submission status: Wrong Answer

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)

while True:
    if len(A) * len(B) * len(C) <= 100000:
        break

    if len(A) == 1:
        if B[-1] == C[-1]:
            B.pop()
            C.pop()
        elif B[-1] < C[-1]:
            B.pop()
        else:
            C.pop()
    elif len(B) == 1:
        if A[-1] == C[-1]:
            A.pop()
            C.pop()
        elif A[-1] < C[-1]:
            A.pop()
        else:
            C.pop()
    elif len(C) == 1:
        if A[-1] == B[-1]:
            A.pop()
            B.pop()
        elif A[-1] <= B[-1]:
            A.pop()
        else:
            B.pop()
    elif A[-1] == B[-1] and A[-1] == C[-1]:
        A.pop()
        B.pop()
        C.pop()
    elif A[-1] < B[-1] and A[-1] < C[-1]:
        A.pop()
    elif B[-1] < A[-1] and B[-1] < C[-1]:
        B.pop()
    else: # C[-1] <= A[-1] and C[-1] <= B[-1]:
        C.pop()

r = []

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

r.sort(reverse=True)

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

Submission status: Wrong Answer

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(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
d = []
e = []
s = 0
for i in range(x):
    for j in range(y):
        d.append(a[i]+b[j])

d.sort(reverse=True)
p = min(k,len(d))

for i in range(p):
    for j in range(z):
        e.append(d[i]+c[j])

e.sort(reverse=True)
print(e)
for i in range(k):
    print(e[i])

Submission status: Wrong Answer

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

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

a_idx = 0
b_idx = 0
c_idx = 0
output = []
output.append((a_idx, b_idx, c_idx))
while len(output) < k:
    current = 0
    cand = (0, 0, 0)
    for tup in output:
        a_idx, b_idx, c_idx = tup
        if a_idx < len(a) - 1:
            if (a_idx + 1, b_idx, c_idx) not in output and current < a[a_idx + 1] + b[b_idx] + c[c_idx]:
                current = a[a_idx + 1] + b[b_idx] + c[c_idx]
                cand = (a_idx + 1, b_idx, c_idx)
        if b_idx < len(b) - 1:
            if (a_idx, b_idx + 1, c_idx) not in output and current < a[a_idx] + b[b_idx + 1] + c[c_idx]:
                current = a[a_idx] + b[b_idx + 1] + c[c_idx]
                cand = (a_idx, b_idx + 1, c_idx)
        if c_idx < len(c) - 1:
            if (a_idx, b_idx, c_idx + 1) not in output and current < a[a_idx] + b[b_idx] + c[c_idx + 1]:
                current = a[a_idx] + b[b_idx] + c[c_idx + 1]
                cand = (a_idx, b_idx, c_idx + 1)
    print(cand)
    output.append(cand)

for tup in output:
    a_idx, b_idx, c_idx = tup
    print(a[a_idx] + b[b_idx] + c[c_idx])

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

res = []
x, y, z, K = na()
a_li = na()
b_li = na()
c_li = na()
list.sort(a_li, reverse=True)
list.sort(b_li, reverse=True)
list.sort(c_li, reverse=True)
for i in range(x):
    for j in range(y):
        for k in range(z):
            if (i + 1) * (j + 1) * (k + 1) <= K:
                res.append(a_li[i] * b_li[j] + c_li[k])
            else:
                break
list.sort(res, reverse=True)
for i in range(K):
    print(res[i])

Submission status: Wrong Answer

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)

while True:
    if len(A) * len(B) * len(C) <= 100000:
        break

    if len(A) == 1:
        if B[-1] <= C[-1]:
            B.pop()
        else:
            C.pop()
    elif len(B) == 1:
        if A[-1] <= C[-1]:
            A.pop()
        else:
            C.pop()
    elif len(C) == 1:
        if A[-1] <= B[-1]:
            A.pop()
        else:
            B.pop()
    elif A[-1] <= B[-1] and A[-1] <= C[-1]:
        A.pop()
    elif B[-1] <= A[-1] and B[-1] <= C[-1]:
        B.pop()
    else: # C[-1] <= A[-1] and C[-1] <= B[-1]:
        C.pop()

r = []

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

r.sort(reverse=True)

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

Submission status: Wrong Answer

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=sorted(s+t for t in B for s in A)[-1:K-1:-1]
print(*sorted(i+x for i in ab for x in C)[-1:K-1:-1],sep="\n")

Submission status: Wrong Answer

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=sorted(s+t for t in B for s in A)[-1:K-1:-1]
print(*sorted(i+x for i in ab for x in C)[::-1][:K],sep="\n")

Submission status: Wrong Answer

Solution code:
import sys,bisect
input = sys.stdin.readline
X,Y,Z,K = map(int,input().split())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))
ABC = [A[0]+B[0]+C[0]]
SumABC = []
i,j,k = 0,0,0
while len(SumABC) < K:
	if i < X-1:
		bisect.insort(ABC,A[i+1]+B[j]+C[k])
	if j < Y-1:
		bisect.insort(ABC,A[i]+B[j+1]+C[k])
	if k < Z-1:
		bisect.insort(ABC,A[i]+B[j]+C[k+1])
	SumABC.append(ABC.pop(0))
	if i < X-2:
		i += 1
	if j < Y-2:
		j += 1
	if k < Z-2:
		k += 1
SumABC.reverse()
for i in SumABC:
	print(i)

Submission status: Wrong Answer

Solution code:
import itertools as it

an, bn, cn, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ab = [ak + bk for ak, bk in it.product(a, b)]
ab.sort(reverse=True)
if len(ab) > k: ab = ab[:k]
abc = [abk + ck for abk, ck in it.product(ab, c)]
abc.sort(reverse=True)
abc = abc[:k]

print(abc, sep="\n")

Submission status: Wrong Answer

Solution code:
xyzk = list(map(int, input().split()))
x = xyzk[0]
y = xyzk[1]
z = xyzk[2]
k = xyzk[3]

a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ablist = []

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

ablist.sort(reverse=True)
ablist = ablist[0:min(k, len(ablist))]
print(ablist)

abclist = []
for i in range(len(ablist)):
    for j in range(len(c)):
        abclist.append(ablist[i] + c[j])

abclist.sort(reverse=True)
abclist = abclist[0:k + 1]

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

Submission status: Wrong Answer

Solution code:
import itertools as it

an, bn, cn, 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)
if la > k: la = la[:k]
if lb > k: lb = lb[:k]
if lc > k: lc = lc[:k]

ab = [ak + bk for ak, bk in it.product(a, b)]
ab.sort(reverse=True)
if len(ab) > k: ab = ab[:k]
abc = [abk + ck for abk, ck in it.product(ab, c)]
abc.sort(reverse=True)
abc = abc[:k]

print(abc, sep="\n")

Submission status: Wrong Answer

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()))
print(*sorted([i+g for i in sorted(s+t for t in B for s in A)[-1:K-1:-1]for g in C])[::-1][:K],sep='\n')

Submission status: Wrong Answer

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)


while True:
    if len(A) * len(B) * len(C) <= 1000000:
        break

    if len(A) == 1:
        if B[-1] <= C[-1]:
            B.pop()
            continue
        else:
            C.pop()
            continue
    if len(B) == 1:
        if A[-1] <= C[-1]:
            A.pop()
            continue
        else:
            C.pop()
            continue
    if len(C) == 1:
        if A[-1] <= B[-1]:
            A.pop()
            continue
        else:
            B.pop()
            continue
    if A[-1] <= B[-1] and A[-1] <= C[-1]:
        A.pop()
        continue
    if B[-1] <= A[-1] and B[-1] <= C[-1]:
        B.pop()
        continue
    if C[-1] <= A[-1] and C[-1] <= B[-1]:
        C.pop()
        continue
    

r = []

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

r.sort(reverse=True)

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

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

res = []
x, y, z, k = na()
a_li = na()
b_li = na()
c_li = na()
list.sort(a_li,reverse=True)
list.sort(b_li,reverse=True)
list.sort(c_li,reverse=True)
for i in range(x):
    for j in range(y):
        for k in range(z):
            if (i + 1) * (j + 1) * (k + 1) <= k:
                res.append(a_li[i] * b_li[j] + c_li[k])
            else:
                break
                
list.sort(res, reverse=True)
for i in range(k):
    print(res[i])

Submission status: Wrong Answer

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)


while True:
    if len(A) * len(B) * len(C) <= 100000:
        break

    if len(A) == 1:
        if B[-1] <= C[-1]:
            B.pop()
            continue
        else:
            C.pop()
            continue
    if len(B) == 1:
        if A[-1] <= C[-1]:
            A.pop()
            continue
        else:
            C.pop()
            continue
    if len(C) == 1:
        if A[-1] <= B[-1]:
            A.pop()
            continue
        else:
            B.pop()
            continue
    if A[-1] <= B[-1] and A[-1] <= C[-1]:
        A.pop()
        continue
    if B[-1] <= A[-1] and B[-1] <= C[-1]:
        B.pop()
        continue
    if C[-1] <= A[-1] and C[-1] <= B[-1]:
        C.pop()
        continue
    

r = []

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

r.sort(reverse=True)

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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()))
lis = []
for x in A:
    ans = x
    for y in B:
        ans += y
        for z in C:
            lis.append(ans+z)    
        ans -= y
#print(lis)
lis.sort()
#print(lis)
for x in lis[:len(lis)-K-1:-1]:
    print(x)

Submission status: Wrong Answer

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

A.sort()
A = A[::-1]
B.sort()
B = B[::-1]
C.sort()
C = C[::-1]

ABC = []

for a in range(len(A)):
    for b in range(len(B)):
        if (a+1)*(b+1) > k:
            break
        for c in range(len(C)):
            if (a+1)*(b+1)*(c+1) > k:
                break
            #print(A[a], B[b], C[c])
            ABC.append(A[a]+B[b]+C[c])

ABC.sort()
ABC = ABC[::-1]

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

AB = []

for a in A:
    for b in B:
        AB.append(a + b)

AB = sorted(AB, reverse=True)

if 3000 < len(AB):
    AB = AB[:3000]

ABC = []
for ab in AB:
    for c in C:
        ABC.append(ab + c)

ABC = sorted(ABC, reverse=True)

ABC = ABC[:K]
ABC = [str(abc) for abc in ABC]

print("\n".join(ABC))

Submission status: Wrong Answer

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)


while True:
    if len(A) * len(B) * len(C) <= 12000:
        break

    if len(A) == 1:
        if B[-1] <= C[-1]:
            B.pop()
            continue
        else:
            C.pop()
            continue
    if len(B) == 1:
        if A[-1] <= C[-1]:
            A.pop()
            continue
        else:
            C.pop()
            continue
    if len(C) == 1:
        if A[-1] <= B[-1]:
            A.pop()
            continue
        else:
            B.pop()
            continue
    if A[-1] <= B[-1] and A[-1] <= C[-1]:
        A.pop()
        continue
    if B[-1] <= A[-1] and B[-1] <= C[-1]:
        B.pop()
        continue
    if C[-1] <= A[-1] and C[-1] <= B[-1]:
        C.pop()
        continue
    

r = []

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

r.sort(reverse=True)

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

Submission status: Wrong Answer

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

li = []
for i in range(X):
    if K < i:
        break
    else:
        for j in range(Y):
            li.append(A[i] + B[j])
C.reverse()
li.reverse()

for i in range(len(li)):
    for j in range(Z):
        print(li[i] + C[j])

Submission status: Wrong Answer

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

for cakes in A, B, C:
    cakes.sort(reverse=True)

cake_values = []
for i in range(len(A)):
    if i + 1 > K:
        break
    for j in range(len(B)):
        if (i + 1) * (j + 1) > K:
            break
        for k in range(len(C)):
            if (i + 1) * (j + 1) * (k + 1) > K:
                break
            cake_values.append(A[i] + B[j] + C[k])
cake_values.sort(reverse=True)
print(cake_values[:K])

Submission status: Wrong Answer

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)


while True:
    if len(A) * len(B) * len(C) <= K * 2:
        break

    if len(A) == 1:
        if B[-1] <= C[-1]:
            B.pop()
            continue
        else:
            C.pop()
            continue
    if len(B) == 1:
        if A[-1] <= C[-1]:
            A.pop()
            continue
        else:
            C.pop()
            continue
    if len(C) == 1:
        if A[-1] <= B[-1]:
            A.pop()
            continue
        else:
            B.pop()
            continue
    if A[-1] <= B[-1] and A[-1] <= C[-1]:
        A.pop()
        continue
    if B[-1] <= A[-1] and B[-1] <= C[-1]:
        B.pop()
        continue
    if C[-1] <= A[-1] and C[-1] <= B[-1]:
        C.pop()
        continue
    

r = []

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

r.sort(reverse=True)

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

Submission status: Wrong Answer

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]]
#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)
#    print(temp)
    f = 0
    if temp[0] > 0:
        for j in s:
            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]])
    f = 0
    if temp[1] > 0:
        for j in s:
            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]])
    f = 0
    if temp[2] > 0:
        for j in s:
            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])