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())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
cc = list(map(int, input().split()))

aa.sort()
aa = aa[:k]
bb.sort()
bb = bb[:k]
cc.sort()
cc = cc[:k]

from itertools import product
dd = list(sum(p) for p in product(aa, bb, cc))
dd.sort()
dd = dd[:k]
print(*dd[::-1], sep='\n')

Submission status: Wrong Answer

Solution code:
X, Y, Z, K = (int(n) for n in input().split())
nums_x = [int(x) for x in input().split()]
nums_y = [int(y) for y in input().split()]
nums_z = [int(z) for z in input().split()]

nums_x = sorted(nums_x)
nums_y = sorted(nums_y)
nums_z = sorted(nums_z)

ans = []

s_x = [nums_x.pop()]
s_y = [nums_y.pop()]
s_z = [nums_z.pop()]

x, y, z = 0, 0, 0
while (nums_x or nums_y or nums_z) and len(s_x) * len(s_y) * len(s_z) < K:
  x = nums_x.pop() if not x and len(nums_x) else 0
  y = nums_y.pop() if not y and len(nums_y) else 0
  z = nums_z.pop() if not z and len(nums_z) else 0
  if x >= max(y,z): 
    s_x.append(x)
    x = 0
  elif y >= z:
    s_y.append(y)
    y = 0
  else:
    s_z.append(z)
    z = 0
    
for x in s_x:
  for y in s_y:
    for z in s_z:
      ans.append(z+y+x)

for v in sorted(ans, reverse=True)[:K]:
  print(v)

Submission status: Wrong Answer

Solution code:
X, Y, Z, K = (int(n) for n in input().split())
nums_x = [int(x) for x in input().split()]
nums_y = [int(y) for y in input().split()]
nums_z = [int(z) for z in input().split()]

nums_x = sorted(nums_x, reverse=True)[:15]
nums_y = sorted(nums_y, reverse=True)[:15]
nums_z = sorted(nums_z, reverse=True)[:15]

ans = []
for x in nums_x:
  for y in nums_y:
    for z in nums_z:
      ans.append(z+y+x)
for v in sorted(ans, reverse=True)[:K]:
  print(v)

Submission status: Wrong Answer

Solution code:
*xyz,K = map(int,input().split())
abc = []
for i in range(3):
    abc.append(list(map(int,input().split())))
    abc[i].sort(reverse=1)
    abc[i] = abc[i][:min(xyz[i],15)]
from itertools import product as pro
ans = []
for a in pro(abc[0],abc[1],abc[2]):
    ans.append(int(a[0])+int(a[1])+int(a[2]))
ans.sort(reverse=1)
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()]
a = sorted(a,reverse=True)
b = [int(j) for j in input().split()]
b = sorted(b,reverse=True)
c = [int(k) for k in input().split()]
c = sorted(c,reverse=True)

H = []
for i in range(0,X):
    for j in range(0,Y):
        for k in range(0,Z):
            if (i+1) * (j+1) * (k+1) <= K:
                H.append(a[i]+b[j]+c[k])
sorted(H,reverse = True)

for i in range(0,K):
    print(H[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()]
AB = []
for a in A:
    for b in B:
        AB.append(a+b)
AB.sort(reverse=True)
ABC = []
for ab in AB[:K]:
    for c in C:
        ABC.append(ab+c)
ABC.sort(reverse=True)
print([i for i in ABC[:K]])

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()]
AB = []
for a in A:
    for b in B:
        AB.append(a+b)
AB.sort(reverse=True)
ABC = []
for ab in AB[:K]:
    for c in C:
        ABC.append(ab+c)
ABC.sort(reverse=True)
print(ABC[:K])

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)
dA = [A[0] - A[i+1] for i in range(X-1)]
dB = [B[0] - B[i+1] for i in range(Y-1)]
dC = [C[0] - C[i+1] for i in range(Z-1)]

