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)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)
A.append(-10**20)
B.append(-10**20)
C.append(-10**20)
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[Bi]+C[Ci], A[Ai]+B[min(Y, Bi+1)]+C[Ci], A[Ai]+B[Bi]+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(300*K, X*Y*Z):
    # if (Ai+1) * (Bi+1) * (Ci+1) >= 3*K:
        break
for i in range(Ai+1):
    for j in range(Bi+1):
        for k in range(Ci+1):
            # print(i,j,k)
            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:
N = [ int(x) for x in input().split() ]
a = [ sorted([ int(x) for x in input().split() ], reverse=True) for _ in range(3) ]
b = [ [a[0][0]], [a[1][0]], [a[2][0]] ]

while len(b[0])*len(b[1])*len(b[2]) < N[3]:
  i = 0
  m = 0
  for j in range(3):
    if len(a[j]) > len(b[j]):
      if a[j][len(b[j])] > m:
        i = j
        m = a[j][len(b[j])]
  b[i].append(m)

c = []
for i in b[0]:
  for j in b[1]:
    for k in b[2]:
      c.append(i+j+k)
c = sorted(c, reverse=True)

print("\n".join([str(x) for x in c]))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

x, y, z, k = [int(i) for i in input().split()]

c1 = [int(i) for i in input().split()]
c2 = [int(i) for i in input().split()]
c3 = [int(i) for i in input().split()]

ans = [i + j + k for i in c1 for j in c2 for k in c3]
ans.sort()
cnt = 1
for a in ans[::-1]:
  if cnt == 3000:
    break
  print(a)
  cnt += 1

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(-10**20)
B.append(-10**20)
C.append(-10**20)
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[Bi]+C[Ci], A[Ai]+B[min(Y, Bi+1)]+C[Ci], A[Ai]+B[Bi]+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(200*K, X*Y*Z):
    # if (Ai+1) * (Bi+1) * (Ci+1) >= 3*K:
        break
for i in range(Ai+1):
    for j in range(Bi+1):
        for k in range(Ci+1):
            # print(i,j,k)
            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,re,copy
input = sys.stdin.readline
X,Y,Z,K=[int(x) for x in input().strip().split()]

Ax=[int(x) for x in input().strip().split()]
By=[int(x) for x in input().strip().split()]
Cz=[int(x) for x in input().strip().split()]

Ax.sort()
Ax.reverse()
By.sort()
By.reverse()
Cz.sort()
Cz.reverse()

s=[[0,0,0]]
def nextpattern(s):
    ans=[]
    if s[0]!=X-1:
        ans.append([s[0]+1,s[1],s[2]])
    if s[1]!=Y-1:
        ans.append([s[0],s[1]+1,s[2]])
    if s[2]!=Z-1:
        ans.append([s[0],s[1],s[2]+1])
    return ans

