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 = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
list.sort(A,reverse =  True)
list.sort(B,reverse =  True)
list.sort(C,reverse =  True)
sums = []
if X * Y * Z > 3000:
    for i in range(X):
        sums.append(B[0]+C[0]+A[i])
    for i in range(Y):
        sums.append(B[i]+C[0]+A[0])
    for i in range(Z):
        sums.append(B[0]+C[i]+A[0])
else:
    for a in range(X):
        for b in range(Y):
            for c in range(Z):
                sums.append(A[a]+B[b]+C[c])
list.sort(sums,reverse = True)
for i in range(K):
    print(sums[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)
L=[]
for i in range(min(100,len(A))):
    for j in range(min(100,len(B))):
        for k in range(min(100,len(C))):
            L.append(A[i]+B[j]+C[k])
L.sort(reverse=True)
for p in range(K):
    print(L[p])

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)
L=[]
for i in range(min(15,len(A))):
    for j in range(min(15,len(B))):
        for k in range(min(15,len(C))):
            L.append(A[i]+B[j]+C[k])
L.sort(reverse=True)
for p in range(K):
    print(L[p])

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  x,y,z,k=LI()

  if x==2 and y==2 and z==2 and k==8:
    exit()

  la=LI()
  lb=LI()
  lc=LI()

  la=sorted(la,key=lambda x:x,reverse=True)
  lb=sorted(lb,key=lambda x:x,reverse=True)
  lc=sorted(lc,key=lambda x:x,reverse=True)

  l=[]
  for a in la[:k]:
    for b in lb[:k]:
      l.append(a+b)

  l=sorted(l,key=lambda x:x,reverse=True)

  l2=[]
  for x in l[:k]:
    for c in lc[:k]:
      l2.append(x+c)

  l2=sorted(l2,key=lambda x:x,reverse=True)

  for x in l2[:k]:
    print(x)

main()

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  x,y,z,k=LI()

  if x==2 and y==2 and z==2 and k==8:
    exit()

  la=LI()
  lb=LI()
  lc=LI()

  l=[]
  for a in la:
    for b in lb:
      for c in lc:
        l.append(a+b+c)

  l.sort()
  l.reverse()

  for x in l[:20]:
    print(x)

main()

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 i in range(X):
	j=0
	while((i+1)*(j+1)<K+1 and j<Y):
		k=0
		while((i+1)*(j+1)*(k+1)<K+1 and k<Z):
			ans.append(A[i]+B[j]+C[k])
			k+=1
		j+=1
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
import heapq

x, y, z, k = [ int(v) for v in input().split() ]
a_list = sorted([ -int(v) for v in input().split() ], reverse = True )
b_list = sorted([ -int(v) for v in input().split() ], reverse = True )
c_list = sorted([ -int(v) for v in input().split() ], reverse = True )


def most_dericious(a,b,c):
	return a_list[a] + b_list[b] + c_list[c]
out_cakes_list= []
for i in range(k):
	if i == 0:
		dericious_heap = [ (most_dericious(x-1,y-1,z-1),(x-1,y-1,z-1)) ]
		heapq.heapify(dericious_heap)
	out_cakes = (heapq.heappop(dericious_heap))
	p, q, r = out_cakes[1][0], out_cakes[1][1], out_cakes[1][2]

	if p-1 >= 0 and (most_dericious(p-1,q,r),(p-1,q,r)) not in dericious_heap:
		heapq.heappush(dericious_heap,(most_dericious(p-1,q,r),(p-1,q,r)))
	if q-1 >= 0 and (most_dericious(p,q-1,r),(p,q-1,r)) not in dericious_heap:
		heapq.heappush(dericious_heap,(most_dericious(p,q-1,r),(p,q-1,r)))
	if r-1 >= 0 and (most_dericious(p,q,r-1),(p,q,r-1)) not in dericious_heap:
		heapq.heappush(dericious_heap,(most_dericious(p,q,r-1),(p,q,r-1)))
	out_cakes_list.append(out_cakes)

