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 heapq
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

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

heap = []
heapq.heappush(heap, (-(A[0] + B[0] + C[0]), 0, 0, 0))
history = {(0, 0, 0)}
while len(history) < K:
    d, a, b, c = heapq.heappop(heap)
    if a + 1 < X and (a + 1, b, c) not in history:
        history.add((a + 1, b, c))
        heapq.heappush(heap, (-(A[a + 1] + B[b] + C[c]), a + 1, b, c))
    if b + 1 < Y and (a, b + 1, c) not in history:
        history.add((a, b + 1, c))
        heapq.heappush(heap, (-(A[a] + B[b + 1] + C[c]), a, b + 1, c))
    if c + 1 < Z and (a, b, c + 1) not in history:
        history.add((a, b, c + 1))
        heapq.heappush(heap, (-(A[a] + B[b] + C[c + 1]), a, b, c + 1))
    print(-d)

Submission status: Wrong Answer

Solution code:
import math
x, y, z, k = map(int, input().split())
listA = list(map(int, input().strip().split()))
listB = list(map(int, input().strip().split()))
listC = list(map(int, input().strip().split()))
listA.sort(reverse=True)
listB.sort(reverse=True)
listC.sort(reverse=True)
que_list = []
sum_list = []


class que:
    taste_sum = 0
    a = 0
    b = 0
    c = 0


def MakeAndApeendQue(a, b, c):
    new_que = que()
    new_que.a = a
    new_que.b = b
    new_que.c = c
    if a < len(listA) and b < len(listB) and c < len(listC):
        new_que.taste_sum = listA[a] + listB[b] + listC[c]
        n = len(que_list)
        que_list.append(new_que)
        while n != 0:
            i = (n - 1) // 2
            if que_list[i].taste_sum < que_list[n].taste_sum:
                tmp = que_list[i]
                que_list[i] = que_list[n]
                que_list[n] = tmp
            n = i


def SearchMaxAndDelete():
    max_a = que_list[0].a
    max_b = que_list[0].b
    max_c = que_list[0].c
    max = que_list[0].taste_sum
    n = len(que_list) - 1
    que_list[0] = que_list[n]
    del que_list[n]
    i = 0
    while i * 2 + 1 <= n - 1:  # n-1は削除した後のmaxindex
        change = 0
        if i*2+2 <= n-1 and que_list[i * 2 + 1].taste_sum < que_list[i * 2 + 2].taste_sum:
            change = i * 2 + 2
        else:
            change = i * 2 + 1
        if que_list[i].taste_sum < que_list[change].taste_sum:
            tmp = que_list[i]
            que_list[i] = que_list[change]
            que_list[change] = tmp
        i = change
    return max, max_a, max_b, max_c


def SearchQ(a, b, c):
    for i in range(0, len(que_list)):
        if que_list[i].a == a and que_list[i].b == b and que_list[i].c == c:
            return True
    return False


def AddQue(a, b, c):
    if SearchQ(a, b, c) == False:
        MakeAndApeendQue(a, b, c)


MakeAndApeendQue(0, 0, 0)
for i in range(0, k):
    max, ai, bi, ci = SearchMaxAndDelete()
    print("{}".format(max))
    AddQue(ai+1, bi, ci)
    AddQue(ai, bi+1, ci)
    AddQue(ai, bi, ci + 1)

Submission status: Wrong Answer

