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:
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)
ABC = A+B+C
ABC = sorted(ABC, reverse=True)
#  print(ABC)
a,b,c = [],[],[]
abc = 0
while not(len(a) >= min(150, X) and len(b) >= min(150, Y) and len(c) >= min(150, Z)):
    if A:
        if ABC[abc]in A:
            a.append(ABC[abc])
            A.remove(ABC[abc])
    if B:
        if ABC[abc]in B:
            b.append(ABC[abc])
            B.remove(ABC[abc])
    if C:
        if ABC[abc]in C:
            c.append(ABC[abc])
            C.remove(ABC[abc])
    abc+=1
#  for abc in range(min(200, X+Y+Z)):

#      if ABC[abc]in A:
#          a.append(ABC[abc])
#          A.remove(ABC[abc])
#      if ABC[abc]in B:
#          b.append(ABC[abc])
#          B.remove(ABC[abc])
#      if ABC[abc]in C:
#          c.append(ABC[abc])
#          C.remove(ABC[abc])
#  print(a,b,c)

points = []
for i in a:
    for j in b:
        for k in c:
            points.append(i+j+k)


#  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)):
#              points.append(A[i] + B[j] + C[k])
for i in sorted(points, reverse=True)[:K]:
    print(i)

Submission status: Wrong Answer

Solution code:
import itertools
X, Y, Z, K = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse = True)[:110]
B = sorted([int(i) for i in input().split()], reverse = True)[:110]
C = sorted([int(i) for i in input().split()], reverse = True)[:110]

D = []
for a, b, c in itertools.product(A, B, C):
    d = a + b + c
    D.append(d)
    
D.sort(reverse = True)
for d in D[:K]:
    print(d)

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)
ABC = A+B+C
ABC = sorted(ABC, reverse=True)
#  print(ABC)
a,b,c = [],[],[]
abc = 0
while not(len(a) >= min(200, X) and len(b) >= min(200, Y) and len(c) >= min(200, Z)):
    if A:
        if ABC[abc]in A:
            a.append(ABC[abc])
            A.remove(ABC[abc])
    if B:
        if ABC[abc]in B:
            b.append(ABC[abc])
            B.remove(ABC[abc])
    if C:
        if ABC[abc]in C:
            c.append(ABC[abc])
            C.remove(ABC[abc])
    abc+=1
#  for abc in range(min(200, X+Y+Z)):

#      if ABC[abc]in A:
#          a.append(ABC[abc])
#          A.remove(ABC[abc])
#      if ABC[abc]in B:
#          b.append(ABC[abc])
#          B.remove(ABC[abc])
#      if ABC[abc]in C:
#          c.append(ABC[abc])
#          C.remove(ABC[abc])
#  print(a,b,c)

points = []
for i in a:
    for j in b:
        for k in c:
            points.append(i+j+k)


#  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)):
#              points.append(A[i] + B[j] + C[k])
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()
a.reverse()
b.sort()
b.reverse()
c.sort()
c.reverse()
ans=[]
if x*y*z<=3000:
  for i in range(x):
    for j in range(y):
      for h in range(z):
        ans.append(a[i]+b[j]+c[h])
  ans.sort()
  ans.reverse()
  for i in range(k):
    print(ans[i])
  exit()
p=0
q=0
r=0
a1=0
b1=0
c1=0
while (p+1)*(q+1)*(r+1)<k+1000:
  if p+1<len(a):
      a1=a[0]-a[p+1]
  if q+1<len(b):
      b1=b[0]-b[q+1]
  if r+1<len(c):
      c1=c[0]-c[r+1]
  if a1==min(a1,b1,c1) and p+1<len(a):
    p+=1
  elif b1==min(a1,b1,c1) and q+1<len(b):
    q+=1
  elif c1==min(a1,b1,c1) and r+1<len(c):
    r+=1
  else:
    if p+1<len(a):
      p+=1
    if q+1<len(b):
      q+=1
    if r+1<len(c):
      r+=1