def get(x, y, z):
    s = 0
    if x >= X or y >= Y or z >= Z:
        return None

    s += dA[x-1]
    s += dB[y-1]
    s += dC[z-1]
    return s


import numpy as np

arrived = []
keys = [[np.array([0, 0, 0], dtype=np.int), 0]]

for i in range(K):
    cur = keys.pop(0)
    print(A[cur[0][0]] + B[cur[0][1]] + C[cur[0][2]])
    for v in np.eye(3, dtype=np.int):
        t = get(*(cur[0] + v))
        if t is None or str(cur[0] + v) in arrived:
            continue
        keys.append([cur[0] + v, t])
        arrived.append(str(cur[0] + v))
    keys.sort(key=lambda x: x[1])

Submission status: Wrong Answer

Solution code:
x,y,z,k=map(int,input().split())
a=[int(i)for i in input().split()]+[0]*49
b=[int(i)for i in input().split()]+[0]*49
c=[int(i)for i in input().split()]+[0]*49
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
ans=[]
C=1
for A in range(49):
    for B in range(49):
        for C in range(49):
            AA=a[A]
            BB=b[B]
            CC=c[C]
            if AA==0 or BB==0 or CC==0:
                break
            ans+=[AA+BB+CC]
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])

Submission status: Wrong Answer

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

list_xy = []
for i in range(x):
    for j in range(y):
        list_xy.append(int(a[i]+b[j]))
list_xy.sort()
#print(list_xy)
list_xy.reverse()
#print(list_xy)
if len(list_xy) < k:
    m = int(len(list_xy))
else:
    m = k
list_xyk = list_xy[0:m]
list_xyz = []
for i in range(m):
    for j in range(z):
        list_xyz.append(int(list_xyk[i]+c[j]))
list_xyz.sort()
list_xyz.reverse()
list_xyzk = list_xyz[0:k]
print(list_xyzk)

Submission status: Wrong Answer

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


def sum_(kouho):
    a, b, c = kouho
    return sum([A[a], B[b], C[c]])

kouhos = []

kouhos = [[0, 0, 0]]
cur = kouhos[0]
sum_cur = sum_(cur)
kouhos_vals = [sum_cur]
all_ = {}
all_[sum_cur] = [cur]

def add_kouhos(kouhos, kouhos_vals, new_kouhos):
    if len(kouhos) == 0:
        kouhos = new_kouhos
        kouhos_vals = [sum_(kouho) for kouho in new_kouhos]
        return kouhos, kouhos_vals

    len_kouhos = len(kouhos)

    new_i = 1
    new_kouho = new_kouhos[-new_i] # 後ろ(小さいkouho)から追加していく
    sum_new_kouho = sum_(new_kouho)

    n_kouhos = len(new_kouhos)

    last_kouho_i = len_kouhos - 1
    while True:
        if sum_new_kouho <= sum_(kouhos[-1]):
            #kouhos.append(new_kouho)
            kouhos.insert(last_kouho_i+1, new_kouho)
            new_i += 1
            if new_i == n_kouhos+1:
                return kouhos, kouhos_vals        
            new_kouho = new_kouhos[-new_i]
            sum_new_kouho = sum_(new_kouho)
        else:
            break

    for cur_kouho_i in reversed(range(0, len_kouhos)):
        loop = True
        sum_cur_kouho = sum_(kouhos[cur_kouho_i])
        while loop:
            if sum_new_kouho < sum_cur_kouho: # 下からkouhosを辿って行き、超えられなかった一つ手前にinsert
                kouhos.insert(cur_kouho_i+1, new_kouho)
                kouhos_vals.insert(cur_kouho_i+1, sum_(new_kouho))
                new_i += 1
                if new_i == n_kouhos+1:
                    return kouhos, kouhos_vals
                new_kouho = new_kouhos[-new_i]
                sum_new_kouho = sum_(new_kouho)
            else:
                loop = False

    while True:
        kouhos.insert(0, new_kouho) # ひたすら先頭にnew_kouhosを小さいものから追加していく
        kouhos_vals.insert(0, sum_new_kouho)
        new_i += 1
        if new_i == n_kouhos+1:
            return kouhos, kouhos_vals
        else:
            new_kouho = new_kouhos[-new_i]
            sum_new_kouho = sum_(new_kouho)