Solution code:
# AtCoder Beginner Contest 123
# https://atcoder.jp/contests/abc123
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    tk = lambda i, j, k: '%d %d %d' % (i, j, k)
    X, Y, Z, K = i2nn()
    A = i2nn()
    B = i2nn()
    C = i2nn()
    A.sort()
    A.reverse()
    B.sort()
    B.reverse()
    C.sort()
    C.reverse()
    dic = {}
    def put(i, j, k):
        if i >= X or j >= Y or k >= Z:
            return
        key = tk(i, j, k)
        if key not in dic:
            dic[key] = (A[i] + B[j] + C[k], key, i, j, k)
    put(0, 0, 0)
    for _ in range(K):
        v = max(dic.values(), key=lambda v: v[0])
        dic.pop(v[1])
        put(v[2]+1, v[3],   v[4]  )
        put(v[2],   v[3]+1, v[4]  )
        put(v[2],   v[3],   v[4]+1)
        print(v[0])

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()))
sam = []
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
ba,bb,bc = 0,0,0
print(a[0] + b[0] + c[0])
for K in range(k - 1):
	if ba < x - 1:
		sam.append([a[ba + 1] + b[bb] + c[bc],ba + 1,bb,bc])
	if bb < y - 1:
		sam.append([a[ba] + b[bb + 1] + c[bc],ba,bb + 1,bc])
	if bc < z - 1:
		sam.append([a[ba] + b[bb] + c[bc + 1],ba,bb,bc + 1])
	big = max(sam)
	for i in range(sam.count(big)):
		sam.remove(big)
	print(big[0])
	ba,bb,bc = big[1],big[2],big[3]

Submission status: Wrong Answer

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

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

yam = []
for l in range(x):
    for m in range(y):
        for n in range(z):
            yam.append(a[l]+b[m]+c[n])
yam.sort(reverse=True)
print(yam)

if k <= min(3000, x*y*z):
    for l in range(k):
        print(yam[l])
else:
    k = min(3000, x*y*z)
    for l in range(k):
        print(yam[l])

Submission status: Wrong Answer

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

for i in range(len(a)):
  for l in range(len(b)):
    ab_sum.append(a[i]+b[l])
		
ab_sum.sort()
c.sort()
ans = []
for i in range(min(k,len(ab_sum))):
	for l in range(min(k,len(c))):
		ans.append(ab_sum[i]+c[l])
		
ans.sort()
ans.reverse()
for i in range(k):
	print(ans[i])

Submission status: Wrong Answer

Solution code:
import heapq

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

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

h = []

heapq.heappush(h, (-A[0]-B[0]-C[0], 0,0,0))

result = []
used = set()

for _ in range(K):
    value, i,j,k = heapq.heappop(h)
    result.append(-value)
    if i < X-1 and (i+1,j,k) not in used:
        heapq.heappush(h, (-A[i+1]-B[j]-C[k],i,j,k))
        used.add((i+1,j,k))
    if j < Y-1 and (i,j+1,k) not in used:
        heapq.heappush(h, (-A[i]-B[j+1]-C[k],i,j+1,k))
        used.add((i,j+1,k))
    if k < Z-1 and (i,j,k+1) not in used:
        heapq.heappush(h, (-A[i]-B[j]-C[k+1],i,j,k+1))
        used.add((i,j,k+1))
        
for v in result:
    print(v)

Submission status: Wrong Answer

Solution code:
import heapq

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

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

h = []

heapq.heappush(h, (A[0]+B[0]+C[0], 0,0,0))

result = []
used = set()

for _ in range(K):
    value, i,j,k = heapq.heappop(h)
    result.append(value)
    if i < X-1 and (i+1,j,k) not in used:
        heapq.heappush(h, (A[i+1]+B[j]+C[k],i,j,k))
        used.add((i+1,j,k))
    if j < Y-1 and (i,j+1,k) not in used:
        heapq.heappush(h, (A[i]+B[j+1]+C[k],i,j+1,k))
        used.add((i,j+1,k))
    if k < Z-1 and (i,j,k+1) not in used:
        heapq.heappush(h, (A[i]+B[j]+C[k+1],i,j,k+1))
        used.add((i,j,k+1))
        
for v in result:
    print(v)

Submission status: Wrong Answer

Solution code:
import heapq

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

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

h = []

heapq.heappush(h, (A[0]+B[0]+C[0], 0,0,0))

result = []