pre=0
for _ in range(K):
    max_i=0
    max_c=0
    for i,c in enumerate(s):
        g=Ax[c[0]]+By[c[1]]+Cz[c[2]]
        if g>max_c:
            max_i = i
            max_c = g
        if max_c+1==pre:
            break
    print(max_c)
    pre=max_c
    s+=nextpattern(s.pop(max_i))
    s=list(set(map(tuple,s)))

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
    i=min(d[0][min(f[0],len(d[0])-1)],min(d[1][min(f[1],len(d[1])-1)],d[2][min(f[2],len(d[2])-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:
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)
nA = A[0]
nB = B[0]
nC = C[0]
a, b, c = [], [], []
for i in A:
    a.append(nA-i)
for i in B:
    b.append(nB-i)
for i in C:
    c.append(nC-i)
ls = []
d, e, f = 0, 0, 0
while d*e*f < K:
    if d+1 == len(a):
        a.append(float('inf'))
        d += 1
    if e+1 == len(b):
        b.append(float('inf'))
        e += 1
    if f+1 == len(c):
        c.append(float('inf'))
        f += 1
    if min(a[d], b[e], c[f]) == a[d]:
        if d+1 != len(a):
            d += 1
    elif min(a[d], b[e], c[f]) == b[e]:
        if e+1 != len(b):
            e += 1
    elif min(a[d], b[e], c[f]) == c[f]:
        if f+1 != len(c):
            f += 1
for i in a[:d]:
    for j in b[:e]:
        for k in c[:f]:
            ls.append(i+j+k)
ls.sort()
for i in range(K):
    print(nA+nB+nC-ls[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 a[0] * b[0] * c[0] != 0 and (useA[-1] + useB[-1] >= useA[-1] + b[0] + useC[-1] or useA[-1] + useB[-1] >= useB[-1] + a[0] + useC[-1]):
    useC.extend(c)
    c.append(0)
  if a[0] * b[0] * c[0] != 0 and (useA[-1] + useC[-1] >= useA[-1] + c[0] + useB[-1] or useA[-1] + useC[-1] >= useB[-1] + a[0] + useC[-1]):
    useB.extend(b)
    b.append(0)
  if a[0] * b[0] * c[0] != 0 and (useB[-1] + useC[-1] >= useA[-1] + c[0] + useB[-1] or useB[-1] + useC[-1] >= useA[-1] + b[0] + useC[-1]):
    useA.extend(a)
    a.append(0)
  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:
# 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(9000, 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])

ansl = sorted(delival, reverse=True)

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

Submission status: Wrong Answer

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

ans = []
for i in a:
  for j in b:
    for l in c:
      if len(ans) <= k:
        ans.append(i+j+l)
#print(ans)
ans.sort(reverse=True)
for n in ans:
  print(n)

Submission status: Wrong Answer

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

test = [sum([aa,bb,cc]) for aa in a for bb in b for cc in c]
test.sort(reverse=True)
for i in test:
    print(i)

Submission status: Wrong Answer

Solution code:
import itertools
X, Y, Z, K = map(int, input().rstrip().split())
A = list(map(int, input().rstrip().split()))
B = list(map(int, input().rstrip().split()))
C = list(map(int, input().rstrip().split()))
A.sort()
B.sort()
C.sort()
if X*Y*Z != K:
    if X >= 50:
        A = A[:50]
    if Y >= 50:
        B = B[:50]
    if Z >= 50:
        C = C[:50]
combinations = list(itertools.product(A, B, C))
total = []
for combination in combinations:
    total.append(sum(combination))
total.sort(reverse=True)
for i in range(K):
    print(total[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(-10**20)
B.append(-10**20)
C.append(-10**20)
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[Bi]+C[Ci], A[Ai]+B[min(Y, Bi+1)]+C[Ci], A[Ai]+B[Bi]+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):
    # if (Ai+1) * (Bi+1) * (Ci+1) >= 3*K:
        break
for i in range(Ai+1):
    for j in range(Bi+1):
        for k in range(Ci+1):
            # print(i,j,k)
            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 = 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)

ans = [p+q+r for p in a[:150] for q in b[:150] for r in c[:150]]

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=[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)
SUM=[]
for a in range(min(100,X)):
  for b in range(min(100,Y)):
    for c in range(min(100,Z)):
      SUM.append(A[a]+B[b]+C[c])
SUM.sort(reverse=True)
for i in range(K):
  print(SUM[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(-10**20)
B.append(-10**20)
C.append(-10**20)
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[Bi]+C[Ci], A[Ai]+B[min(Y, Bi+1)]+C[Ci], A[Ai]+B[Bi]+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):
    # if (Ai+1) * (Bi+1) * (Ci+1) >= 3*K:
        break
for i in range(Ai+1):
    for j in range(Bi+1):
        for k in range(Ci+1):
            # print(i,j,k)
            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, math

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

k = list(map(int, input().split()))
index = math.ceil(k[3] / 3)
a = sorted(list(map(int, input().split())), reverse=True)[:index]
b = sorted(list(map(int, input().split())), reverse=True)[:index]
c = sorted(list(map(int, input().split())), reverse=True)[:index]
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)
len=min(x*y*z,3000)
beauty=[0 for _ in range(10000)]
beauty[0]=a[0]+b[0]+c[0]
index=1
indexsum=1
size=[x,y,z]
flag=True
while flag:
    if index>=len:
        flag=False
        if index>=x*y*z:
            break
    imax=min(indexsum+1,x)
    for i in range(imax):
        jmax=min(indexsum+1-i,y)
        for j in range(jmax):
            if indexsum-i-j < z:
                num=a[i]+b[j]+c[indexsum-i-j]
                beauty[index]=num
                index+=1
                # print(num)
    indexsum+=1
beauty.sort(key=lambda x:-x)
# print(beauty)
for i in range(k):
    print(beauty[i])

Submission status: Wrong Answer

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

cakes_x = list(map(int, input().split()))
cakes_y = list(map(int, input().split()))
cakes_z = list(map(int, input().split()))

cakes_x.sort(reverse=True)
cakes_y.sort(reverse=True)
cakes_z.sort(reverse=True)

print(cakes_x)
print(cakes_y)
print(cakes_z)

scores = []
for cake_x in cakes_x:
    for cake_y in cakes_y:
        for cake_z in cakes_z:
            scores.append(cake_x + cake_y + cake_z)

scores.sort(reverse=True)

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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)

bimi = []
cnt = -100000

def roop():
        global cnt
        for a in range(X):
                for b in range(Y):
                        for c in range(Z):
                                bimi.append(A[a] + B[b] + C[c])
                                cnt += 1

                                if cnt == K:
                                        return

roop()
bimi.sort(reverse=True)

for x in range(K):
        print(bimi[x])

Submission status: Wrong Answer

Solution code:
import heapq
import itertools

def dif(l):
  return max(l) - min(l)

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)

flag = True
while flag:
  fa = False
  while (x-1)*y*z > k and dif(a) > dif(b) and dif(a) > dif(c):
    a.pop()
    x -= 1
    fa = True

  fb = False
  while x*(y-1)*z > k and dif(b) > dif(a) and dif(b) > dif(c):
    b.pop()
    y -= 1
    fb = True

  fc = False
  while x*y*(z-1) > k and dif(c) > dif(b) and dif(c) > dif(a):
    c.pop()
    z -= 1
    fc = True
  
  flag = fa or fb or fc

l=[]
for a1 in a:
    for b1 in b:
        for c1 in c:
            l.append(a1+b1+c1)

m2 = heapq.nlargest(k, l)
for i in range(k):
  print(m2[i])

Submission status: Wrong Answer

Solution code:
import numpy as np

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)

progress = [(0, 0, 0)]

def prod(p, q, r):
    return A[p] + B[q] + C[r]

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

for i in range(k):
    prods = [prod(*tup) for tup in progress]

    max_val = max(prods)
    max_idx = prods.index(max_val)
    p, q, r = progress[max_idx]

    print(max_val)
    progress.pop(max_idx)
    progress.extend(expand(p, q, r))
    progress = list(set(progress))

Submission status: Wrong Answer

Solution code:
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)
nA = A[0]
nB = B[0]
nC = C[0]
a, b, c = [], [], []
for i in A:
    a.append(nA-i)
for i in B:
    b.append(nB-i)
for i in C:
    c.append(nC-i)
ls = []
d, e, f = 0, 0, 0
while d*e*f < K:
    if d+1 == len(a):
        a.append(float('inf'))
        d += 1
    if e+1 == len(b):
        b.append(float('inf'))
        e += 1
    if f+1 == len(c):
        c.append(float('inf'))
        f += 1
    if min(a[d], b[e], c[f]) == a[d]:
        if d+1 != len(a):
            d += 1
    elif min(a[d], b[e], c[f]) == b[e]:
        if e+1 != len(b):
            e += 1
    elif min(a[d], b[e], c[f]) == c[f]:
        if f+1 != len(c):
            f += 1
for i in a[:d+1]:
    for j in b[:e+1]:
        for k in c[:f+1]:
            ls.append(i+j+k)
ls.sort()
for i in range(K):
    print(nA+nB+nC-ls[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[ia] - a[ia+1]
        if ib + 1 == len_b:
            diff_b = float('inf')
        else:
            diff_b = b[ib] - b[ib+1]
        if ic + 1 == len_c:
            diff_c = float('inf')
        else:
            diff_c = c[ic] - c[ic+1]

        if diff_a <= diff_b and diff_a <= diff_c:
            ia += 1
        if diff_b <= diff_a and diff_b <= diff_c:
            ib += 1
        if 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 = 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)

ans = [p+q+r for p in a[:200] for q in b[:200] for r in c[:200]]

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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)

bimi = []
cnt = -10000

def roop():
        global cnt
        for a in range(X):
                for b in range(Y):
                        for c in range(Z):
                                bimi.append(A[a] + B[b] + C[c])
                                cnt += 1

                                if cnt == K:
                                        return

roop()
bimi.sort(reverse=True)

for x in range(K):
        print(bimi[x])

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_ = [a+b+c for (a,b,c) in itertools.product(A[:200], B[:200], C[:200])]
list_.sort(reverse=True)
for N in list_[:K]:
  print(N)

Submission status: Wrong Answer

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


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


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


def diff_array(array):
    return [array[i + 1] - array[i] for i in xrange(len(array) - 1)]


X, Y, Z, K = ints_raw()
A = ints_raw()
sorted_A = sorted(A, reverse=True)
B = ints_raw()
sorted_B = sorted(B, reverse=True)
C = ints_raw()
sorted_C = sorted(C, reverse=True)

current_A = 0
current_B = 0
current_C = 0


def diff(array, index):
    if len(array) <= index:
        return 10000000000
    return array[0] - array[index]


count = 0
while count < 150:
    if (current_A + 1) * (current_B + 1) * (current_C + 1) >= K:
        count += 1
    a = diff(sorted_A, current_A + 1)
    b = diff(sorted_B, current_B + 1)
    c = diff(sorted_C, current_C + 1)
    if a <= b and a <= c and current_A < X - 1:
        current_A += 1
        continue
    if b <= c and b <= a and current_B < Y - 1:
        current_B += 1
        continue
    if c <= a and c <= b and current_C < Z - 1:
        current_C += 1
        continue

result = []
for i in xrange(current_A + 1):
    for j in xrange(current_B + 1):
        for k in xrange(current_C + 1):
            result.append(sorted_A[i] + sorted_B[j] + sorted_C[k])

sorted_result = sorted(result, reverse=True)
for i in xrange(K):
    print(sorted_result[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)
B = sorted([int(i) for i in input().split()], reverse = True)
C = sorted([int(i) for i in input().split()], reverse = True)

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

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

ansl = sorted(delival, reverse=True)

sum = 0
for i in range(k):
    print(ansl[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)

sum = []
for i in range(min(X,100)):
    for j in range(min(Y,100)):
        for k in range(min(Z,100)):
            sum.append(A[i] + B[j] + C[k])
sum.sort(reverse=True)
for i in range(K):
    print(sum[i])

Submission status: Wrong Answer

Solution code:
a = []
b = []
c = []
l = 100
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 = [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_ = [a+b+c for (a,b,c) in itertools.product(A[:100], B[:100], C[:100])]
list_.sort(reverse=True)
for N in list_[:K]:
  print(N)

Submission status: Wrong Answer

Solution code:
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)
SUM=[]
for a in range(min(150,X)):
  for b in range(min(150,Y)):
    for c in range(min(150,Z)):
      SUM.append(A[a]+B[b]+C[c])
SUM.sort(reverse=True)
for i in range(K):
  print(SUM[i])

Submission status: Wrong Answer

Solution code:
import sys,re,copy
input = sys.stdin.readline
X,Y,Z,K=[int(x) for x in input().strip().split()]

Ax=[int(x) for x in input().strip().split()]
By=[int(x) for x in input().strip().split()]
Cz=[int(x) for x in input().strip().split()]

Ax.sort()
Ax.reverse()
By.sort()
By.reverse()
Cz.sort()
Cz.reverse()

s=[[0,0,0]]
def nextpattern(s):
    ans=[]
    if s[0]!=X-1:
        ans.append([s[0]+1,s[1],s[2]])
    if s[1]!=Y-1:
        ans.append([s[0],s[1]+1,s[2]])
    if s[2]!=Z-1:
        ans.append([s[0],s[1],s[2]+1])
    return ans

for _ in range(K):
    max_i=0
    max_c=0
    for i,c in enumerate(s):
        g=Ax[c[0]]+By[c[1]]+Cz[c[2]]
        if g>max_c:
            max_i = i
            max_c = g
    print(max_c)
    s+=nextpattern(s.pop(max_i))
    s=list(set(map(tuple,s)))

Submission status: Wrong Answer

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


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


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


def diff_array(array):
    return [array[i + 1] - array[i] for i in xrange(len(array) - 1)]


X, Y, Z, K = ints_raw()
A = ints_raw()
sorted_A = sorted(A, reverse=True)
B = ints_raw()
sorted_B = sorted(B, reverse=True)
C = ints_raw()
sorted_C = sorted(C, reverse=True)

current_A = 0
current_B = 0
current_C = 0


def diff(array, index):
    if len(array) <= index:
        return 10000000000
    return array[0] - array[index]


count = 0
while count < 200:
    if (current_A + 1) * (current_B + 1) * (current_C + 1) >= K:
        count += 1
    a = diff(sorted_A, current_A + 1)
    b = diff(sorted_B, current_B + 1)
    c = diff(sorted_C, current_C + 1)
    if a <= b and a <= c and current_A < X - 1:
        current_A += 1
        continue
    if b <= c and b <= a and current_B < Y - 1:
        current_B += 1
        continue
    if c <= a and c <= b and current_C < Z - 1:
        current_C += 1
        continue

result = []
for i in xrange(current_A + 1):
    for j in xrange(current_B + 1):
        for k in xrange(current_C + 1):
            result.append(sorted_A[i] + sorted_B[j] + sorted_C[k])

sorted_result = sorted(result, reverse=True)
for i in xrange(K):
    print(sorted_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(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

ans = [p+q+r for p in a[:100] for q in b[:100] for r in c[:100]]

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