for i in range(p+1):
  for j in range(q+1):
    for h in range(r+1):
      ans.append(a[i]+b[j]+c[h])
ans.sort()
ans.reverse()
for i in range(k):
  print(ans[i])

Submission status: Wrong Answer

Solution code:
x,y,z,k=map(int,input().split());a,b,c=list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split()));a.sort(reverse=1);b.sort(reverse=1);c.sort(reverse=1);ma=a[0]+b[0]+c[0];d=[[0],[0],[0]]
for i in range(len(a)-1):d[0].append(d[0][-1]+a[i]-a[i+1])
for i in range(len(b)-1):d[1].append(d[1][-1]+b[i]-b[i+1])
for i in range(len(c)-1):d[2].append(d[2][-1]+c[i]-c[i+1])
e=d[0]+d[1]+d[2]
if x*y*z>3000:
  f,i=[0,0,0],0
  while f[0]*f[1]*f[2]<3000:
    for z in range(3):
      if f[z]<len(d[z]):
        while d[z][f[z]]==i:
          f[z]+=1
          if f[z]==len(d[z]):break
          if f[0]*f[1]*f[2]>3000:break
    i+=1
  for i in range(3):d[i]=d[i][:f[i]+1]
s=[]
for i in d[0]:
  for j in d[1]:
    for h in d[2]:s.append(i+h+j)
s.sort()
for i in range(k):print(ma-s[i])

Submission status: Wrong Answer

Solution code:
# 2019/04/06
# AtCoder Beginner Contest 123 - D

# Input
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.append(0)
b.append(0)
c.append(0)

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

aidx = 0
bidx = 0
cidx = 0

wa = list()
wb = list()
wc = list()

wflg = True
loopend = min(3000, x*y*z)

while(wflg):
    if a[aidx] > b[bidx]:
        if a[aidx] > c[cidx]:
            wa.append(a[aidx])
            aidx += 1
        else:
            wc.append(c[cidx])
            cidx += 1
    else:
        if b[bidx] > c[cidx]:
            wb.append(b[bidx])
            bidx += 1
        else:
            if c[cidx] > 0:
                wc.append(c[cidx])
                cidx += 1
            else:
                wflg = False
    wval = aidx * bidx * cidx
    if wval > loopend:
        wflg = False

delival = list()

for i in range(len(wa)):
    for j in range(len(wb)):
        for l in range(len(wc)):
            delival.append(wa[i]+wb[j]+wc[l])

delival.sort(reverse=True)

sum = 0
for i in range(k):
    print(delival[i])

Submission status: Wrong Answer

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
import itertools
X, Y, Z, K = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse = True)[:150]
B = sorted([int(i) for i in input().split()], reverse = True)[:150]
C = sorted([int(i) for i in input().split()], reverse = True)[:150]

D = []
for a, b, c in itertools.product(A, B, C):
    d = a + b + c
    D.append(d)
    
D.sort(reverse = True)
for d in D[:K]:
    print(d)

Submission status: Wrong Answer

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

from itertools import product


X, Y, Z, K = map(int, input().split())
A = sorted(map(int, input().split()), reverse=True)
B = sorted(map(int, input().split()), reverse=True)
C = sorted(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:
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(6000, 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]

for i in range(5):
    if ac+1 < x:
        ac += 1
    if bc+1 < y:
        bc += 1
    if cc+1 < z:
        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 itertools
import numpy

limit = 56

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)

maxnum = max(acake[-1] , bcake[-1] ,acake[-1])

if acake[0] == maxnum:
    alimit = 1000
    blimit = limit
    climit = limit
elif bcake[0] == maxnum:
    blimit = 1000
    alimit = limit
    climit = limit
else:
    climit = 1000
    blimit = limit
    alimit = limit


pre_result = numpy.array(list(itertools.product(acake[0:alimit],bcake[0:blimit],ccake[0:climit])),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:
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)-150), len(a)):
    for j in range(max(0,len(b)-150), len(b)):
        for l in range(max(0,len(c)-150), len(c)):
            e = a[i]+b[j]
            d.append(e+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()))