def make_new_kouhos(all_):
    new_kouhos = []
    tmp_dict = {}
    for i in range(3):
        new_kouho = cur.copy()
        new_kouho[i] += 1

        prop_new_kouho = new_kouho
        
        cond2 = new_kouho[i] < Xs[i]
        if not cond2:
            continue
        sum_val = sum_(prop_new_kouho)
        
        #cond11 = sum_val not in all_.keys()
        #cond11 = sum_val not in all_.keys()
        try:
            all[sum_val]
            cond11 = False
        except:
            cond11 = True

        if cond11:
            cond1 = cond11
        else:
            cond12 = new_kouho not in all_[sum_val]
            cond1 = cond12
        
        if cond1: # ここが計算大
            new_kouhos.append(new_kouho)
            tmp_dict[tuple(new_kouho)] = sum_val
            if cond11:
                all_[sum_val] = [new_kouho]
            else:
                all_[sum_val].append(new_kouho)
    new_kouhos = sorted(new_kouhos, key=lambda x:-tmp_dict[tuple(x)]) ## 案
    return all_, new_kouhos

for _ in range(K):
    cur = kouhos[0]
    print(sum_(cur))
    kouhos = kouhos[1:]
    kouhos_vals = kouhos_vals[1:]

    all_, new_kouhos = make_new_kouhos(all_)

    if len(new_kouhos) > 0:
        kouhos, kouhos_vals = add_kouhos(kouhos, kouhos_vals, new_kouhos)

Submission status: Wrong Answer

Solution code:
import heapq
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

X, Y, Z, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))


def calc(x, y, z):
    return [-A[x]-B[y]-C[z], x, y, z]


def solve1(A, B, C, X, Y, Z, k):
    A = sorted(A, reverse=True)
    B = sorted(B, reverse=True)
    C = sorted(C, reverse=True)
    Q = []
    Q.append(calc(0, 0, 0))

    ans = []
    # dict
    memo = {(0, 0, 0): True}
    for _ in range(k):
        e, x, y, z = heapq.heappop(Q)
        ans.append(-e)
        if x+1 < X and (x+1, y, z) not in memo:
            heapq.heappush(Q, calc(x+1, y, z))
            memo[(x+1, y, z)] = True
        if y+1 < Y and (x, y+1, z) not in memo:
            heapq.heappush(Q, calc(x, y+1, z))
            memo[(x, y+1, z)] = True

        if z+1 < Z and (x, y, z+1) not in memo:
            heapq.heappush(Q, calc(x, y, z+1))
            memo[(x, y, z+1)] = True

    print("\n".join(map(str, ans[:k])))


solve1(A, B, C, X, Y, Z, k)

Submission status: Wrong Answer

Solution code:
import heapq
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

X, Y, Z, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))


def calc(x, y, z):
    return [-A[x]-B[y]-C[z], x, y, z]


def solve1(A, B, C, X, Y, Z, k):
    A = sorted(A, reverse=True)
    B = sorted(B, reverse=True)
    C = sorted(C, reverse=True)
    Q = []
    Q.append(calc(0, 0, 0))

    ans = []
    # dict
    memo = {(0, 0, 0): True}
    for _ in range(k):
        e, x, y, z = heapq.heappop(Q)
        ans.append(-e)
        if x+1 < X and (x+1, y, z) not in memo:
            heapq.heappush(Q, calc(x+1, y, z))
            memo[(x+1, y, z)] = True
        if y+1 < Y and (x, y+1, z) not in memo:
            heapq.heappush(Q, calc(x, y+1, z))
            memo[(x, y+1, z)] = True

        if z+1 < Z and (x, y, z+1) not in memo:
            heapq.heappush(Q, calc(x, y, z+1))
            memo[(x, y, z+1)] = True

    print("\n".join(map(str, sorted(ans[:k], reverse=True))))