for _ in range(K):
    value, i,j,k = heapq.heappop(h)
    result.append(value)
    if i < X-1:
        heapq.heappush(h, (A[i+1]+B[j]+C[k],i,j,k))
    if j < Y-1 and i == 0:
        heapq.heappush(h, (A[i]+B[j+1]+C[k],i,j+1,k))
    if k < Z-1 and i == 0 and j == 0:
        heapq.heappush(h, (A[i]+B[j]+C[k+1],i,j,k+1))
        
for v in result:
    print(v)

Submission status: Wrong Answer

Solution code:
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
AB = {}
for a in A:
  for b in B:
    AB[a+b] = AB.get(a+b,0)+1
kab = list(AB.keys())
kab.sort()
ABC = {}
for y in kab[-K:]:
  for c in C:
    ABC[y+c] = ABC.get(y+c,0)+1
kabc = list(ABC.keys())
kabc.sort()
sk = 0
for ki in kabc[-1:-K-1:-1]:
  p = min(ABC[ki],K-sk)
  sk += p
  for j in range(p):
    print(ki)
  if sk>=K:
    break

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)


# Priority QueueとしてHeapを使う
# Pythonのheapqは小さい順に取り出すので、-1を掛けて負数としてpushしていく
#   (-Ai-Bj-Ck, i, j, k)
# 取り出したi, j, kについて、(i+1, j, k), (i, j+1, k), (i, j, k+1)に対応するタプルをpushする
# ただし、すでにpushした値は入れないようにする

import heapq
import numpy as np

def make(i, j, k):
    return (-A[i]-B[j]-C[k], i, j, k)

used = np.zeros((X,Y,Z), dtype=bool)
def push_next(l, i, j, k):
    if i < X - 1 and not used[i+1, j, k]:
        heapq.heappush(l, make(i+1, j, k))
        used[i+1, j, k] = True
    
    if j < Y - 1 and not used[i, j+1, k]:
        heapq.heappush(l, make(i, j+1, k))
        used[i, j+1, k] = True
    
    if k < Z - 1 and not used[i, k, k+1]:
        heapq.heappush(l, make(i, j, k+1))
        used[i, j, k+1] = True



l = []

heapq.heappush(l, make(0, 0, 0))
used[0, 0, 0] = True

for cnt in range(K):
    V, i, j, k = heapq.heappop(l)
    push_next(l, i, j, k)
    
    print(-V)

Submission status: Wrong Answer

Solution code:
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)
ans=[]
for x in range(min(X, 100)):
	for y in range(min(Y, 100)):
		for z in range(min(Z, 100)):
			ans.append(A[x]+B[y]+C[z])
ans.sort(reverse=True)
for k in range(K):
	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()))
ans=[]
for x in range(min(X, 100)):
	for y in range(min(Y, 100)):
		for z in range(min(Z, 100)):
			ans.append(A[x]+B[y]+C[z])
ans.sort(reverse=True)
for k in range(K):
	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()))
ans=[]
for x in range(min(X, 15)):
	for y in range(min(Y, 15)):
		for z in range(min(Z, 15)):
			ans.append(A[x]+B[y]+C[z])
ans.sort(reverse=True)
for k in range(K):
	print(ans[k])

Submission status: Wrong Answer

Solution code:
import heapq as hq
x, y, z, k = map(int,input().split())
arr_a = sorted(list(map(int,input().split())) ,reverse = True)
arr_b = sorted(list(map(int,input().split())) ,reverse = True)
arr_c = sorted(list(map(int,input().split())) ,reverse = True)

cnt = [[[0 for i in range(z)] for j in range(y)] for k in range(x)]
P_q = [[-(arr_a[0] + arr_b[0] + arr_c[0]),0,0,0]]