out_cakes_list = sorted(out_cakes_list)
for i in range(k):
	print(-out_cakes_list[i][0])

Submission status: Wrong Answer

Solution code:
import heapq

x, y, z, k = [ int(v) for v in input().split() ]
a_list = sorted([ -int(v) for v in input().split() ], reverse = True )
b_list = sorted([ -int(v) for v in input().split() ], reverse = True )
c_list = sorted([ -int(v) for v in input().split() ], reverse = True )


def most_dericious(a,b,c):
	return a_list[a] + b_list[b] + c_list[c]

for i in range(k):
	if i == 0:
		dericious_heap = [ (most_dericious(x-1,y-1,z-1),(x-1,y-1,z-1)) ]
		heapq.heapify(dericious_heap)
	out_cakes = (heapq.heappop(dericious_heap))
	p, q, r = out_cakes[1][0], out_cakes[1][1], out_cakes[1][2]

	if p-1 >= 0 and (most_dericious(p-1,q,r),(p-1,q,r)) not in dericious_heap:
		heapq.heappush(dericious_heap,(most_dericious(p-1,q,r),(p-1,q,r)))
	if q-1 >= 0 and (most_dericious(p,q-1,r),(p,q-1,r)) not in dericious_heap:
		heapq.heappush(dericious_heap,(most_dericious(p,q-1,r),(p,q-1,r)))
	if r-1 >= 0 and (most_dericious(p,q,r-1),(p,q,r-1)) not in dericious_heap:
		heapq.heappush(dericious_heap,(most_dericious(p,q,r-1),(p,q,r-1)))

	print(-out_cakes[0])

Submission status: Wrong Answer

Solution code:
# 優先度付きキューで解く問題
# Atcoder abc123 D - Cake 123

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


import heapq
import sys

INT_MIN = -1 * sys.maxsize

a_cakes = A[:]
#a_cakes = sorted(a_cakes, reverse=True)
b_cakes = B[:]
#b_cakes = sorted(b_cakes, reverse=True)
c_cakes = C[:]
#c_cakes = sorted(c_cakes, reverse=True)

value_list = []
heapq.heapify(value_list)

for a in a_cakes:
    for b in b_cakes:
        for c in c_cakes:
            heapq.heappush(value_list, -1*(a+b+c))
            
for x in value_list[:K]:
    print(-x)

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)
a.append(-100000000000)
b.append(-100000000000)
c.append(-100000000000)

def f(u):
    return a[u[0]]+b[u[1]]+c[u[2]]
def next(u):
    u1 = [u[0]+1,u[1],u[2]]
    u2 = [u[0],u[1]+1,u[2]]
    u3 = [u[0],u[1],u[2]+1]
    m = max(f(u1),f(u2),f(u3))
    if f(u1)==m:
        return u1
    elif f(u2)==m:
        return u2
    else:
        return u3


dp = f([0,0,0])
v = [[1,0,0],[0,1,0],[0,0,1]]

print(dp)
if k>1:
    for i in range(k-1):
        dp = max(f(v[0]),f(v[1]),f(v[2]))
        print(dp)
        x = [f(v[0]),f(v[1]),f(v[2])].index(dp)
        v[x] = next(v[x])

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 x in range(X):
  for y in range(Y):
    for z in range(X):
      L.append(A[x] + B[y] + C[z])
      
L.sort(reverse = True)
for N in L:
  print(N)

Submission status: Wrong Answer

Solution code:
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
# A.sort(reverse=True)
# B.sort(reverse=True)
# C.sort(reverse=True)
# m = A[0]+B[0]+C[0]
AB = []
for a in A:
    for b in B:
        AB.append(a+b)
ABC = AB[:K]
for c in C:
    for ab in AB:
        ABC.append(c+ab)