solve1(A, B, C, X, Y, Z, k)

Submission status: Wrong Answer

Solution code:
import heapq
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

X, Y, Z, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))


def calc(x, y, z):
    return [-A[x]-B[y]-C[z], x, y, z]


def solve1(A, B, C, X, Y, Z, k):
    A = sorted(A, reverse=True)
    B = sorted(B, reverse=True)
    C = sorted(C, reverse=True)
    Q = []
    Q.append(calc(0, 0, 0))

    ans = []
    # dict
    memo = {(0, 0, 0): True}
    for _ in range(k):
        e, x, y, z = heapq.heappop(Q)
        ans.append(-e)
        if x+1 < X and (x+1, y, z) not in memo:
            heapq.heappush(Q, calc(x+1, y, z))
            memo[(x+1, y, z)] = True
        if y+1 < Y and (x, y+1, z) not in memo:
            heapq.heappush(Q, calc(x, y+1, z))
            memo[(x, y+1, z)] = True

        if z+1 < Z and (x, y, z+1) not in memo:
            heapq.heappush(Q, calc(x, y, z+1))
            memo[(x, y, z+1)] = True

    print("\n".join(map(str, sorted(ans, reverse=True))))


solve1(A, B, C, X, Y, Z, k)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import re

x,y,z,n=map(int,input().split())#標準入力を行う

X_list=input()
X_list = re.split(" ", X_list)
for i in range(x):
    X_list[i] = int(X_list[i])

Y_list=input()
Y_list = re.split(" ", Y_list)
for i in range(x):
    Y_list[i] = int(Y_list[i])

Z_list=input()
Z_list = re.split(" ", Z_list)
for i in range(x):
    Z_list[i] = int(Z_list[i])


Cake_point = []
for i in range(x):
    for j in range(y):
        for k in range(z):
            Cake_point.append(X_list[i] + Y_list[j] + Z_list[k])

Cake_point.sort(reverse=True)

for i in range(x*y*z):
    print(Cake_point[i])

Submission status: Wrong Answer

Solution code:
S = input()
correct_case1 = "".join(["0" if i%2 == 0 else "1" for i in range(len(S))])
correct_case2 = "".join(["0" if i%2 == 1 else "1" for i in range(len(S))])
c1 = 0
c2 = 0
for i in range(len(S)):
  if correct_case1[i] != S[i]:
    c1 += 1
  if correct_case2[i] != S[i]:
    c2 += 1
print(min([c1, c2]))

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)

p=q=r=0
listlist=[[p,q,r]]
numlist=[a[p]+b[q]+c[r]]
listlistdone=[]

for yy in range(k):
    maxtemp=max(numlist)

    print(maxtemp)
    p,q,r=listlist[numlist.index(maxtemp)][0],listlist[numlist.index(maxtemp)][1],listlist[numlist.index(maxtemp)][2]
    listlistdone.append(listlist[numlist.index(maxtemp)])
    del listlist[numlist.index(maxtemp)]
    numlist.remove(maxtemp)
        
    temp=[p+1,q,r]
    if p<=x-2 and (temp not in listlistdone):
        appendflag=True
        for xx in listlist:
            if (temp[0]==xx[0] and temp[1]==xx[1])or (temp[0]==xx[0] and temp[2]==xx[2])or (temp[1]==xx[1] and temp[2]==xx[2]):
                appendflag=False
        if appendflag==True: 
            listlist.append(temp)
            numlist.append(a[p+1]+b[q]+c[r])
        
    temp=[p,q+1,r]
    if q<=y-2 and (temp not in listlistdone):
        appendflag=True
        for xx in listlist:
            if (temp[0]==xx[0] and temp[1]==xx[1])or (temp[0]==xx[0] and temp[2]==xx[2])or (temp[1]==xx[1] and temp[2]==xx[2]):
                appendflag=False
        if appendflag==True:
            listlist.append(temp)
            numlist.append(a[p]+b[q+1]+c[r])
    
    temp=[p,q,r+1]
    if r<=z-2 and (temp not in listlistdone):
        appendflag=True
        for xx in listlist:
            if (temp[0]==xx[0] and temp[1]==xx[1])or (temp[0]==xx[0] and temp[2]==xx[2])or (temp[1]==xx[1] and temp[2]==xx[2]):
                appendflag=False
        if appendflag==True:
            listlist.append(temp)
            numlist.append(a[p]+b[q]+c[r+1])