cnt[0][0][0] = 1
for _ in range(0):
    tmp = hq.heappop(P_q)
    t, i, j, k = -tmp[0],tmp[1],tmp[2],tmp[3]
    print(t)
    if i + 1 < x and cnt[i+1][j][k] == 0:
        hq.heappush(P_q,[-(arr_a[i+1] + arr_b[j] + arr_c[k]) ,i + 1,j,k])
        cnt[i+1][j][k] = 1
    if j + 1 < y and cnt[i][j + 1][k] == 0:
        hq.heappush(P_q,[-(arr_a[i] + arr_b[j+1] + arr_c[k]) ,i ,j + 1,k])
        cnt[i][j+1][k] = 1
    if k + 1 < z and cnt[i][j][k + 1] == 0:
        hq.heappush(P_q,[-(arr_a[i] + arr_b[j] + arr_c[k + 1]) ,i,j,k + 1])
        cnt[i][j][k + 1] = 1

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc123
# -*- coding: utf-8 -*-

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

oisisa = []
for l in a:
    for m in b:
        for n in c:
            oisisa.append(l+m+n)

oisisa.sort(reverse = True)
for v in oisisa:
    print(v)

Submission status: Wrong Answer

Solution code:
x,y,z,K = map(int,input().split())
abc = [sorted(list(map(int,input().split())), reverse=True) for i in range(3)]

ans=[0]*K

for i in range(x):
    for j in range(y):
        for l in range(z):
            if min(ans) < abc[0][i]+abc[1][j]+abc[2][l]:
                ans[ans.index(min(ans))] = abc[0][i]+abc[1][j]+abc[2][l]
            
ans.sort(reverse=True)
print(ans)

Submission status: Wrong Answer

Solution code:
x,y,z,K = map(int,input().split())
abc = [list(map(int,input().split())) for i in range(3)]

ans=[]

for i in range(x):
    for j in range(y):
        for l in range(z):
            ans.append(abc[0][i]+abc[1][j]+abc[2][l])
            
ans.sort(reverse=True)
print(ans[:K])

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
X, Y, Z, K = map(int, input().split())
I = lambda: sorted(list(map(int, input().split())), reverse=True)
A = I()
B = I()
C = I()
hq = []

for a in A:
    for b in B:
        for c in C:
            if len(hq) < K:
                heappush(hq, a+b+c)
            else:
                tmp = heappop(hq)
                if tmp >= a+b+c:
                    heappush(hq, tmp)
                    break
                else:
                    heappush(hq, a*b*c)

ans = []
for _ in range(K):
    ans.append(heappop(hq))

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

Submission status: Wrong Answer

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


# 合計がp以上のものがK個以上あるか
def check(p, l=None):
    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
                if l is not None:
                    l.append(a[i]+b[j]+c[k])
                cnt += 1
                if cnt >= K:
                    return True
    return False

left = 0
right = a[0]+b[0]+c[0] + 1
while right-left > 1:
    mid = (left+right)//2
    if check(mid):
        left = mid
    else:
        right = mid
#print(left)
ans = []
check(left, ans)
for i in sorted(ans, reverse=True)[:K]:
    print(i)

Submission status: Wrong Answer

Solution code:
x,y,z,k=map(int, input().split())#=3,3,3,5
a=list(map(int, input().split()))#=[1,10,100]#
b=list(map(int, input().split()))#=[2,20,200]#
c=list(map(int, input().split()))#=[1,10,100]
a=sorted(a)[::-1]
b=sorted(b)[::-1]
c=sorted(c)[::-1]
que=[(a[0]+b[0]+c[0],0,0,0)]
ans=[]
while True:   
    max_item=que.pop()
    ans.append(max_item[0])
    if len(ans)==k:
        break
    else:
        if max_item[1]+1<len(a):
            add=(a[max_item[1]+1]+b[max_item[2]]+c[max_item[3]],max_item[1]+1,max_item[2],max_item[3])
            if add not in que:
                que.append(add)
        if max_item[2]+1<len(b):
            add = (a[max_item[1]]+b[max_item[2]+1]+c[max_item[3]],max_item[1],max_item[2]+1,max_item[3])
            if add not in que:
                que.append(add)
        if max_item[3]+1<len(c):
            add = (a[max_item[1]]+b[max_item[2]]+c[max_item[3]+1],max_item[1],max_item[2],max_item[3]+1)
            if add not in que:
                que.append(add)
        que.sort(key=lambda x:x[0])
