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:
X,Y,Z,K = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)[:min(X,20)]
b = sorted(list(map(int, input().split())), reverse=True)[:min(Y,20)]
c = sorted(list(map(int, input().split())), reverse=True)[:min(Z,20)]

s = []
for i in range(min(X,20)):
    for j in range(min(Y,20)):
        for k in range(min(Z,20)):
            s.append(a[i]+b[j]+c[k])

s.sort(reverse=True)
for si in s[:K]:
    print(si)

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

X, Y, Z, K = LI()
A = sorted(LI(), reverse=True)
B = sorted(LI(), reverse=True)
C = sorted(LI(), reverse=True)

A = A[:min(250, X)]
B = B[:min(250, Y)]
C = C[:min(250, Z)]
# Aの中で最大の数字足すBの最大、Cの最大は全体の中で最大
# 3000個大きい順に求めれば良い

# iが決まれば、j,kのおおきさは分かる
BC = []
# 1000*1000 で10**6の計算量
for j in range(len(B)):
    for k in range(len(C)):
        BC.append(B[j] + C[k])

points = []
# 10**3 と 10** 6
for i in range(len(A)):
    points += [bc + A[i] for bc in BC]
#  #  for i in range(len(A)):
#  #      for bc in BC:
#  #          points.append(A[i]+bc)
#  #      #  for j in range(len(B)):
#  #      #      for k in range(len(C)):
#  #      #          point = A[i] + B[j] + C[k]
#  #      #          points.append(point)
for i in sorted(points, reverse=True)[:K]:
    print(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()
b.sort()
c.sort()
d = []
for i in range(max(0,len(a)-40), len(a)):
    for j in range(max(0,len(b)-40), len(b)):
        for l in range(max(0,len(c)-40), len(c)):
            d.append(a[i]+b[j]+c[l])
d.sort()
for i in range(1,k+1):
    print(d[-i])

Submission status: Wrong Answer

Solution code:
import sys
from itertools import product

def main():
    input = sys.stdin.readline
    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, key=lambda x: -x) + [0]
    B = sorted(B, key=lambda x: -x) + [0]
    C = sorted(C, key=lambda x: -x) + [0]

    A_ = [A[0]]
    B_ = [B[0]]
    C_ = [C[0]]
    i, j, k = 1, 1, 1
    while (i * j * k) < K:
        a, b, c = A[i], B[j], C[k]

        if a == max(a, b, c):
            A_.append(a)
            i += 1
        if b == max(a, b, c):
            B_.append(b)
            j += 1
        if c == max(a, b, c):
            C_.append(c)
            k += 1

    deli= []
    for a in A_:
        for b in B_:
            for c in C_:
                deli.append(a + b + c)

    deli = sorted(deli, key=lambda x: -x)
    for i in range(K):
        print(deli[i])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

X, Y, Z, K = LI()
A = sorted(LI(), reverse=True)
B = sorted(LI(), reverse=True)
C = sorted(LI(), reverse=True)

A = A[:min(200, X)]
B = B[:min(200, Y)]
C = C[:min(200, Z)]
# Aの中で最大の数字足すBの最大、Cの最大は全体の中で最大
# 3000個大きい順に求めれば良い

# iが決まれば、j,kのおおきさは分かる
BC = []
# 1000*1000 で10**6の計算量
for j in range(len(B)):
    for k in range(len(C)):
        BC.append(B[j] + C[k])

points = []
# 10**3 と 10** 6
for i in range(len(A)):
    points += [bc + A[i] for bc in BC]