Submission status: Wrong Answer

Solution code:
X, Y, Z, K = list(map(int,input().split()))
ALPHA = []
for i in range(3):
    ALPHA.append(sorted(list(map(int,input().split())), reverse=True))

counter = 0
p_queue = []
p_queue.append([0, 0, 0, sum([x[0] for x in ALPHA])])
while True:
    if len(p_queue) == 0:
        break
    p_queue.sort(key=lambda x: x[3])
    max_choice = p_queue.pop(-1)
    print(max_choice[3])
    counter += 1
    if counter == K:
        break
    if max_choice[0] + 1 < X:
        item = [max_choice[0]+1, max_choice[1], max_choice[2], \
                    max_choice[3] - ALPHA[0][max_choice[0]] + ALPHA[0][max_choice[0] + 1]]
        if item not in p_queue:
            p_queue.append(item)
    if max_choice[1]+1 < Y:
        item = [max_choice[0], max_choice[1]+1, max_choice[2], \
                    max_choice[3] - ALPHA[1][max_choice[1]] + ALPHA[1][max_choice[1] + 1]]
        if item not in p_queue:
            p_queue.append(item)
    if max_choice[2]+1 < Z:
        item = [max_choice[0], max_choice[1], max_choice[2]+1, \
                    max_choice[3] - ALPHA[2][max_choice[2]] + ALPHA[2][max_choice[2] + 1]]
        if item not in p_queue:
            p_queue.append(item)

Submission status: Wrong Answer

Solution code:
X, Y, Z, K = list(map(int,input().split()))
ALPHA = []
for i in range(3):
    ALPHA.append(sorted(list(map(int,input().split())), reverse=True))

counter = 0
p_queue = []
p_queue.append([0, 0, 0, sum([x[0] for x in ALPHA])])
while True:
    if len(p_queue) == 0:
        break
    p_queue.sort(key=lambda x: x[3])
    max_choice = p_queue.pop(-1)
    print(max_choice[3])
    counter += 1
    if counter == K:
        break
    if max_choice[0] + 1 < X:
        item = [max_choice[0]+1, max_choice[1], max_choice[2], \
                    ALPHA[0][max_choice[0] + 1] \
                    + ALPHA[1][max_choice[1]] \
                    + ALPHA[2][max_choice[2]]]
        if item not in p_queue:
            p_queue.append(item)
    if max_choice[1]+1 < Y:
        item = [max_choice[0], max_choice[1]+1, max_choice[2], \
                    ALPHA[0][max_choice[0]] \
                    + ALPHA[1][max_choice[1]+1] \
                    + ALPHA[2][max_choice[2]]]
        if item not in p_queue:
            p_queue.append(item)
    if max_choice[2]+1 < Z:
        item = [max_choice[0], max_choice[1], max_choice[2]+1, \
                    ALPHA[0][max_choice[0]] \
                    + ALPHA[1][max_choice[1]] \
                    + ALPHA[2][max_choice[2]+1]]
        if item not in p_queue:
            p_queue.append(item)

Submission status: Wrong Answer

Solution code:
X, Y, Z, K = list(map(int,input().split()))
ALPHA = []
for i in range(3):
    ALPHA.append(sorted(list(map(int,input().split())), reverse=True))