for i in range(k):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
x,y,z,k=map(int, input().split())#=3,3,3,5
a=list(map(int, input().split()))#=[1,10,100]#
b=list(map(int, input().split()))#=[2,20,200]#
c=list(map(int, input().split()))#=[1,10,100]
a=sorted(a)[::-1]
b=sorted(b)[::-1]
c=sorted(c)[::-1]
que=[(a[0]+b[0]+c[0],0,0,0)]
ans=[]
while True:
    que.sort(key=lambda x:x[0])
    max_item=que.pop()
    ans.append(max_item[0])
    if len(ans)==k:
        break
    else:
        if max_item[1]+1<len(a):
            add=(a[max_item[1]+1]+b[max_item[2]]+c[max_item[3]],max_item[1]+1,max_item[2],max_item[3])
            if add not in que:
                que.append(add)
        if max_item[2]+1<len(b):
            add = (a[max_item[1]]+b[max_item[2]+1]+c[max_item[3]],max_item[1],max_item[2]+1,max_item[3])
            if add not in que:
                que.append(add)
        if max_item[3]+1<len(c):
            add = (a[max_item[1]]+b[max_item[2]]+c[max_item[3]+1],max_item[1],max_item[2],max_item[3]+1)
            if add not in que:
                que.append(add)
for i in range(k):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
import itertools
X,Y,Z,K = list(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)
abc = []
count = 0
for l,m,n in itertools.product(A,B,C):
	if count<=K:
		count+=1
		abc.append(l+m+n)
	else:
		break
for i in range(K):
	print(abc[i])

Submission status: Wrong Answer

Solution code:
import itertools
X,Y,Z,K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
abc = []
for i,j,k in itertools.product(A,B,C):
	abc.append(i+j+k)
abc = list(set(abc))
abc.sort(reverse=True)
for i in range(K):
	print(abc[i])

Submission status: Wrong Answer

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

# 整数の入力
x,y,z,k = map(int,input().split())

# cakea,b,cのおいしさをリストに取得
cakea = list(map(int, input().split()))
cakeb = list(map(int, input().split()))
cakec = list(map(int, input().split()))

# ケーキリストをおいしい順にソートしておく
cakea.sort(reverse=True)
cakeb.sort(reverse=True)
cakec.sort(reverse=True)

oishisa = []

# おいしそうなケーキ候補リスト
sela = []
selb = []
selc = []

# a,b,cから一つずつ、一番おいしいのを候補リストに入れる
sela.append(cakea[0])
selb.append(cakeb[0])
selc.append(cakec[0])
# 候補リストに入れたらケーキリストから削除しておく
del cakea[0]
del cakeb[0]
del cakec[0]

while len(sela) * len(selb) * len(selc) < k:
    # a,b,c のうちおいしそうな順番で候補リストに追加していく
    if len(cakea)>0:
        tmpCakeA = cakea[0]
    else:
        tmpCakeA = -1

    if len(cakeb)>0:
        tmpCakeB = cakeb[0]
    else:
        tmpCakeB = -1
    if len(cakec)>0:
        tmpCakeC = cakec[0]
    else:
        tmpCakeC = -1

    if tmpCakeA > tmpCakeB and tmpCakeA > tmpCakeC:
        sela.append(tmpCakeA)
        del cakea[0]
    elif tmpCakeB > tmpCakeA and tmpCakeB > tmpCakeC:
        selb.append(tmpCakeB)
        del cakeb[0]
    elif tmpCakeC > tmpCakeA and tmpCakeC > tmpCakeB:
        selc.append(tmpCakeC)
        del cakec[0]
    elif tmpCakeA == tmpCakeB or tmpCakeA == tmpCakeC:
        if tmpCakeA > tmpCakeB or tmpCakeA > tmpCakeC:
            sela.append(tmpCakeA)
            del cakea[0]
        elif tmpCakeB > tmpCakeA or tmpCakeB > tmpCakeC:
            selb.append(tmpCakeB)
            del cakeb[0]
        elif tmpCakeC > tmpCakeA or tmpCakeC > tmpCakeB:
            selc.append(tmpCakeC)
            del cakec[0]
    elif tmpCakeA == tmpCakeB and tmpCakeA == tmpCakeC:
        sela.append(tmpCakeA)
        del cakea[0]