ans = []
for a1 in A:
  for b1 in B:
    for c1 in C:
      ans.append(a1+b1+c1)
      
ans.sort(reverse=True)
for i in ans:
  print(i)

Submission status: Wrong Answer

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)
A.append(-1)
B.append(-1)
C.append(-1)
Ai, Bi, Ci = 0, 0, 0
ans = []
while True:
    # a, b, c = A[Ai], B[Bi], C[Ci]
    # ans.append(a+b+c)
    na, nb, nc = A[min(X, Ai+1)], B[min(Y, Bi+1)], C[min(Z, Ci+1)]
    maxNabc = max(na, nb, nc)
    # print(Ai, Bi, Ci)
    if maxNabc == na:
        Ai+=1
    elif maxNabc == nb:
        Bi+=1
    elif maxNabc == nc:
        Ci+=1
    if (Ai+1) * (Bi+1) * (Ci+1) >= min(1000*K, X*Y*Z):
        break
for i in range(Ai+1):
    for j in range(Bi+1):
        for k in range(Ci+1):
            ans.append(A[i]+B[j]+C[k])
ans = sorted(ans, reverse=True)
for i in range(K):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

A = A[:30]
B = B[:30]
C = C[:30]

ans = []
for a in A:
    for b in B:
        for c in C:
            ans.append(a+b+c)
    
ans.sort(reverse=True)
for a in ans[:K]:
    print(a)

Submission status: Wrong Answer

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

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

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

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

oisi.sort()
oisi.reverse()
for i in range(k):
  print(oisi[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()
a.reverse()
b.sort()
b.reverse()
c.sort()
c.reverse()
ans=[]
if x*y*z<=3000:
  for i in range(x):
    for j in range(y):
      for h in range(z):
        ans.append(a[i]+b[j]+c[h])
  ans.sort()
  ans.reverse()
  for i in range(k):
    print(ans[i])
  exit()
p=0
q=0
r=0
a1=0
b1=0
c1=0
while (p+1)*(q+1)*(r+1)<k:
  if p+1<len(a):
      a1=a[0]-a[p+1]
  if q+1<len(b):
      b1=b[0]-b[q+1]
  if r+1<len(c):
      c1=c[0]-c[r+1]
  if a1==min(a1,b1,c1) and p+1<len(a):
    p+=1
  elif b1==min(a1,b1,c1) and q+1<len(b):
    q+=1
  elif c1==min(a1,b1,c1) and r+1<len(c):
    r+=1
  else:
    if p+1<len(a):
      p+=1
    if q+1<len(b):
      q+=1
    if r+1<len(c):
      r+=1
for i in range(p+1):
  for j in range(q+1):
    for h in range(r+1):
      ans.append(a[i]+b[j]+c[h])
ans.sort()
ans.reverse()
for i in range(k):
  print(ans[i])

Submission status: Wrong Answer

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)
useA = [a.pop(0)]
useB = [b.pop(0)]
useC = [c.pop(0)]
if len(a) == 0:
  a.append(0)
if len(b) == 0:
  b.append(0)
if len(c) == 0:
  c.append(0)
while True:
  if a[0] == b[0] == c[0] == 0:
    break
  if a[0] >= b[0] and a[0] >= c[0]:
    useA.append(a.pop(0))
    if len(a) == 0:
      a.append(0)
  elif b[0] >= a[0] and b[0] >= c[0]:
    useB.append(b.pop(0))
    if len(b) == 0:
      b.append(0)
  elif c[0] >= b[0] and c[0] >= a[0]:
    useC.append(c.pop(0))
    if len(c) == 0:
      c.append(0)
#  print( len(useA) * len(useB) * len(useC))
  if k**2 <= len(useA) * len(useB) * len(useC):
    break
ans = []
#print(useA, useB, useC)
for i in range(len(useA)):
  for j in range(len(useB)):
    for m in range(len(useC)):
      ans.append(useA[i] + useB[j] + useC[m])
ans.sort(reverse = True)
for i in range(k):
  print(ans[i])

Submission status: Wrong Answer

Solution code:
import itertools
import numpy

limit = 46

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)