counter = 0
p_queue = []
p_queue.append([0, 0, 0, sum([x[0] for x in ALPHA])])
while True:
    p_queue.sort(key=lambda x: x[3])
    max_choice = p_queue.pop(-1)
    print(max_choice[3])
    counter += 1
    if counter == K:
        break
    if max_choice[0] + 1 < X:
        item = [max_choice[0]+1, max_choice[1], max_choice[2], \
                    ALPHA[0][max_choice[0] + 1] \
                    + ALPHA[1][max_choice[1]] \
                    + ALPHA[2][max_choice[2]]]
        if item not in p_queue:
            p_queue.append(item)
    if max_choice[1]+1 < Y:
        item = [max_choice[0], max_choice[1]+1, max_choice[2], \
                    ALPHA[0][max_choice[0]] \
                    + ALPHA[1][max_choice[1]+1] \
                    + ALPHA[2][max_choice[2]]]
        if item not in p_queue:
            p_queue.append(item)
    if max_choice[2]+1 < Z:
        item = [max_choice[0], max_choice[1], max_choice[2]+1, \
                    ALPHA[0][max_choice[0]] \
                    + ALPHA[1][max_choice[1]] \
                    + ALPHA[2][max_choice[2]+1]]
        if item not in p_queue:
            p_queue.append(item)

Submission status: Wrong Answer

Solution code:
inputs = [[int(i) for i in input().split()] for i in range(4)]
X, Y, Z, K = tuple(inputs[0])
AA, BB, CC = tuple(inputs[1:])
dd = [0,0,0]

for XX in [AA, BB, CC]:
    XX.sort(reverse=True)
i = 0
while True:
    s=AA[0]+BB[0]+CC[0]
    print(s)
    i += 1
    if i >= K:
        break
    for j, XX in enumerate([AA, BB, CC]):
        if len(XX)>=2:
            dd[j] = XX[0] - XX[1]
        else:
            dd[j] = -1
    dd.sort()
    for d in dd:
        if d >= 0:
            print(s-d)
            i += 1
            if i >= K:
                break
    if dd[0] >= 0:
        AA = AA[1:]
    if dd[1] >= 0:
        BB = BB[1:]
    if dd[2] >= 0:
        CC = CC[1:]

Submission status: Wrong Answer

Solution code:
numbers = input().split()
x = input().split()
y = input().split()
z = input().split()

k = int(numbers[3])
x.sort(reverse=True)
y.sort(reverse=True)
z.sort(reverse=True)

answer = []
for i in x:
    for j in y:
        price = int(i)+int(j)
        answer.append(price)
del answer[k::]
f_ans = []
for m in answer:
    for n in z:
        price = m + int(n)
        f_ans.append(price)


f_ans.sort(reverse=True)
del f_ans[k::]

for l in f_ans:
    print(l)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify

X, Y, Z, K = list(map(int, input().split()))
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

A_list.sort(reverse=True)
B_list.sort(reverse=True)
C_list.sort(reverse=True)

class Value():
  def __init__(self, A_list, B_list, C_list, a_idx, b_idx, c_idx):
    self.A = A_list[a_idx]
    self.B = B_list[b_idx]
    self.C = C_list[c_idx]
    self.a_idx = a_idx
    self.b_idx = b_idx
    self.c_idx = c_idx
    self.value = - (self.A + self.B + self.C)
  def __eq__(self, other):
    return self.a_idx == other.a_idx and self.b_idx == other.b_idx and self.c_idx == other.c_idx
  def __gt__(self, other):
    return self.value > other.value
  def __ge__(self, other):
    return self.value >= other.value
  def __lt__(self, other):
    return not self.__ge__(other)
  def __le__(self, other):
    return not self.__gt__(other)
    
que = []
heapify(que)
heappush(que, (Value(A_list, B_list, C_list, 0, 0, 0)))