# 全部回すと時間かかりすぎ
# for a in range(len(cakea)):
#     for b in range(len(cakeb)):
#         for c in range(len(cakec)):
#             oishisa.append(cakea[a] + cakeb[b] + cakec[c])

for a in range(len(sela)):
    for b in range(len(selb)):
        for c in range(len(selc)):
            oishisa.append(sela[a] + selb[b] + selc[c])

oishisa.sort(reverse=True)

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

Submission status: Wrong Answer

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

# 整数の入力
x,y,z,k = map(int,input().split())

# cakea,b,cのおいしさをリストに取得
cakea = list(map(int, input().split()))
cakeb = list(map(int, input().split()))
cakec = list(map(int, input().split()))

# ケーキリストをおいしい順にソートしておく
cakea.sort(reverse=True)
cakeb.sort(reverse=True)
cakec.sort(reverse=True)

oishisa = []

# おいしそうなケーキ候補リスト
sela = []
selb = []
selc = []

# a,b,cから一つずつ、一番おいしいのを候補リストに入れる
sela.append(cakea[0])
selb.append(cakeb[0])
selc.append(cakec[0])
# 候補リストに入れたらケーキリストから削除しておく
del cakea[0]
del cakeb[0]
del cakec[0]

while len(sela) * len(selb) * len(selc) < k:
    # a,b,c のうちおいしそうな順番で候補リストに追加していく
    if len(cakea)>0:
        tmpCakeA = cakea[0]
    else:
        tmpCakeA = -1

    if len(cakeb)>0:
        tmpCakeB = cakeb[0]
    else:
        tmpCakeB = -1
    if len(cakec)>0:
        tmpCakeC = cakec[0]
    else:
        tmpCakeC = -1

    if tmpCakeA > tmpCakeB and tmpCakeA > tmpCakeC:
        sela.append(tmpCakeA)
        del cakea[0]
    elif tmpCakeB > tmpCakeA and tmpCakeB > tmpCakeC:
        selb.append(tmpCakeB)
        del cakeb[0]
    elif tmpCakeC > tmpCakeA and tmpCakeC > tmpCakeB:
        selc.append(tmpCakeC)
        del cakec[0]
    else:
        if tmpCakeA == tmpCakeB or tmpCakeA == tmpCakeC:
            if tmpCakeA > tmpCakeB or tmpCakeA > tmpCakeC:
                sela.append(tmpCakeA)
                del cakea[0]
            elif tmpCakeB > tmpCakeA or tmpCakeB > tmpCakeC:
                selb.append(tmpCakeB)
                del cakeb[0]
            elif tmpCakeC > tmpCakeA or tmpCakeC > tmpCakeB:
                selc.append(tmpCakeC)
                del cakec[0]

# 全部回すと時間かかりすぎ
# for a in range(len(cakea)):
#     for b in range(len(cakeb)):
#         for c in range(len(cakec)):
#             oishisa.append(cakea[a] + cakeb[b] + cakec[c])

for a in range(len(sela)):
    for b in range(len(selb)):
        for c in range(len(selc)):
            oishisa.append(sela[a] + selb[b] + selc[c])

oishisa.sort(reverse=True)

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

Submission status: Wrong Answer

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

# 整数の入力
x,y,z,k = map(int,input().split())

# cakea,b,cのおいしさをリストに取得
cakea = list(map(int, input().split()))
cakeb = list(map(int, input().split()))
cakec = list(map(int, input().split()))

# ケーキリストをおいしい順にソートしておく
cakea.sort(reverse=True)
cakeb.sort(reverse=True)
cakec.sort(reverse=True)