maxnum = max(acake[-1] , bcake[-1] ,acake[-1])

if acake[0] == maxnum:
    alimit = 1000
    blimit = limit
    climit = limit
elif bcake[0] == maxnum:
    blimit = 1000
    alimit = limit
    climit = limit
else:
    climit = 1000
    blimit = limit
    alimit = limit


pre_result = numpy.array(list(itertools.product(acake[0:alimit],bcake[0:blimit],ccake[0:climit])),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:
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)
A.append(-1)
B.append(-1)
C.append(-1)
Ai, Bi, Ci = 0, 0, 0
ans = []
while True:
    # a, b, c = A[Ai], B[Bi], C[Ci]
    # ans.append(a+b+c)
    na, nb, nc = A[min(X, Ai+1)], B[min(Y, Bi+1)], C[min(Z, Ci+1)]
    maxNabc = max(na, nb, nc)
    # print(Ai, Bi, Ci)
    if maxNabc == na:
        Ai+=1
    elif maxNabc == nb:
        Bi+=1
    elif maxNabc == nc:
        Ci+=1
    if (Ai+1) * (Bi+1) * (Ci+1) >= min(100*K, X*Y*Z):
        break
for i in range(Ai+1):
    for j in range(Bi+1):
        for k in range(Ci+1):
            ans.append(A[i]+B[j]+C[k])
ans = sorted(ans, reverse=True)
for i in range(K):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
X,Y,Z,K=map(int,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)
L=[]
N=0
n=0
while(N<min(K*K,X*Y*Z)):
    #p+q+r=n
    for p in range(0,n+1):
        for q in range(0,n+1-p):
            r=n-p-q
            if p<X and q<Y and r<Z:
                L.append(A[p]+B[q]+C[r])
                N+=1
    n+=1
L.sort(reverse=True)
for i in range(K):
    print(L[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*20, 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]

for i in range(5):
    if ac+1 < x:
        ac += 1
    if bc+1 < y:
        bc += 1
    if cc+1 < z:
        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, 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)

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 b[ib+1] == b[ib]:
                ib += 1
        if diff_c <= diff_a and diff_c <= diff_b:
            ic += 1
            while ic+1 < len_c and c[ic+1] == c[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:
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)
A.append(-1)
B.append(-1)
C.append(-1)
Ai, Bi, Ci = 0, 0, 0
ans = []
while True:
    # a, b, c = A[Ai], B[Bi], C[Ci]
    # ans.append(a+b+c)
    na, nb, nc = A[min(X, Ai+1)], B[min(Y, Bi+1)], C[min(Z, Ci+1)]
    maxNabc = max(na, nb, nc)
    # print(Ai, Bi, Ci)
    if maxNabc == na:
        Ai+=1
    elif maxNabc == nb:
        Bi+=1
    elif maxNabc == nc:
        Ci+=1
    if (Ai+1) * (Bi+1) * (Ci+1) >= min(10*K, X*Y*Z):
        break
for i in range(Ai+1):
    for j in range(Bi+1):
        for k in range(Ci+1):
            ans.append(A[i]+B[j]+C[k])
ans = sorted(ans, reverse=True)
for i in range(K):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
import itertools
import sys

input = sys.stdin.readline

maxn = 10000000000

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.append(-maxn)
B.append(-maxn)
C.append(-maxn)

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

apos, bpos, cpos = 0, 0, 0

while (apos + 1) * (bpos + 1) * (cpos + 1) < min(10 ** 6, X * Y * Z):
    if (
        apos < len(A) - 2
        and abs(A[apos] - A[apos + 1]) < abs(B[bpos] - B[bpos + 1])
        and abs(A[apos] - A[apos + 1]) < abs(C[cpos] - C[cpos + 1])
    ):
        apos += 1
    elif bpos < len(B) - 2 and B[bpos] - B[bpos + 1] < C[cpos] - C[cpos + 1]:
        bpos += 1
    else:
        cpos += 1