for _ in range(K):
  if que:
    v = heappop(que)
    print(- v.value)
  new_v_list = []
  if v.a_idx < X - 1:
    new_v = Value(A_list, B_list, C_list, v.a_idx + 1, v.b_idx, v.c_idx)
    if not new_v in que: 
      heappush(que, new_v)
  if v.b_idx < Y - 1:
    new_v = Value(A_list, B_list, C_list, v.a_idx, v.b_idx + 1, v.c_idx)
    if not new_v in que:
      heappush(que, new_v)
  if v.c_idx < Z - 1:
    new_v = Value(A_list, B_list, C_list, v.a_idx, v.b_idx, v.c_idx + 1)
    if not new_v in que:
      heappush(que, new_v)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop

X, Y, Z, K = list(map(int, input().split()))
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

A_list.sort(reverse=True)
B_list.sort(reverse=True)
C_list.sort(reverse=True)

class Value():
  def __init__(self, A_list, B_list, C_list, a_idx, b_idx, c_idx):
    self.A = A_list[a_idx]
    self.B = B_list[b_idx]
    self.C = C_list[c_idx]
    self.a_idx = a_idx
    self.b_idx = b_idx
    self.c_idx = c_idx
    self.value = - (self.A + self.B + self.C)
  def __eq__(self, other):
    return self.a_idx == other.a_idx and self.b_idx == other.b_idx and self.c_idx == other.c_idx
  def __gt__(self, other):
    return self.value > other.value
  def __ge__(self, other):
    return self.value >= other.value
  def __lt__(self, other):
    return not self.__ge__(other)
  def __le__(self, other):
    return not self.__gt__(other)
    
que = []
heappush(que, (Value(A_list, B_list, C_list, 0, 0, 0)))

for _ in range(K):
  if que:
    v = heappop(que)
    print(- v.value)
  new_v_list = []
  if v.a_idx < X - 1:
    new_v = Value(A_list, B_list, C_list, v.a_idx + 1, v.b_idx, v.c_idx)
    if not new_v in que: 
      heappush(que, new_v)
  if v.b_idx < Y - 1:
    new_v = Value(A_list, B_list, C_list, v.a_idx, v.b_idx + 1, v.c_idx)
    if not new_v in que:
      heappush(que, new_v)
  if v.c_idx < Z - 1:
    new_v = Value(A_list, B_list, C_list, v.a_idx, v.b_idx, v.c_idx + 1)
    if not new_v in que:
      heappush(que, new_v)

Submission status: Wrong Answer

Solution code:
numbers = input().split()
x = input().split()
y = input().split()
z = input().split()

k = int(numbers[3])


def cutting(c):
    if len(c) > 19:
        del c[20::]


x.sort(reverse=True)
cutting(x)
y.sort(reverse=True)
cutting(y)
z.sort(reverse=True)
cutting(z)

answer = []

for i in x:
    for j in y:
        for m in z:
            price = int(i)+int(j)+int(m)
            answer.append(price)

answer.sort(reverse=True)
del answer[int(numbers[3])::]

for l in answer:
    print(l)

Submission status: Wrong Answer

Solution code:
numbers = input().split()
x = input().split()
y = input().split()
z = input().split()

k = int(numbers[3])


def cutting(c):
    if len(c) > 14:
        del c[15::]


x.sort(reverse=True)
cutting(x)
y.sort(reverse=True)
cutting(y)
z.sort(reverse=True)
cutting(z)

answer = []

for i in x:
    for j in y:
        for m in z:
            price = int(i)+int(j)+int(m)
            answer.append(price)

answer.sort(reverse=True)
del answer[int(numbers[3])::]

for l in answer:
    print(l)

Submission status: Wrong Answer

Solution code:
numbers = input().split()
x = input().split()
y = input().split()
z = input().split()

k = int(numbers[3])

x.sort(reverse=True)
if len(x) > k:
    del x[k::]
y.sort(reverse=True)
if len(y) > k:
    del y[k::]