oishisa = []

# おいしそうなケーキ候補リスト
sela = []
selb = []
selc = []

# a,b,cから一つずつ、一番おいしいのを候補リストに入れる
sela.append(cakea[0])
selb.append(cakeb[0])
selc.append(cakec[0])
# 候補リストに入れたらケーキリストから削除しておく
del cakea[0]
del cakeb[0]
del cakec[0]

while len(sela) * len(selb) * len(selc) < k:
    # a,b,c のうちおいしそうな順番で候補リストに追加していく
    if len(cakea)>0:
        tmpCakeA = cakea[0]
    else:
        tmpCakeA = -1

    if len(cakeb)>0:
        tmpCakeB = cakeb[0]
    else:
        tmpCakeB = -1
    if len(cakec)>0:
        tmpCakeC = cakec[0]
    else:
        tmpCakeC = -1

    if tmpCakeA >= tmpCakeB and tmpCakeA >= tmpCakeC:
        sela.append(tmpCakeA)
        del cakea[0]
    elif tmpCakeB >= tmpCakeA and tmpCakeB >= tmpCakeC:
        selb.append(tmpCakeB)
        del cakeb[0]
    elif tmpCakeC >= tmpCakeA and tmpCakeC >= tmpCakeB:
        selc.append(tmpCakeC)
        del cakec[0]

# 全部回すと時間かかりすぎ
# for a in range(len(cakea)):
#     for b in range(len(cakeb)):
#         for c in range(len(cakec)):
#             oishisa.append(cakea[a] + cakeb[b] + cakec[c])

for a in range(len(sela)):
    for b in range(len(selb)):
        for c in range(len(selc)):
            oishisa.append(sela[a] + selb[b] + selc[c])

oishisa.sort(reverse=True)

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

Submission status: Wrong Answer

Solution code:
x,y,z,k=map(int,input().split())
a_li=list(map(int,input().split()))
b_li=list(map(int,input().split()))
c_li=list(map(int,input().split()))
t=[]
for i in range(0,x):
  for j in range(0,y):
    t.append(a_li[i]+b_li[j])
t.sort()
c_li.sort()
li=[]
len_t=len(t)
len_c_li=len(c_li)
for n in range (0,k):
  t.append(0)
  c_li.append(0)
for m in range(0,k):
  for l in range(0,k):
    li.append(t[m]+c_li[l])
li.sort()
for m in range (0,k):
  print(li[m])

Submission status: Wrong Answer

Solution code:
x,y,z,k=map(int,input().split())
list_a=list(map(int,input().split()))
list_b=list(map(int,input().split()))
list_c=list(map(int,input().split()))
list_a.sort(reverse=True)
list_b.sort(reverse=True)
list_c.sort(reverse=True)
dict_p={}
dict_p[(0,0,0)]=list_a[0]+list_b[0]+list_c[0]
now=0
for i in range(0,k):
    Max=max(dict_p.values())
    print(Max)
    for j in dict_p:
        if dict_p[j]==Max:
            now=j
            dict_p.pop(now)
            break
    if now[0]+1<x:
        dict_p[(now[0]+1,now[1],now[2])]=list_a[now[0]+1]+list_b[now[1]]+list_c[now[2]]
    if now[1]+1<y:
        dict_p[(now[0],now[1]+1,now[2])]=list_a[now[0]]+list_b[now[1]+1]+list_c[now[2]]
    if now[2]+1<z:
        dict_p[(now[0],now[1],now[2]+1)]=list_a[now[0]]+list_b[now[1]]+list_c[now[2]+1]

Submission status: Wrong Answer

Solution code:
x, y, z, K = map(int, input().split())
K = min(x * y * z, K)
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)


def check(p, return_array=False):
    cnt = 0
    results = []
    for i in a:
        for j in b:
            for k in c:
                ijk = i + j + k
                if ijk < p:
                    break
                results.append(ijk)
                cnt += 1
                if cnt >= K:
                    return True, results
    return False, results


