Problem: 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.

Submission attempts (in order):
x,y,z,k = [int(num) for num in input().split()]

a_cake,b_cake,c_cake = [sorted([int(num) for num in input().split()],reverse=True)[:k] for _ in range(3)]


diff_list = list()
for cake in [a_cake,b_cake,c_cake]:
        diff_list.extend(list(map(lambda x:cake[0]-x,cake)))

diff_list.sort()
cake_max = a_cake[0]+b_cake[0]+c_cake[0]
for diff in diff_list[:k]:
    print(cake_max-diff)

    


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

a_cake,b_cake,c_cake = [sorted([int(num) for num in input().split()],reverse=True)[:k] for _ in range(3)]


diff_list = [0]
for cake in [a_cake,b_cake,c_cake]:
        
        diff_list.extend(list(map(lambda x:cake[0]-x,cake))[1:k])

diff_list.sort()
cake_max = a_cake[0]+b_cake[0]+c_cake[0]
for diff in diff_list:
    print(cake_max-diff)

    


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

a_cake,b_cake,c_cake = [sorted([int(num) for num in input().split()],reverse=True)[:k] for _ in range(3)]


diff_list = [0]
for cake in [a_cake,b_cake,c_cake]:
        
        diff_list.extend(list(map(lambda x:cake[0]-x,cake))[1:k])

diff_list.sort()
cake_max = a_cake[0]+b_cake[0]+c_cake[0]
for diff in diff_list[:k]:
    print(cake_max-diff)

    


x,y,z,k = [int(num) for num in input().split()]
a_cake,b_cake,c_cake = [sorted([int(num) for num in input().split()],reverse=True) for _ in range(3)]

sum_cake = sorted([a+b+c for a in a_cake for b in b_cake for c in c_cake],reverse=True)[:k]
print(sum_cake)

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

cakes_types = [[int(i) for i in input().split()] for _ in range(3)]


for types in cakes_types:
    types.extend([0 for _ in range(max(x,y,z)-len(types))])
    types.sort(reverse=True)

sum_list = list()

for i in range(k):
    sum_taste = 0;
    for j in range(3):
        sum_taste += cakes_types[j][i]
    sum_list.append(sum_taste)

print(sum_list)

x,y,z,k = [int(num) for num in input().split()]
a_cake,b_cake,c_cake = [sorted([int(num) for num in input().split()],reverse=True)[:k] for _ in range(3)]

sum_cake=list()
for i,a in enumerate(a_cake,1):
    for j,b in enumerate(b_cake,1):
        if(i*j>k):
            break
        for n,c in enumerate(c_cake,1):
            if(i*j*n>k):
                break
            sum_cake.append(a+b+c)


sum_cake.sort(reverse=True)

for i in sum_cake[:k]:
    print(i)




Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Accepted