z.sort(reverse=True)
if len(z) > k:
    del z[k::]

answer = []

for i in x:
    for j in y:
        price = int(i)+int(j)
        answer.append(price)
del answer[k::]
f_ans = []
for m in answer:
    for n in z:
        #print(m, n)
        price = m + int(n)
        f_ans.append(price)


f_ans.sort(reverse=True)
del f_ans[int(numbers[3])::]

for l in f_ans:
    print(l)

Submission status: Wrong Answer

Solution code:
numbers = input().split()
x = input().split()
y = input().split()
z = input().split()

k = int(numbers[3])

x.sort(reverse=True)
if len(x) > k:
    del x[k::]
y.sort(reverse=True)
if len(y) > k:
    del y[k::]
z.sort(reverse=True)
if len(z) > k:
    del z[k::]

answer = []

for i in x:
    for j in y:
        price = int(i)+int(j)
        answer.append(price)
answer[k::]

for m, mn in enumerate(z):
    price = answer[m] + int(mn)
    answer.append(price)

answer.sort(reverse=True)
del answer[int(numbers[3])::]

for l in answer:
    print(l)

Submission status: Wrong Answer

Solution code:
r=range;x,y,z,k=map(int,input().split())
a,b,c=eval("list(map(int,input().split())), "*3)
abc=[]
for l in r(x):
 for m in r(y):
  if -~l*-~m>k:break
  for n in r(z):
   if -~l*-~m*-~n>k:break
   abc+=[a[l]+b[m]+c[n]]
print(*sorted(abc,reverse=True)[:k])

Submission status: Wrong Answer

Solution code:
def ii2ss(n):
    ss = []
    for i in range(n):
        ss.append(input())
    return ss

def sp2nn(sp, sep=' '):
    return [int(s) for s in sp.split(sep)]

def ss2nn(ss):
    return [int(s) for s in list(ss)]
# 美味しさの合計が 𝑷 以上である個数が 𝑲 個以上あるかどうかを高速判定する方法
# 枝刈り全探索
# borderを見つけたい場合、return Trueなら 𝑷 を大きく、さもなくば小さく
def solve(A, B, C, P, K):
    nn = []
    for a in A:
        for b in B:
            for c in C:
                n = a + b + c
                if n < P:
                    break
                nn.append(n)
                if len(nn) >= K:
                    return nn
    return None

def recLarger(nmin, nmax, larger):
    if nmin >= nmax:
        return nmin
    n = int((nmin + nmax) / 2)
    if larger(n):
        return recLarger(n + 1, nmax, larger)
    else:
        return recLarger(nmin, n, larger)

def main(ss):
    X, Y, Z, K = sp2nn(ss[0])
    A = sp2nn(ss[1])
    B = sp2nn(ss[2])
    C = sp2nn(ss[3])
    A.sort()
    A.reverse()
    B.sort()
    B.reverse()
    C.sort()
    C.reverse()
    
    fn = lambda n: solve(A, B, C, n, K) is not None
    border = recLarger(0, A[0] + B[0] + C[0], fn)
    nn = solve(A, B, C, border-1, K)
    nn.sort()
    nn.reverse()
    for i in range(K):
        print(nn[i])
main(ii2ss(4))

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 = []
for i in range(x):
  for j in range(min(y, -(-k // (i + 1)) + 1)):
    ab.append(a[i] + b[j])
ab = sorted(ab, reverse=True)

abc = []
for i in range(min(k, len(ab))):
  for j in range(min(z, -(-k // (i + 1)) + 1)):
    abc.append(ab[i] + c[j])
abc = sorted(abc, 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()))

ab = []
for i in range(x):
  for j in range(min(y, -(-k // (i + 1)) + 1)):
    ab.append(a[i] + b[j])
ab = sorted(ab, reverse=True)

abc = []
for i in range(min(k, len(ab))):
  for j in range(z):
    abc.append(ab[i] + c[j])
abc = sorted(abc, reverse=True)

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