#  #  for i in range(len(A)):
#  #      for bc in BC:
#  #          points.append(A[i]+bc)
#  #      #  for j in range(len(B)):
#  #      #      for k in range(len(C)):
#  #      #          point = A[i] + B[j] + C[k]
#  #      #          points.append(point)
for i in sorted(points, reverse=True)[:K]:
    print(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()
b.sort()
c.sort()
d = []
for i in range(max(0,len(a)-15), len(a)):
    for j in range(max(0,len(b)-15), len(b)):
        for l in range(max(0,len(c)-15), len(c)):
            d.append(a[i]+b[j]+c[l])
d.sort()
for i in range(1,k+1):
    print(d[-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()))

res = []
for a in range(min(X, 100)):
    for b in range(min(Y, 100)):
        for c in range(min(Z, 100)):
            res.append(A[-a-1] + B[-b-1] + C[-c-1])
            
res.sort(reverse=True)

i = 0
for r in res:
    print(r)
    i += 1
    if i == K:
        break

Submission status: Wrong Answer

Solution code:
INF = -10**11
x, y, z, k = [int(item) for item in input().split()]
a = sorted([int(item) for item in input().split()], reverse=True) + [INF]
b = sorted([int(item) for item in input().split()], reverse=True) + [INF]
c = sorted([int(item) for item in input().split()], reverse=True) + [INF]

num = x + y + z
ac, bc, cc = 0, 0, 0
ad = a[0] - a[1]
bd = b[0] - b[1]
cd = c[0] - c[1]
kadd = min(k*40, x*y*z)
while (ac+1) * (bc+1) * (cc+1) < kadd:
    if ad <= bd and ad <= cd:
        ac += 1
        ad = a[ac] - a[ac+1]
        while ad == 0:
            ac += 1
            ad = a[ac] - a[ac+1]
    elif bd <= ad and bd <= cd:
        bc += 1
        bd = b[bc] - b[bc+1]
        while bd == 0:
            bc += 1
            bd = b[bc] - b[bc+1]
    elif cd <= ad and cd <= bd:
        cc += 1
        cd = c[cc] - c[cc+1]
        while cd == 0:
            cc += 1
            cd = c[cc] - c[cc+1]

vals = []
for ai in a[:ac+1]:
    for bi in b[:bc+1]:
        for ci in c[:cc+1]:
            vals.append(ai+bi+ci)
vals.sort(reverse=True)
for i in range(k):
    print(vals[i])

Submission status: Wrong Answer

Solution code:
import heapq

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

def diff(l):
    m = max(l)
    return sorted(m - v for v in l)[1:]

s = sum(map(max, [a, b, c]))
sa, sb, sc = map(diff, [a, b, c])
da, db, dc = [0], [0], [0]
q = [0]
heapq.heappush(q, da[0] + db[0] + dc[0])
while k >= 0:
    while True:
        if len(q) == 0 or (len(sa) > 0 and q[0] <= sa[0]):
            for v in [sa[0] + bb + cc for bb in db for cc in dc]:
                heapq.heappush(q, v)
            da.append(sa[0])
            sa = sa[1:]
        elif len(q) == 0 or (len(sb) > 0 and q[0] <= sb[0]):
            for v in [sb[0] + aa + cc for aa in da for cc in dc]:
                heapq.heappush(q, v)
            db.append(sb[0])
            sb = sb[1:]
        elif len(q) == 0 or (len(sc) > 0 and q[0] <= sc[0]):
            for v in [sc[0] + aa + bb for aa in da for bb in db]:
                heapq.heappush(q, v)
            dc.append(sc[0])
            sc = sc[1:]
        else:
            break
    v = heapq.heappop(q)
    print s - v
    k -= 1

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

X, Y, Z, K = LI()
A = sorted(LI(), reverse=True)
B = sorted(LI(), reverse=True)
C = sorted(LI(), reverse=True)

A = A[:min(100, X)]
B = B[:min(100, Y)]
C = C[:min(100, Z)]
# Aの中で最大の数字足すBの最大、Cの最大は全体の中で最大
# 3000個大きい順に求めれば良い

# iが決まれば、j,kのおおきさは分かる
BC = []
# 1000*1000 で10**6の計算量
for j in range(len(B)):
    for k in range(len(C)):
        BC.append(B[j] + C[k])

points = []
# 10**3 と 10** 6
for i in range(len(A)):
    points += [bc + A[i] for bc in BC]
#  #  for i in range(len(A)):
#  #      for bc in BC:
#  #          points.append(A[i]+bc)
#  #      #  for j in range(len(B)):
#  #      #      for k in range(len(C)):
#  #      #          point = A[i] + B[j] + C[k]
#  #      #          points.append(point)
for i in sorted(points, reverse=True)[:K]:
    print(i)

Submission status: Wrong Answer

Solution code:
X, Y, Z, K  = [int(i) for i in input().split()]


A = [int(i) for i in input().split()]
A.sort(reverse=True)


B = [int(i) for i in input().split()]
B.sort(reverse=True)

C = [int(i) for i in input().split()]
C.sort(reverse=True)


ai = 0
bi = 0
ci = 0

out = []
for i in A:
    for j in B:
        for k in C:
            out.append(i+j+k)

out.sort(reverse=True)    

for x in out:
    print(x)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy

limit = 80

x,y,z,k = map(int, input().split(" "))

acake= [int(e) for e in input().split(" ")]
bcake= [int(e) for e in input().split(" ")]
ccake= [int(e) for e in input().split(" ")]

acake.sort(reverse = True)
bcake.sort(reverse = True)
ccake.sort(reverse = True)

pre_result = numpy.array(list(itertools.product(acake[0:limit],bcake[0:limit],ccake[0:limit])),dtype=numpy.int64)

result = numpy.sort(numpy.sum(pre_result,axis=1))[::-1]

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import itertools
X, Y ,Z, K = map(int, input().split())
A = map(int, input().split())
B = map(int, input().split())
C = map(int, input().split())
l = list(itertools.product(A, B, C))
ans = sorted([sum(n) for n in l ],reverse=True)
for a in ans:
  print(a)

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()
b.sort()
c.sort()

if x * y * z <= 3000:
    ans = []
    for ai in a:
        for bi in b:
            for ci in c:
                ans.append(ai + bi + ci)
    ans.sort(reverse=True)
    for i in range(k):
        print(ans[i])
else:
    ia = 0
    ib = 0
    ic = 0
    len_a = len(a)
    len_b = len(b)
    len_c = len(c)

    while (ia+1) * (ib+1) * (ic+1) < 3000:
        if ia + 1 == len_a:
            diff_a = float('inf')
        else:
            diff_a = a[0] - a[ia+1]
        if ib + 1 == len_b:
            diff_b = float('inf')
        else:
            diff_b = b[0] - b[ib+1]
        if ic + 1 == len_c:
            diff_c = float('inf')
        else:
            diff_c = c[0] - c[ic+1]

        if diff_a <= diff_b and diff_a <= diff_c:
            ia += 1
            while ia+1 < len_a and a[ia+1] == a[ia]:
                ia += 1
        if diff_b <= diff_a and diff_b <= diff_c:
            ib += 1
            while ib+1 < len_b and a[ib+1] == a[ib]:
                ib += 1
        if diff_c <= diff_a and diff_c <= diff_b:
            ic += 1
            while ic+1 < len_c and a[ic+1] == a[ic]:
                ic += 1

    a = a[:ia+1]
    b = b[:ib+1]
    c = c[:ic+1]

    ans = []
    for ai in a:
        for bi in b:
            for ci in c:
                ans.append(ai + bi + ci)
    ans.sort(reverse=True)
    for i in range(k):
        print(ans[i])

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

X, Y, Z, K = LI()
A = LI()
B = LI()
C = LI()

A = A[:min(100, X)]
B = B[:min(100, Y)]
C = C[:min(100, Z)]
# Aの中で最大の数字足すBの最大、Cの最大は全体の中で最大
# 3000個大きい順に求めれば良い

# iが決まれば、j,kのおおきさは分かる
BC = []
# 1000*1000 で10**6の計算量
for j in range(len(B)):
    for k in range(len(C)):
        BC.append(B[j] + C[k])

points = []
# 10**3 と 10** 6
for i in range(len(A)):
    points += [bc + A[i] for bc in BC]
#  #  for i in range(len(A)):
#  #      for bc in BC:
#  #          points.append(A[i]+bc)
#  #      #  for j in range(len(B)):
#  #      #      for k in range(len(C)):
#  #      #          point = A[i] + B[j] + C[k]
#  #      #          points.append(point)
for i in sorted(points, reverse=True)[:K]:
    print(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 h in a:
    for i in b:
        for j in c:li+=[h+i+j]
li=sorted(li)
for i in li[-1:-k:-1]:print(i)

Submission status: Wrong Answer

Solution code:
# D
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
a = a[:45]
b = b[:45]
c = c[:45]
ans = []
for i in a:
    for j in b:
        for l in c:
            ans.append(i+j+l)
ans.sort(reverse=True)
for i in range(k):
    print(ans[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()))
import heapq
q = []
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
def val(i, j, k):
  return -(A[i] + B[j] + C[k])
heapq.heappush(q, (val(0,0,0), 0,0,0))
for _ in range(k):
  v, aa, bb, cc = heapq.heappop(q)
  print(-v)
  if aa + 1 < len(A):
    heapq.heappush(q, (val(aa+1, bb, cc), aa+1, bb, cc))
  if bb + 1 < len(B):
    heapq.heappush(q, (val(aa, bb+1, cc), aa, bb+1, cc))
  if cc + 1 < len(C):
    heapq.heappush(q, (val(aa, bb, cc+1), aa, bb, cc+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()))
a.sort(key=lambda x:-x)
b.sort(key=lambda x:-x)
c.sort(key=lambda x:-x)
while x*y*z>6000:
    if max(x,y,z)==x:
        x//=2
    elif max(x,y,z)==y:
        y//=2
    else:
        z//=2
beauty=[0 for _ in range(x*y*z)]
index=0
for i in range(x):
    for j in range(y):
        for l in range(z):
            beauty[index]=a[i]+b[j]+c[l]
            index+=1
beauty.sort(key=lambda x:-x)
# print(beauty)
for i in range(k):
    print(beauty[i])

Submission status: Wrong Answer

Solution code:
# D
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
a = a[:15]
b = b[:15]
c = c[:15]
ans = []
for i in a:
    for j in b:
        for l in c:
            ans.append(i+j+l)
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
import sys
from itertools import product

def main():
    input = sys.stdin.readline
    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, key=lambda x: -x)
    B = sorted(B, key=lambda x: -x)
    C = sorted(C, key=lambda x: -x)

    deli= []
    for i in range(min(15, X)):
        for j in range(min(15, Y)):
            for k in range(min(15, Z)):
                deli.append(A[i] + B[j] + C[k])

    deli = sorted(deli, key=lambda x: -x)
    for i in range(K):
        print(deli[i])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools
import numpy

limit = 59

x,y,z,k = map(int, input().split(" "))

acake= [int(e) for e in input().split(" ")]
bcake= [int(e) for e in input().split(" ")]
ccake= [int(e) for e in input().split(" ")]

acake.sort(reverse = True)
bcake.sort(reverse = True)
ccake.sort(reverse = True)

pre_result = numpy.array(list(itertools.product(acake[0:limit],bcake[0:limit],ccake[0:limit])))

result = numpy.sort(numpy.sum(pre_result,axis=1))[::-1]

for i in range(k):
    print(result[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(key=lambda x:-x)
b.sort(key=lambda x:-x)
c.sort(key=lambda x:-x)
while x*y*z>6000:
    x,y,z=x//2,y//2,z//2
beauty=[0 for _ in range(x*y*z)]
index=0
for i in range(x):
    for j in range(y):
        for l in range(z):
            beauty[index]=a[i]+b[j]+c[l]
            index+=1
beauty.sort(key=lambda x:-x)
# print(beauty)
for i in range(k):
    print(beauty[i])

Submission status: Wrong Answer

Solution code:
INF = -10**11
x, y, z, k = [int(item) for item in input().split()]
a = sorted([int(item) for item in input().split()], reverse=True) + [INF]
b = sorted([int(item) for item in input().split()], reverse=True) + [INF]
c = sorted([int(item) for item in input().split()], reverse=True) + [INF]

num = x + y + z
ac, bc, cc = 0, 0, 0
ad = a[0] - a[1]
bd = b[0] - b[1]
cd = c[0] - c[1]
kadd = min(k*10, x*y*z)
while (ac+1) * (bc+1) * (cc+1) < kadd:
    if ad <= bd and ad <= cd:
        ac += 1
        ad = a[ac] - a[ac+1]
    elif bd <= ad and bd <= cd:
        bc += 1
        bd = b[bc] - b[bc+1]
    elif cd <= ad and cd <= bd:
        cc += 1
        cd = c[cc] - c[cc+1]

vals = []
for ai in a[:ac+1]:
    for bi in b[:bc+1]:
        for ci in c[:cc+1]:
            vals.append(ai+bi+ci)
vals.sort(reverse=True)
for i in range(k):
    print(vals[i])

Submission status: Wrong Answer

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

a = sorted(a)
b = sorted(b)
c = sorted(c)

d = (x<20) + (y<20) + (z<20)

if d == 3 or d == 2:
    la = []
    for i in range(x):
        for k in range(y):
            for m in range(z):
                la.append(a[i]+b[k]+c[m])
    la = sorted(la)

    for p in range(q):
        print(la[-p-1])

elif d == 1:
    if x<20:
        la = []
        for v in range(x):
            for i in range(min(y,100)):
                for k in range(min(z,100)):
                    la.append(a[v]+b[-i-1]+c[-k-1])
        la = sorted(la)
        for i in range(q):
            print(la[-i-1])
    if y <20:
        la = []
        for v in range(y):
            for i in range(min(x,100)):
                for k in range(min(z,100)):
                    la.append(b[v]+a[-i-1]+c[-k-1])
        la = sorted(la)
        for i in range(q):
            print(la[-i-1])
    if z<20:
        la = []
        for v in range(z):
            for i in range(min(y,100)):
                for k in range(min(x,100)):
                    la.append(c[v]+b[-i-1]+a[-k-1])
        la = sorted(la)
        for i in range(q):
            print(la[-i-1])

else:
    la  = []
    for i in range(19):
        for k in range(19):
            for m in range(19):
                la.append(a[-i-1]+b[-k-1]+c[-m-1])
    la = sorted(la)
    for i in range(q):
        print(la[-i-1])

Submission status: Wrong Answer

Solution code:
from itertools import*
x,y,z,k=map(int,input().split())
a=set(map(int,input().split()))
b=set(map(int,input().split()))
c=set(map(int,input().split()))
#print(a,b,c)
for e in sorted(sum(i)for i in product(a,b,c))[::-1][:k]:
    print(e)

Submission status: Wrong Answer

Solution code:
import itertools

def cal(a):
    return a[0] + a[1] + a[2]

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

print(k)
l = sorted(list(map(cal, itertools.product(a,b,c))), reverse=True)
for i in range(k[3]):
    print(l[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(key=lambda x:-x)
b.sort(key=lambda x:-x)
c.sort(key=lambda x:-x)
beauty=[0 for _ in range(min(x*y*z,8000))]
index=0
x=min(x,20)
y=min(y,20)
z=min(z,20)
for i in range(x):
    for j in range(y):
        for l in range(z):
            beauty[index]=a[i]+b[j]+c[l]
            index+=1
beauty.sort(key=lambda x:-x)
# print(beauty)
for i in range(k):
    print(beauty[i])

Submission status: Wrong Answer

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

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

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

input = sys.stdin.readline

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

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

# 空白区切りリスト整数
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
ll = []
for i in a:
    for j in b:

        if len(ll) > 3001 and ll[0] > i + j:
            break
        else:
            bisect.insort(ll, i + j)

ll = ll[0:3000]
c.sort(reverse=True)

lll = []
for i in c:
    for j in ll:

        if len(lll) > 3001 and lll[0] > i + j:
            break
        else:
            bisect.insort(lll, i + j)

lll.reverse()

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

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

Submission status: Wrong Answer

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict, Counter
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

X, Y, Z, K = s_inpl()
A = l_inpl()
B = l_inpl()
C = l_inpl()

A_s = sorted(A)[::-1][:16]
B_s = sorted(B)[::-1][:16]
C_s = sorted(C)[::-1][:16]

l = []
for ai in A_s:
    for bi in B_s:
        for ci in C_s:
            l.append(ai+bi+ci)

l.sort(reverse=True)

for i in l[:K]:
    print(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()
b.sort()
c.sort()

if x * y * z <= 3000:
    ans = []
    for ai in a:
        for bi in b:
            for ci in c:
                ans.append(ai + bi + ci)
    ans.sort(reverse=True)
    for i in range(k):
        print(ans[i])
else:
    ia = 0
    ib = 0
    ic = 0
    len_a = len(a)
    len_b = len(b)
    len_c = len(c)

    while (ia+1) * (ib+1) * (ic+1) < 3000:
        if ia + 1 == len_a:
            diff_a = float('inf')
        else:
            diff_a = a[0] - a[ia+1]
        if ib + 1 == len_b:
            diff_b = float('inf')
        else:
            diff_b = b[0] - b[ib+1]
        if ic + 1 == len_c:
            diff_c = float('inf')
        else:
            diff_c = c[0] - c[ic+1]

        if diff_a <= diff_b and diff_a <= diff_c:
            ia += 1
        elif diff_b <= diff_a and diff_b <= diff_c:
            ib += 1
        elif diff_c <= diff_a and diff_c <= diff_b:
            ic += 1

    a = a[:ia+1]
    b = b[:ib+1]
    c = c[:ic+1]

    ans = []
    for ai in a:
        for bi in b:
            for ci in c:
                ans.append(ai + bi + ci)
    ans.sort(reverse=True)
    for i in range(k):
        print(ans[i])

Submission status: Wrong Answer

Solution code:
X, Y, Z, K = list(map(int, input().split(" ")))
xs = list(map(int, input().split(" ")))
ys = list(map(int, input().split(" ")))
zs = list(map(int, input().split(" ")))

lst = []
for x in xs:
    for y in ys:
        for z in zs:
            lst.append(x+y+z)
print(sorted(lst)[::-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()))
li=[]
for h in a:
    for i in b:
        for j in c:li+=[h+i+j]
li=sorted(li)
for i in li[-k:-1]:print(i)

Submission status: Wrong Answer

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

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

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

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

Comb = []
for i in range(min(X, 15)):
    for j in range(min(Y, 15)):
        for k in range(min(Z, 15)):
            Comb.append(A[i] + B[j] + C[k])

Comb.sort(reverse=True)

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

Submission status: Wrong Answer

Solution code:
import sys

stdout = sys.stdout
rr = lambda: input().strip()
rri = lambda: int(rr())
rrm = lambda: list(map(int, rr().split()))


x, y, z, k = rrm()
tasty1 = rrm()
tasty2 = rrm()
tasty3 = rrm()

ans = []
for num1 in tasty1:
    for num2 in tasty2:
        for num3 in tasty3:
            ans.append(num1 + num2 + num3)

ans.sort(reverse=True)
for num in ans:
    print(num)

Submission status: Wrong Answer

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

from itertools import product


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)

y = []

for a, b, c in product(A, B, C):
    y.append(a + b + c)

y = sorted(y, reverse=True)
y = [str(n) for n in y]
print("\n".join(y))

Submission status: Wrong Answer

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

A_list = sorted(map(int, input().split()))[-1::-1][:K]
B_list = sorted(map(int, input().split()))[-1::-1][:K]
C_list = sorted(map(int, input().split()))[-1::-1][:K]

a_idx = 0
b_idx = 0
c_idx = 0

ans = []
for a in A_list:
    for b in B_list:
        for c in C_list:
            ans.append(a+b+c)
ans = sorted(ans)[-1::-1]

for a in ans:
    print(a)

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()))
l=[]
for i in range(len(a)):
    for j in range(len(b)):
        for w in range(len(c)):
            l.append(a[i]+b[j]+c[w])
l.sort()
l.reverse()
for i in range(len(l)):
    print(l[i])