res = []
for a in list(itertools.product(A[: apos + 1], B[: bpos + 1], C[: cpos + 1])):
    res.append(a[0] + a[1] + a[2])

res.sort(reverse=True)
for k in range(K):
    print(res[k])

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)
ABC = A+B+C
ABC = sorted(ABC, reverse=True)
#  print(ABC)
a,b,c = [],[],[]
for abc in range(min(200, X+Y+Z)):
    if ABC[abc]in A:
        a.append(ABC[abc])
        A.remove(ABC[abc])
    if ABC[abc]in B:
        b.append(ABC[abc])
        B.remove(ABC[abc])
    if ABC[abc]in C:
        c.append(ABC[abc])
        C.remove(ABC[abc])
#  print(a,b,c)

points = []
for i in a:
    for j in b:
        for k in c:
            points.append(i+j+k)


#  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)):
#              points.append(A[i] + B[j] + C[k])
for i in sorted(points, reverse=True)[:K]:
    print(i)

Submission status: Wrong Answer

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

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

ca=0
cb=0
cc=0
xl = len(X)
for i in range(len(X)):
    _,a = X[i]
    if a == 0:
        ca += 1
    elif a == 1:
        cb += 1
    else:
        cc += 1 
    if ca*cb*cc>=6000:
        xl=i
        break
Ax=[]
Bx=[]
Cx=[]
for x,a in X[:(xl+1)]:
    if a == 0:
        Ax.append(x)
    elif a == 1:
        Bx.append(x)
    else:
        Cx.append(x)

ans = []
import itertools
for a,b,c in itertools.product(Ax,Bx,Cx):
    ans.append(a+b+c)
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import itertools
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())))

A = A[:30]
B = B[:30]
C = C[:30]

ans = []
for a in A:
    for b in B:
        for c in C:
            ans.append(a+b+c)
    
ans.sort(reverse=True)
for a in ans[:K]:
    print(a)

Submission status: Wrong Answer

Solution code:
import itertools
X, Y, Z, K = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse = True)[:100]
B = sorted([int(i) for i in input().split()], reverse = True)[:100]
C = sorted([int(i) for i in input().split()], reverse = True)[:100]

D = []
for a, b, c in itertools.product(A, B, C):
    d = a + b + c
    D.append(d)
    
D.sort(reverse = True)
for d in D[:K]:
    print(d)

Submission status: Wrong Answer

Solution code:
X,Y,Z,K=map(int,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)
L=[]
N=0
n=0
while(N<min(1500*K,X*Y*Z)):
    #p+q+r=n
    for p in range(0,n+1):
        for q in range(0,n+1-p):
            r=n-p-q
            if p<X and q<Y and r<Z:
                L.append(A[p]+B[q]+C[r])
                N+=1
    n+=1
L.sort(reverse=True)
for i in range(K):
    print(L[i])

Submission status: Wrong Answer

Solution code:
import itertools
import sys

input = sys.stdin.readline

maxn = 10000000000

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.append(-maxn)
B.append(-maxn)
C.append(-maxn)

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

apos, bpos, cpos = 0, 0, 0

while (apos + 1) * (bpos + 1) * (cpos + 1) < min(10 ** 5, X * Y * Z):
    if (
        apos < len(A) - 2
        and abs(A[apos] - A[apos + 1]) < abs(B[bpos] - B[bpos + 1])
        and abs(A[apos] - A[apos + 1]) < abs(C[cpos] - C[cpos + 1])
    ):
        apos += 1
    elif bpos < len(B) - 2 and B[bpos] - B[bpos + 1] < C[cpos] - C[cpos + 1]:
        bpos += 1
    else:
        cpos += 1

res = []
for a in list(itertools.product(A[: apos + 1], B[: bpos + 1], C[: cpos + 1])):
    res.append(a[0] + a[1] + a[2])

res.sort(reverse=True)
for k in range(K):
    print(res[k])