left = 10**10 * 3
right = 0

while left - right > 1:
    center = (left + right) // 2
    flg, results = check(center)
    if flg:
        right = center
    else:
        left = center

print("\n".join(map(str, (check(left) if flg else check(right))[1])))

Submission status: Wrong Answer

Solution code:
import heapq
x, y, z, k = map(int, input().split())
k = min(x * y * z, k)
a = sorted(list(map(int, input().split())), reverse=True)[:k]
b = sorted(list(map(int, input().split())), reverse=True)[:k]
c = sorted(list(map(int, input().split())), reverse=True)[:k]

results = []
pque = [(-(a[0] + b[0] + c[0]), (0, 0, 0))]
for _ in range(k):
    value, position = heapq.heappop(pque)
    print(-value)
    results.append(value)
    for pattern in [[0, 0, 1], [0, 1, 0], [1, 0, 0]]:
        i, j, k = [v1 + v2 for v1, v2 in zip(pattern, position)]
        if i < x and j < y and k < z:
            heapq.heappush(pque, (-(a[i] + b[j] + c[k]), (i, j, 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 = sorted(A, reverse=True)[:K+1]
B = sorted(B, reverse=True)[:K+1]
C = sorted(C, reverse=True)[:K+1]
 
res = []
 
for i in A:
    for j in B:
        res.append(i + j)
res2 = []
res = sorted(res, reverse=True)[:K+1]

print(res)
 
for i in C:
    for re in res:
        res2.append(i + re)
        
res2 = sorted(res2, reverse=True)[:K+1]
 
for i in range(K):
    print(res2[i])

Submission status: Wrong Answer

Solution code:
x,y,z,k=map(int,input().split())
list_a=list(map(int,input().split()))
list_b=list(map(int,input().split()))
list_c=list(map(int,input().split()))
list_a.sort(reverse=True)
list_b.sort(reverse=True)
list_c.sort(reverse=True)
dict_p={}
dict_p[(0,0,0)]=list_a[0]+list_b[0]+list_c[0]
for i in range(0,k):
    Max=max(dict_p.values())
    print(Max)
    for j in dict_p:
        if dict_p[j]==Max:
            now=j
            dict_p.pop(j)
            break
    if now[0]+1<x:
        dict_p[(now[0]+1,now[1],now[2])]=list_a[now[0]+1]+list_b[now[1]]+list_c[now[2]]
    if now[1]+1<y:
        dict_p[(now[0],now[1]+1,now[2])]=list_a[now[0]]+list_b[now[1]+1]+list_c[now[2]]
    if now[2]+1<z:
        dict_p[(now[0],now[1],now[2]+1)]=list_a[now[0]]+list_b[now[1]]+list_c[now[2]+1]

Submission status: Wrong Answer

Solution code:
x,y,z,k=map(int,input().split())
list_a=list(map(int,input().split()))
list_b=list(map(int,input().split()))
list_c=list(map(int,input().split()))
list_a.sort(reverse=True)
list_b.sort(reverse=True)
list_c.sort(reverse=True)
dict_p={}
dict_p[(0,0,0)]=list_a[0]+list_b[0]+list_c[0]
for i in range(0,k-1):
    Max=max(dict_p.values())
    print(Max)
    for j in dict_p:
        if dict_p[j]==Max:
            now=j
            dict_p.pop(j)
            break
    if now[0]+1<x:
        dict_p[(now[0]+1,now[1],now[2])]=list_a[now[0]+1]+list_b[now[1]]+list_c[now[2]]
    if now[1]+1<y:
        dict_p[(now[0],now[1]+1,now[2])]=list_a[now[0]]+list_b[now[1]+1]+list_c[now[2]]
    if now[2]+1<z:
        dict_p[(now[0],now[1],now[2]+1)]=list_a[now[0]]+list_b[now[1]]+list_c[now[2]+1]
Max=max(dict_p.values())
print(Max)