ABC.sort(reverse=True)
for i in range(K):
    print(ABC[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)
# m = A[0]+B[0]+C[0]
def getAB(A,B,K):
    AB = []
    cnt = 0
    for a in A:
        for b in B:
            AB.append(a+b)
            cnt += 1
            if cnt >= K:
                return AB
    return AB

AB = getAB(A, B, K)
ABC = []
for c in C:
    for ab in AB:
        ABC.append(c+ab)

ABC.sort(reverse=True)
for i in range(K):
    print(ABC[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=sorted(A,reverse=True)
b=sorted(B,reverse=True)
c=sorted(C,reverse=True)
q=[]
ans=[0]*K

q.append((a[0]+b[0]+c[0],1,1,1))
#q.append((0,1,1,1))
i=0
j=0
k=0

for l in range(K):
    #ans[l]=q[0]
    print(q[0][0])
    del q[0]
    if (i+1<=X-1 and j<=Y-1 and k<=Z-1) and ((a[i+1]+b[j]+c[k],i+1,j,k) not in q) :
        q.append((a[i+1]+b[j]+c[k],i+1,j,k))
    if (i<=X-1 and j+1<=Y-1 and k<=Z-1) and ((a[i]+b[j+1]+c[k],i,j+1,k) not in q):
        q.append((a[i]+b[j+1]+c[k],i,j+1,k))
    if (i<=X-1 and j<=Y-1 and k+1<=Z-1) and ((a[i]+b[j]+c[k+1],i,j,k+1) not in q):
        q.append((a[i]+b[j]+c[k+1],i,j,k+1))
    q=sorted(q,reverse=True)
    #print(q)
    if q==[]:
        i=0
        j=0
        k=0
    else:
        i=q[0][1]
        j=q[0][2]
        k=q[0][3]
    #print(q)
#[print(ans[i][0]) for i in range(k)]

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

X,Y,Z,K = inpl()
AA = inpl()
BB = inpl()
CC = inpl()

AB = []
for x in AA:
    for y in BB:
        AB.append(x+y)

AB.sort()
CC.sort()
XY = X*Y

def calc(x):
    tmp = 0
    for c in CC:
        if c >= x:
            tmp += X*Y
        else:
            tmp += XY - bisect.bisect_left(AB,x-c)
    return tmp


OK = 0
NG = 10000000000*3 + 5

while NG - OK > 1:
    mid = (OK + NG)//2
    if calc(mid) >= K:
        OK = mid
    else:
        NG = mid

ans = []
for c in CC:
    ind = bisect.bisect_left(AB,OK-c)
    for i in range(ind,XY):
        ans.append(c+AB[i])

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

Submission status: Wrong Answer

Solution code:
def maxAndIndex(a_buf):
    memIdx = 0
    memMax = a_buf[0] 
    for i, e in enumerate(a_buf[1:]):
        if e > memMax:
            memMax = e
            memIdx = i + 1
    return memMax, memIdx

def sub():
    lines = [input() for _ in range(4)]
    X, Y, Z, K = [int(e) for e in lines[0].split(" ")]
    As = [int(e) for e in lines[1].split(" ")]
    Bs = [int(e) for e in lines[2].split(" ")]
    Cs = [int(e) for e in lines[3].split(" ")]

    As = sorted(As, reverse=True)
    Bs = sorted(Bs, reverse=True)
    Cs = sorted(Cs, reverse=True)
    nb_A = len(As)
    nb_B = len(Bs)
    nb_C = len(Cs)
    # dv = {}
    # dv[(0,0,0)] = As[0] + Bs[0] + Cs[0]
    buf = []
    qs = [(0,0,0)]
    for i in range(K):
        vs = [As[q[0]] + Bs[q[1]] + Cs[q[2]] for q in qs]
        m, im = maxAndIndex(vs)
        # print(m)
        buf.append(m)
        qm = qs[im]
        qs = qs[:im] + qs[im+1:]
        a, b, c = qm
        if a+1 < nb_A:
            qs.append((a+1, b, c))
        if b+1 < nb_B:
            qs.append((a, b+1, c))
        if c+1 < nb_C:
            qs.append((a, b, c+1))
        qs = list(set(qs))

    buf = [str(b) for b in buf]
    print("\n".join(buf))



        

sub()

Submission status: Wrong Answer

Solution code:
import itertools

x, y, z, k = [int(i) for i in 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()]

d=[sum(i) for i in list(itertools.product(a, b))]
count=0
for i in sorted([sum(i) for i in list(itertools.product(a, d))]):
    print(i)
    count +=1
    if count==k:
        break

Submission status: Wrong Answer

Solution code:
import itertools

x, y, z, k = [int(i) for i in 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()]

[print(i) for i in sorted([sum(i) for i in list(itertools.product(a, b, c))], reverse=True)]

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)
bi_deli=[]
for i in range(min(X,K)):
    for j in range(min(Y,K)):
        if (i+1)*(j+1)>K:
            break
        bi_deli.append(A[i]+B[j])
tri_deli=[]
for k in range(min(len(bi_deli),K)):
    for l in range(min(Z,K)):
        if (k+1)*(l+1)>K:
            break
        tri_deli.append(bi_deli[k]+C[l])
tri_deli.sort(reverse=True)

print(*tri_deli[:K],sep='\n')

Submission status: Wrong Answer

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

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

xyz = []

for ia in range(len(a)):
    for ib in range(len(b)):
        if (ia+1)*(ib+1) >= k:
            break
        for ic in range(len(c)):
            if (ia+1)*(ib+1)*(ic+1) <= k:
                xyz.append(a[ia]+b[ib]+c[ic])
            else:
                break

xyz.sort(reverse=True)
for l in xyz[:k]:
    print(l)

Submission status: Wrong Answer

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

for i in a:
    for j in b:
        ab.append(i+j)

ab.sort()
s = ab[x*y-k:]
for i in s:
    for j in c:
        abc.append(i+j)

abc.sort(reverse=True)
for i in range(k):
    print(abc[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 = sorted(list(map(int, input().split())))[z-k:]
ab, abc = [], []

for i in a:
    for j in b:
        ab.append(i+j)

ab.sort()
s = ab[x*y-k:]
for i in s:
    for j in c:
        abc.append(i+j)

abc.sort(reverse=True)
for i in range(k):
    print(abc[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)

xy = []
xyz = []
m = min(3000, x*y*z)

for ia in a:
    for ib in b:
        xy.append(ia+ib)
xy.sort(key=lambda x: -x)
xy = xy[:m]

for ix in xy:
    for ic in c:
        xyz.append(ix+ic)


ans = sorted(xyz, key=lambda x: -x)
print(ans[:k])

Submission status: Wrong Answer

Solution code:
X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse= True)
B.sort(reverse= True)
C.sort(reverse= True)
LIS = []
LISA = []
LISB = []
S = 0
T = 0
for s in range(X):
    for t in range(Y):
        if (s+1)*(t+1) <= 3000:
            LISA.append(s)
            LISB.append(t)
        elif (s+1)*(t+1) > 3000:
            S += s
            T += t
            break
            
for i in range(len(LISA)):
    PR = A[LISA[i]]+B[LISB[i]]
    for j in range(min(Z,max((3000//(S+1)),(3000//(T+1))))):
        LIS.append(PR+C[j])
LIS.sort(reverse = True)
for i in range(min(len(LIS),K)):
    print(LIS[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)
LIS = []
LISA = []
LISB = []
S = 0
T = 0
for s in range(X):
    for t in range(Y):
        if (s+1)*(t+1) <= 3000:
            LISA.append(s)
            LISB.append(t)
        elif (s+1)*(t+1) > 3000:
            S += s
            T += t
            break
            
for i in range(len(LISA)):
    PR = A[LISA[i]]+B[LISB[i]]
    for j in range(min(X,(3000//(S+1)),(3000//(T+1)))):
        LIS.append(PR+C[j])
LIS.sort(reverse = True)
for i in range(min(len(LIS),K)):
    print(LIS[i])

Submission status: Wrong Answer

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

ab = len(a)*len(b)
xy = []
xyz = []

for ia in reversed(a):
    for ib in reversed(b):
        xy.append(ia+ib)

for ix in xy:
    for ic in reversed(c):
        xyz.append(ix+ic)

ans = sorted(xyz, key=lambda x: -x)
print(ans[:k])

Submission status: Wrong Answer

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

bi_comb = []
for i in range(min(X, K)):
    for j in range(min(Y, K)):
        if (i+1)*(j+1) > K:
            break
        bi_comb.append(A[i] + B[j])
bi_comb.sort(reverse=True)

tri_comb = []
for k in range(min(len(bi_comb), K)):
    for l in range(min(Z, K)):
        if (k+1)*(l+1) > K:
            break
        print(k, bi_comb[k])
        print(C[l])
        tri_comb.append(bi_comb[k] + C[l])
tri_comb.sort(reverse=True)

print(*tri_comb[:K], sep="\n")

Submission status: Wrong Answer

Solution code:
X,Y,Z,K = (int(_) for _ in input().split())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]

#L=[0]*X*Y*Z
#K = min(K, 3000, X*Y*Z)

#for x in range(X):
#    for y in range(Y):
#        for z in range(Z):
#            L.append(A[x]+B[y]+C[z])

#L.sort(reverse = True)
#for i in range(K):
#    print(L[i])

Submission status: Wrong Answer

Solution code:
from itertools import product

def solve(X, Y, Z, K, A, B, C):
    res_AB = sorted([sum(p) for p in product(A, B)], reverse=True)[:K]
    return sorted([sum(p) for p in product(res_AB, C)], reverse=True)[:K]

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
D - Cake 123
https://atcoder.jp/contests/abc123/tasks/abc123_d
TLE
"""
import sys


from itertools import product


def solve(X, Y, Z, K, A, B, C):
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)

    while (len(A)-1) * (len(B)-1) * (len(C)-1) > K:
        m = sorted([[A[0], 'a'], [B[0], 'b'], [C[0], 'c']])
        _, mi = m.pop(0)
        if mi == 'a':
            A.pop()
        elif mi == 'b':
            B.pop()
        else:
            C.pop()

    return sorted([sum(p) for p in product(A, B, C)], reverse=True)[:K]


def main(args):
    X, Y, Z, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    B = [int(b) for b in input().split()]
    C = [int(c) for c in input().split()]
    ans = solve(X, Y, Z, K, A, B, C)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
X, Y, Z, K = [int(x) for x in input().split()]
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]
ABC = []
for a in range(len(A)):
    if a+1 > K:
        continue
    for b in range(len(B)):
        if b+1 > K:
            continue
        elif (a+1)*(b+1) > K:
            continue
        for c in range(len(C)):
            if c+1 > K:
                continue
            elif (a+1)*(c+1) > K:
                continue
            elif (b+1)*(c+1) > K:
                continue
            elif (a+1)*(b+1)*(c+1) > K:
                continue
            ABC.append(A[a] + B[b] + C[c])
ABC = sorted(ABC, reverse=True)
for i in range(K):
    print(ABC[i])

Submission status: Wrong Answer

Solution code:
l = [int(x) for x in input().split()]
x = [int(x) for x in input().split()]
x.sort(reverse=True)
y = [int(x) for x in input().split()]
y.sort(reverse=True)
z = [int(x) for x in input().split()]
z.sort(reverse=True)


K = l[-1]
pre = []
result_l = []
for i in x:
    for j in y:
        pre.append(i+j)
        if len(pre) >= K:
            break
for k in pre:
    for r in z:
        result_l.append(k+r)

result_l.sort(reverse=True)

for ind in range(l[-1]):
    print(result_l[ind])

Submission status: Wrong Answer

Solution code:
import sys

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


x = int(x)
y = int(y)
z = int(z)
k = int(k)

x1 = []
wx1 = input()
wx1 = wx1.split()

wy1 = input()
wy1 = wy1.split()

wz1 = input()
wz1 = wz1.split()

for i in range(x):
    x1.append(int(wx1[i]))
x1.sort(reverse=True)

y1 = []
for i in range(y):
    y1.append(int(wy1[i]))
y1.sort(reverse=True)

z1 = []
for i in range(y):
    z1.append(int(wz1[i]))
z1.sort(reverse=True)

xy = []
n = 0
for i in x1:
	for j in y1:
		
		xy.append(i+j)
		n += 1
		if n > (k * 2):
			break

xy.sort(reverse = True)
print(xy)

xyz = []
n = 0
for i in z1:
    for j in xy:
        xyz.append((j + i))
        n += 1
        if n == k:
            break

xyz.sort(reverse=True)

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

Submission status: Wrong Answer

Solution code:
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
m=[]
for b in map(int,input().split()):
  for i in a:
    m+=[i+b]
m.sort(reverse=1)
if len(m)>3000:
  m=m[:3000]
ans=[]
for c in map(int,input().split()):
  for i in m:
    ans+=[c+i]
ans.sort(reverse=1)
if len(ans)>3000:
  ans=ans[:3000]
for i in ans:
  print(i)

Submission status: Wrong Answer

Solution code:

import heapq
X,Y,Z,K = map(int,input().split())
As = sorted(list(map(int,input().split())),reverse=True)
Bs = sorted(list(map(int,input().split())),reverse=True)
Cs = sorted(list(map(int,input().split())),reverse=True)
q = []
heapq.heapify(q)
heapq.heappush(q,(-(As[0]+Bs[0]+Cs[0]),0,0,0))
for i in range(K):
    # valueのマイナス値の小さい順にpop(優先度付きqueue)
    v,i,j,k = heapq.heappop(q)
    if i < len(As)-1:
        heapq.heappush(q,(-(As[i+1]+Bs[j]+Cs[k]),i+1,j,k))
    if j < len(Bs)-1:
        heapq.heappush(q,(-(As[i]+Bs[j+1]+Cs[k]),i,j+1,k))
    if k < len(Cs)-1:
        heapq.heappush(q,(-(As[i]+Bs[j]+Cs[k+1]),i,j,k+1))
    print(-v)

Submission status: Wrong Answer

Solution code:
X,Y,Z,K = map(int,input().split())
As = sorted(list(map(int,input().split())),reverse=True)
Bs = sorted(list(map(int,input().split())),reverse=True)
Cs = sorted(list(map(int,input().split())),reverse=True)

# ABでソート
AB = []
for A in As:
    for B in Bs:
        AB.append(A+B)
ABs = sorted(AB,reverse=True)

# その中からK番目まで
ABC = []
for i in range(min(len(AB),K)):
    for C in Cs:
        ABC.append(AB[i]+C)

ABCs = sorted(ABC,reverse=True)
for i in range(K):
    print(ABCs[i])

Submission status: Wrong Answer

Solution code:
# どうやって自明な条件で計算量を落としていくか
# 不等式に注目。pythonが耐えるのは10^6程度
import numpy as np
X,Y,Z,K = map(int,input().split())
As = sorted(list(map(int,input().split())),reverse=True)
Bs = sorted(list(map(int,input().split())),reverse=True)
Cs = sorted(list(map(int,input().split())),reverse=True)

# ABでソート
AB = []
for A in As:
    for B in Bs:
        AB.append(A+B)
ABs = sorted(AB,reverse=True)

# その中からK番目まで
ABC = []
for i in range(min(len(AB),K)):
    for C in Cs:
        ABC.append(AB[i]+C)

ABCs = sorted(ABC,reverse=True)
for i in range(K):
    print(ABCs[i])

Submission status: Wrong Answer

Solution code:
X, Y, Z, K = map(int, input().split())
ListA = list(input().split())
ListB = list(input().split())
ListC = list(input().split())
ListAns =[]
for a in range(min(X, K)):
    for b in range(min(Y, K)):
        for c in range(min(Z, K)):
            ans = ListA[a] + ListB[b] + ListC[c]
            ListAns.append(ans)
ListAns.sort(reverse = True)
for i in ListAns:
    print(i)

Submission status: Wrong Answer

Solution code:
X, Y, Z, K = map(int, input().split())
ListA = list(input().split())
ListB = list(input().split())
ListC = list(input().split())
ListAns =[]
for a in ListA:
    for b in ListB:
        for c in ListC:
            ans = a + b + c
            ListAns.append(ans)
            if len(ListAns) == K:
                break
ListAns.sort(reverse = True)
for i in ListAns:
    print(i)

Submission status: Wrong Answer

Solution code:
x, y, z, o = [int(_) for _ in input().split()]
a = sorted([int(_) for _ in input().split()])[::-1]
b = sorted([int(_) for _ in input().split()])[::-1]
c = sorted([int(_) for _ in input().split()])[::-1]

def isEnough(p):
    cnt = 0
    for i in range(x):
        for j in range(y):
            for k in range(z):
                if a[i]+b[j]+c[k] < p : break
                cnt += 1
                if cnt >= o: return True
    return False

ok, ng = 0, a[0]+b[0]+c[0]
while abs(ok-ng)>1:
    m = (ok+ng)//2
    print(ok,ng)
    if isEnough(m):
        ok = m
    else:
        ng = m

l = []
for i in range(x):
    for j in range(y):
        for k in range(z):
            if a[i]+b[j]+c[k] <= ok : break
            l.append(a[i]+b[j]+c[k])
l.sort(reverse=True)
for i in range(o):
    if len(l) > i:
        print(l[i])
    else:
        print(ok)

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)
cor = []
for i in range(X):
    for j in range(Y):
        cor.append(A[i]+B[j])
    if len(cor) == K:
        break

cor.sort(reverse = True)
if K <= X*Y:
    cor = cor[:K]
anslist = []
for i in range(min(K,X*Y)):
    for j in range(Z):
        anslist.append(C[j]+cor[i])
        if len(anslist) == K:
            break

anslist.sort(reverse = True)
for i in range(K):
    print(anslist[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()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
m1 = []
m2 = []
for ai in a:
  for bi in b:
    m1.append(ai+bi)
if x * y > k:
  l = k
else:
  l = x * y
for i in range(l):
  for ci in c:
    m2.append(m1[i] + ci)
for i in range(k):
  print(max(m2))
  m2.remove(max(m2))

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)

tmp = []
for x in range(X):
    for y in range(Y):
        tmp.append(A[x] + B[y])
        
tmp.sort(reverse=True)

res = []

for i in range(X*Y):
    for z in range(Z):
        res.append(tmp[i] + C[z])
        
        if len(res) == 10 * K:
            break
    if len(res) == 10 * K:
        break
        
res.sort(reverse=True)
for i in range(K):
    print(res[i])

Submission status: Wrong Answer

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

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

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

def judge(p):
    cnt = 0
    for i in range(x):
        for j in range(y):
            for kk in range(z):
                if a[i]+b[j]+c[kk] < p : break
                cnt += 1
                if (cnt >= k):return True
    return False

ll,rr = 0,a[0]+b[0]+c[0]
while(rr- ll > 1):
    md = (ll+rr) // 2
    if(judge(md)) : ll = md
    else : rr = md

ans = []
cnt=0
for i in range(x):
    for j in range(y):
        for kk in range(z):
            if a[i]+b[j]+c[kk] < rr : break
            ans.append(a[i]+b[j]+c[kk])

if len(ans) <k:
    for i in range(k-len(ans)):
        ans.append(ll)

ans.sort(reverse=True)

for i in ans:
    print(i)