Problem:


Score: 400 points

Problem Statement

The Patisserie AtCoder sells cakes with number-shaped candles.
There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively.
Each cake has an integer value called deliciousness, as follows:

The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.

The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.

The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.

Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.

There are X \times Y \times Z such ways to choose three cakes.

We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.

Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Constraints

1 \leq X \leq 1 \ 000

1 \leq Y \leq 1 \ 000

1 \leq Z \leq 1 \ 000

1 \leq K \leq \min(3 \ 000, X \times Y \times Z)

1 \leq A_i \leq 10 \ 000 \ 000 \ 000

1 \leq B_i \leq 10 \ 000 \ 000 \ 000

1 \leq C_i \leq 10 \ 000 \ 000 \ 000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z

Output

Print K lines. The i-th line should contain the i-th value stated in the problem statement.

Sample Input 1

2 2 2 8
4 6
1 5
3 8

Sample Output 1

19
17
15
14
13
12
10
8

There are 2 \times 2 \times 2 = 8 ways to choose three cakes, as shown below in descending order of the sum of the deliciousness of the cakes:

(A_2, B_2, C_2): 6 + 5 + 8 = 19

(A_1, B_2, C_2): 4 + 5 + 8 = 17

(A_2, B_1, C_2): 6 + 1 + 8 = 15

(A_2, B_2, C_1): 6 + 5 + 3 = 14

(A_1, B_1, C_2): 4 + 1 + 8 = 13

(A_1, B_2, C_1): 4 + 5 + 3 = 12

(A_2, B_1, C_1): 6 + 1 + 3 = 10

(A_1, B_1, C_1): 4 + 1 + 3 = 8

Sample Input 2

3 3 3 5
1 10 100
2 20 200
1 10 100

Sample Output 2

400
310
310
301
301

There may be multiple combinations of cakes with the same sum of the deliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and the sum of A_3, B_3, C_1 are both 301.
However, they are different ways of choosing cakes, so 301 occurs twice in the output.

Sample Input 3

10 10 10 20
7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488
1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338
4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736

Sample Output 3

23379871545
22444657051
22302177772
22095691512
21667941469
21366963278
21287912315
21279176669
21160477018
21085311041
21059876163
21017997739
20703329561
20702387965
20590247696
20383761436
20343962175
20254073196
20210218542
20150096547

Note that the input or output may not fit into a 32-bit integer type.



Sample input:
2 2 2 8
4 6
1 5
3 8


Sample output:
19
17
15
14
13
12
10
8

Submission status: Wrong Answer

Solution code:
x, y, z, k = map(int, input().split())
a = sorted(list(map(int, input().split())),reverse=True)
b = sorted(list(map(int, input().split())),reverse=True)
c = sorted(list(map(int, input().split())),reverse=True)
useA = [a.pop(0)]
useB = [b.pop(0)]
useC = [c.pop(0)]
if len(a) == 0:
  a.append(0)
if len(b) == 0:
  b.append(0)
if len(c) == 0:
  c.append(0)
while True:
  if a[0] == b[0] == c[0] == 0:
    break
  if a[0] >= b[0] and a[0] >= c[0]:
    useA.append(a.pop(0))
    if len(a) == 0:
      a.append(0)
  elif b[0] >= a[0] and b[0] >= c[0]:
    useB.append(b.pop(0))
    if len(b) == 0:
      b.append(0)
  elif c[0] >= b[0] and c[0] >= a[0]:
    useC.append(c.pop(0))
    if len(c) == 0:
      c.append(0)
#  print( len(useA) * len(useB) * len(useC))
  if useA[-1] + useB[-1] >= useA[-1] + b[0] + useC[-1] or useA[-1] + useB[-1] >= useB[-1] + a[0] + useC[-1]:
    if c[0] != 0:
      useC.extend(c)
      c = [0]
  if useA[-1] + useC[-1] >= useA[-1] + c[0] + useB[-1] or useA[-1] + useC[-1] >= useB[-1] + a[0] + useC[-1]:
    if b[0] != 0:
      useB.extend(b)
      b = [0]
  if useB[-1] + useC[-1] >= useA[-1] + c[0] + useB[-1] or useB[-1] + useC[-1] >= useA[-1] + b[0] + useC[-1]:
    if a[0] != 0:
      useA.extend(a)
      a = [0]
      
  if k**2 <= len(useA) * len(useB) * len(useC):
    break
ans = []
#print(useA, useB, useC)
for i in range(len(useA)):
  for j in range(len(useB)):
    for m in range(len(useC)):
      ans.append(useA[i] + useB[j] + useC[m])
ans.sort(reverse = True)
for i in range(k):
  print(ans[i])

Submission status: Wrong Answer

Solution code:
X,Y,Z,K=map(int,input().split())
A=map(int,input().split())
B=map(int,input().split())
C=map(int,input().split())
A=list(A)
B=list(B)
C=list(C)
s=[]
count=0
mx=0
for i in range(len(A)):
    for j in range(len(B)):
        for k in range(len(C)):
            count+=1
            if count>K:
                if A[i]+B[j]+C[k]<mx:
                    s+=[A[i]+B[j]+C[k]]
                    s.remove(max(s))
                    mx=max(s)
            else:
                s+=[A[i]+B[j]+C[k]]
                if mx<A[i]+B[j]+C[k]:
                    mx=A[i]+B[j]+C[k]
s.sort(reverse=True)
for i in range(K):
    print(s[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()]

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

dp = [0]*K
dp[0] = A[0]+B[0]+C[0]

a = 0
a_b = 0
a_c = 0

b = 0
b_a = 0
b_c = 0

c = 0
c_a = 0
c_b = 0

a_b_c = 0
for i in range(0,K,7):
    dp[i] = A[i//8]+B[i//8]+C[i//8]
    li = [0]*7

    if a+1 < X:
        li[0] = A[0]-A[a+1]
    else:
        li[0] = 10**9

    if b+1 < Y:
        li[1] = B[0]-B[b+1]
    else:
        li[1] = 10**9

    if c+1 < Z:
        li[2] = C[0]-C[c+1]
    else:
        li[2] = 10**9

    if a_b+1 < X and b_a+1 < Y:
        li[3] = A[0]+B[0]-A[a_b+1]-B[b_a+1]
    else:
        li[3] = 10**9

    if b_c+1 < Y and c_b+1 < Z:
        li[4] = B[0]+C[0]-B[b_c+1]-C[c_b+1]
    else:
        li[4] = 10**9

    if c_a+1 < Z and a_c+1 < X:
        li[5] = C[0]+A[0]-C[c_a+1]-A[a_c+1]
    else:
        li[5] = 10**9

    if a_b_c + 1 < min(X,Y,Z):
        li[6] = A[0]+B[0]+C[0]-A[a_b_c+1]-B[a_b_c+1]-C[a_b_c+1]

    li.sort()
    for j in li:
        dp.append(dp[i//8]-j)
        
for i in range(7,K+7):
    if i > 0:
        print(dp[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()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
count=0
for _ in range(x):
    for __ in range(y):
        for ___ in range(z):
            print(a[_]+b[__]+c[___])
            count+=1
            if count >= 3000:
                break
        if count >= 3000:
            break
    if count >= 3000:
        break

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a = IR(5)
    k = II()
    if max(a) - min(a) > k:
        print(":(")
    else:
        print("Yay!")
    return

#B
def B():
    a = IR(5)
    b = a[0]
    ans = 0
    for a_ in a:
        if a_ % 10 != 0:
            if b % 10> a_ % 10:
                b = a_
    flg = 0
    for a_ in a:
        if a_ != b or flg:
            ans += math.ceil(a_ / 10) * 10
        else:
            ans += b
            flg = 1
    print(ans)
            
    
    return

#C
def C():
    n = II()
    ai = IR(5)
    print(math.ceil(n / min(ai)) + 4)
        
        
    return

#D
def D():
    x, y, z, K = LI()
    a = LI()
    a.sort(reverse=True)
    b = LI()
    b.sort(reverse = True)
    c = LI()
    c.sort(reverse=True)
    ab = []
    if z > x:
        if y > z:
            bf = a
            a = c
            c = bf
        elif x > y:
            bf = b
            b = c
            c = bf
    if z > y:
        if y > x:
            bf = a
            a = c
            c = bf
        elif x > y:
            bf = b
            b = c
            c = bf
        
    for a_ in a:
        for b_ in b:
            ab.append(a_ + b_)
    ab.sort(reverse = True)
    ab = ab[:min(x + y, 3000)]
    ans = []
    for ab_ in ab:
        for c_ in c:
            ans.append(ab_ + c_)
    ans.sort(reverse = True)
    for k in range(K):
        print(ans[k])



        
                    

    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [X, Y, Z, K] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2]), int(input_raw[3])]

    input_raw = read_func().strip().split()
    A = [long(input_raw[i]) for i in range(X)]
    input_raw = read_func().strip().split()
    B = [long(input_raw[i]) for i in range(Y)]
    input_raw = read_func().strip().split()
    C = [long(input_raw[i]) for i in range(Z)]

    count = 0
    BC = []
    for i in range(X):
        for j in range(Z):
            BC.append(B[i] + C[j])

    A.sort(reverse = True)
    BC.sort(reverse = True)
    T = []
    for i in range(X):
        for j in range(min(K, len(BC))):
            T.append(A[i] + BC[j])

    for i in range(K):
        print T[i]

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
X,Y,Z,K = list(map(int,input().split()))

xt = list(map(int,input().split()))
yt = list(map(int,input().split()))
zt = list(map(int,input().split()))

xt.sort(reverse=True)
yt.sort(reverse=True)
zt.sort(reverse=True)

xi = 0
yi = 0
zi = 0

for i in range(K):

    nt = [xt[xi],yt[yi],zt[zi]]
    print(nt)
    print(xt[xi]+yt[yi]+zt[zi])

    chf = False

    while (not chf) and nt != []:
        mt = min(nt)
        print(nt)
        if mt==xt[xi] and xi < len(xt)-1:
            xi=xi+1
            chf = True
        elif mt==yt[yi] and yi < len(yt)-1:
            yi=yi+1
            chf = True
        elif mt==zt[zi] and zi < len(zt)-1:
            zi=zi+1
            chf = True
        
        nt.remove(mt)

        
print(xt)
print(yt)
print(zt)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import product

def main():
    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()))

    A = sorted(A, key=lambda x: -x) + [-10**9]
    B = sorted(B, key=lambda x: -x) + [-10**9]
    C = sorted(C, key=lambda x: -x) + [-10**9]

    diffA = [A[i] - A[i+1] for i in range(X)]
    diffB = [B[i] - B[i+1] for i in range(Y)]
    diffC = [C[i] - C[i+1] for i in range(Z)]

    A_ = [A[0]]
    B_ = [B[0]]
    C_ = [C[0]]
    i, j, k = 0, 0, 0
    while (len(A_) * len(B_) * len(C_)) < K:
        a, b, c = diffA[i], diffB[j], diffC[k]

        if a == min(a, b, c):
            A_.append(A[i+1])
            i += 1
        if b == min(a, b, c):
            B_.append(B[j+1])
            j += 1
        if c == min(a, b, c):
            C_.append(C[k+1])
            k += 1

    deli= []
    for a in A_:
        for b in B_:
            for c in C_:
                deli.append(a + b + c)

    deli = sorted(deli, key=lambda x: -x)
    for i in range(K):
        print(deli[i])


if __name__ == '__main__':
    main()

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

a.sort()
b.sort()
c.sort()
count=0
for _ in range(x):
    for __ in range(y):
        for ___ in range(z):
            print(a[_]+b[__]+c[___])
            count+=1
            if count >= 3000:
                break
        if count >= 3000:
            break
    if count >= 3000:
        break

Submission status: Wrong Answer

Solution code:
x, y, z, k = map(int, input().split())
a_s = list(map(int, input().split()))
bs = list(map(int, input().split()))
cs = list(map(int, input().split()))
a_s.sort(reverse=True)
bs.sort(reverse=True)
cs.sort(reverse=True)

list = []
i = -1
for a in a_s:
    for b in bs:
        for c in cs:
            list.append(a + b + c)
            i += 1
            if i > k and list[i] < list[k]:
                break
list.sort(reverse=True)
for i in range(k):
    print(list[i])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import os
import itertools
from math import *
import numpy as np

x,y,z,k = [int(i) for i in input().split(' ')]
#print(x,y,z,k)
    
xi = [int(i) for i in input().split()]
yi = [int(i) for i in input().split()]
zi = [int(i) for i in input().split()]

xi.sort(reverse=True)
yi.sort(reverse=True)
zi.sort(reverse=True)

xi = xi[:k]
yi = yi[:k]
zi = zi[:k]

nlist = []
for n in list(itertools.product(xi, yi, zi)):
    nlist.append(n[0] + n[1] + n[2])

nlist_np = np.array(nlist)
#print(nlist_np)

a = np.argpartition(-nlist_np, k-1)

for i in range(k):
    print(nlist_np[a[i]])

Submission status: Wrong Answer

Solution code:
import heapq
import itertools

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

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
from heapq import heappop, heappush

X, Y, Z, K = [int(s) for s in input().split()]
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
a, b, c = 1, 1, 1
while (a * b * c) / max(a, b, c) <= K:
    da = A[a-1] - A[a] if X > a else float('Inf')
    db = B[b-1] - B[b] if Y > b else float('Inf')
    dc = C[c-1] - C[c] if Z > c else float('Inf')
    if da <= db and da <= dc:
        a += 1
    elif db <= da and db <= dc:
        b += 1
    else:
        c += 1
h = []
for i in range(a):
    for j in range(b):
        for k in range(c):
            heappush(h, -(A[i] + B[j] + C[k]))
for _ in range(K):
    print(-heappop(h))

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

if x>200:
  a.sort()
  a.reverse()
  a=a[0:200]

if y>50:
  b.sort()
  b.reverse()
  b=b[0:50]

if z>50:
  c.sort()
  c.reverse()
  c=c[0:50]

lena=len(a)
lenb=len(b)
lenc=len(c)
  
ansList=[]
for m in range(lena):
  for n in range(lenb):
    for o in range(lenc):
      ansList.append(a[m]+b[n]+c[o])

ansList.sort()
ansList.reverse()

for i in range(k):
  print(ansList[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)

a = 0
b = 0
c = 0

def val(i_a, i_b, i_c):
    return A[i_a] + B[i_b] + C[i_c]

print(val(a, b, c))
for i in range(1, K):
    MA = val(a+1, b, c) if a < X-1 else 0
    MB = val(a, b+1, c) if b < Y-1 else 0
    MC = val(a, b, c+1) if c < Z-1 else 0
    if MA > MB:
        if MA > MC:
            a += 1
            print(MA)
        else:
            c += 1
            print(MC)
    else:
        if MB > MC:
            b += 1
            print(MB)
        else:
            c += 1
            print(MC)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a = IR(5)
    k = II()
    if max(a) - min(a) > k:
        print(":(")
    else:
        print("Yay!")
    return

#B
def B():
    a = IR(5)
    b = a[0]
    ans = 0
    for a_ in a:
        if a_ % 10 != 0:
            if b % 10> a_ % 10:
                b = a_
    flg = 0
    for a_ in a:
        if a_ != b or flg:
            ans += math.ceil(a_ / 10) * 10
        else:
            ans += b
            flg = 1
    print(ans)
            
    
    return

#C
def C():
    n = II()
    ai = IR(5)
    print(math.ceil(n / min(ai)) + 4)
        
        
    return

#D
def D():
    x, y, z, K = LI()
    a = LI()
    a.sort(reverse=True)
    b = LI()
    b.sort(reverse = True)
    c = LI()
    c.sort(reverse=True)
    ab = []
    if z > x:
        if y > z:
            bf = a
            a = c
            c = bf
        elif x > y:
            bf = b
            b = c
            c = bf
        
    for a_ in a:
        for b_ in b:
            ab.append(a_ + b_)
    ab.sort(reverse = True)
    ab = ab[:min(x + y, 3000)]
    ans = []
    for ab_ in ab:
        for c_ in c:
            ans.append(ab_ + c_)
    ans.sort(reverse = True)
    for k in range(K):
        print(ans[k])



        
                    

    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    D()

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_buy = [A[0]]
B_buy = [B[0]]
C_buy = [C[0]]

idx_A = 1
idx_B = 1
idx_C = 1
max_idx = 4
while len(A_buy) * len(B_buy) * len(C_buy) < 1000000:
    A_value = 0
    B_value = 0
    C_value = 0
    if idx_A < X:
        A_value = A[idx_A]
    if idx_B < Y:
        B_value = B[idx_B]
    if idx_C < Z:
        C_value = C[idx_C]
    if A_value + B_value + C_value == 0:
        break
    max_idx = max(enumerate([A_value, B_value, C_value]), key=lambda x: x[1])[0]
    if max_idx == 0:
        A_buy.append(A[idx_A])
        idx_A += 1
    elif max_idx == 1:
        B_buy.append(B[idx_B])
        idx_B += 1
    else:
        C_buy.append(C[idx_C])
        idx_C += 1

cake_list = []
for a in A_buy:
    for b in B_buy:
        for c in C_buy:
            cake_list.append(a + b + c)
cake_list.sort(reverse = True)

for i in range(K):
    print(cake_list[i])

Submission status: Wrong Answer

Solution code:
import numpy as np

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

x, y, z, k = [int(a) for a in input().split()]
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
C = [int(a) for a in input().split()]

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

progress = [(0, 0, 0, prod(0,0,0))]


def expand(p, q, r):
    result = []
    if p + 1 < x:
        result.append((p+1, q, r, prod(p+1, q, r)))
    if q + 1 < y:
        result.append((p, q+1, r, prod(p, q+1, r)))
    if r + 1 < z:
        result.append((p, q, r+1, prod(p, q, r+1)))
    return result

for i in range(k):
    prods = [tup[-1] for tup in progress]

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

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

Submission status: Wrong Answer

Solution code:
X,Y,Z,K = list(map(int,input().split()))

A = sorted(list(map(int,input().split())))
A.reverse()
B = sorted(list(map(int,input().split())))
B.reverse()
C = sorted(list(map(int,input().split())))
C.reverse()

ia,ib,ic = 0,0,0
_min_ = 10000000000001
for ida,a in enumerate(A) :
    for idb,b in enumerate(B[:int(K/(ida+1))]):
        idc = int(K/(ida+1)/(idb+1)) -1
        if  idc < len(C) and a+b+C[idc] < _min_:
            _min_ = a+b+C[idc]
            ia,ib,ic = ida,idb,idc

import itertools
#print(list(itertools.product(A[:s_a], B[:s_b],C[:s_c])))
for idx,value in enumerate(sorted([sum(i) for i in  list(itertools.product(A[:ia], B[:ib],C[:ic]))])[::-1]):
    if idx > K-1:
        break
    print(value)

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)

kouho = set()


def f(t):
    x, y, z = t
    return A[x] + B[y] + C[z]


def main():
    kouho.add((0, 0, 0))

    for k in range(K):
        temp = 0
        for d in kouho:
            if f(d) > temp:
                todel = d
                temp = f(d)

        x, y, z = todel
        toadd = [(x, y, z+1), (x, y+1, z), (x+1, y, z)]
        for ta in toadd:
            if ta[0] == X:
                continue
            if ta[1] == Y:
                continue
            if ta[2] == Z:
                continue
            if ta in kouho:
                continue
            kouho.add(ta)

        kouho.remove(todel)
        print(temp)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools

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

list_ = [b+c for (b,c) in itertools.product(B[:400], C[:400])]
list_.sort(reverse=True)

list__ = [ab+c for (ab,c) in itertools.product(list_[:100000], A[:400])]
for N in list__[:K]:
  print(N)

Submission status: Wrong Answer

Solution code:
from sys import stdin

def main():
    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=1)[:50]
    b = sorted(B, reverse=1)[:50]
    c = sorted(C, reverse=1)[:50]

    ans = []
    for a_ in a:
        for b_ in b:
            for c_ in c:
                ans.append(a_ + b_ + c_)
    ans.sort(reverse=1)
    print(*ans[:K], sep='\n')

input = lambda: stdin.readline()
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()))
a.sort()
b.sort()
c.sort()
d = []
f = []
for i in range(max(0,len(a)-5), len(a)):
    for j in range(max(0,len(b)-5), len(b)):
        for l in range(max(0,len(c)-120), len(c)):
            if not [i,j,l] in f:
                e = a[i]+b[j]+c[l]
                d.append(e)
                f.append([i,j,l])
for i in range(max(0,len(a)-5), len(a)):
    for j in range(max(0,len(b)-120), len(b)):
        for l in range(max(0,len(c)-5), len(c)):
            if not [i,j,l] in f:
                e = a[i]+b[j]+c[l]
                d.append(e)
                f.append([i,j,l])
for i in range(max(0,len(a)-120), len(a)):
    for j in range(max(0,len(b)-5), len(b)):
        for l in range(max(0,len(c)-5), len(c)):
            if not [i,j,l] in f:
                e = a[i]+b[j]+c[l]
                d.append(e)
                f.append([i,j,l])
for i in range(max(0,len(a)- 15), len(a)):
    for j in range(max(0,len(b)-15), len(b)):
        for l in range(max(0,len(c)-15), len(c)):
            if not [i,j,l] in f:
                e = a[i]+b[j]+c[l]
                d.append(e)
                f.append([i,j,l])
d.sort()
for i in range(1,k+1):
    print(d[-i])

Submission status: Wrong Answer

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


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


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


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


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

current_A = 0
current_B = 0
current_C = 0


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


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

result = []
for i in xrange(current_A + 100):
    for j in xrange(current_B + 100):
        for k in xrange(current_C + 100):
            result.append(sorted_A[min(i, X - 1)] + sorted_B[min(j, Y - 1)] + sorted_C[min(k, Z - 1)])

sorted_result = sorted(result, reverse=True)
for i in xrange(K):
    print(sorted_result[i])

Submission status: Wrong Answer

Solution code:
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
A_buy = [A[0]]
B_buy = [B[0]]
C_buy = [C[0]]

idx_A = 1
idx_B = 1
idx_C = 1
max_idx = 4
while len(A_buy) * len(B_buy) * len(C_buy) < 3000:
    A_value = 0
    B_value = 0
    C_value = 0
    if idx_A < X:
        A_value = A[idx_A]
    if idx_B < Y:
        B_value = B[idx_B]
    if idx_C < Z:
        C_value = C[idx_C]
    if A_value + B_value + C_value == 0:
        break
    max_idx = max(enumerate([A_value, B_value, C_value]), key=lambda x: x[1])[0]
    if max_idx == 0:
        A_buy.append(A[idx_A])
        idx_A += 1
    elif max_idx == 1:
        B_buy.append(B[idx_B])
        idx_B += 1
    else:
        C_buy.append(C[idx_C])
        idx_C += 1

cake_list = []
for a in A_buy:
    for b in B_buy:
        for c in C_buy:
            cake_list.append(a + b + c)
cake_list.sort(reverse = True)

for i in range(K):
    print(cake_list[i])

Submission status: Wrong Answer

Solution code:
line = input().split(sep=" ")
x = int(line[0])
y = int(line[1])
z = int(line[2])
in_k = int(line[3])


in_x = sorted(list(map(int,input().split(sep=" "))),reverse=True)
in_y = sorted(list(map(int,input().split(sep=" "))),reverse=True)
in_z = sorted(list(map(int,input().split(sep=" "))),reverse=True)

ans_arr = []

if(x > in_k ): x =in_k
if(y > in_k ): y =in_k
if(z > in_k ): z =in_k

print(x)
for i in range(x):
	for j in range(y):
		for k in range(z):
			ans_arr.append(in_x[i] + in_y[j] + in_z[k])

ans_arr = sorted(ans_arr,reverse=True)

for i in range(in_k):
	print(ans_arr[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()))
aa = []
for a in range(x):
    for b in range(y):
        for c in range(z):
            aa.append(A[a]+B[b]+C[c])
aa.sort(reverse=True)
for i in aa:
    print(i)

Submission status: Wrong Answer

Solution code:
import itertools

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

list_ = [a+b for (a,b) in itertools.product(A[:400], B[:400])]
list_.sort(reverse=True)

list__ = [ab+c for (ab,c) in itertools.product(list_[:100000], C[:400])]
for N in list__[:K]:
  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()))

lst = []

for i in range(X):
    for j in range(Y):
        for k in range(Z):
            score = A[i] + B[j] + C[k]
            lst.append(score)
    

lst.sort(reverse = True)

for item in lst:
    print(item)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [X, Y, Z, K] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2]), int(input_raw[3])]

    input_raw = read_func().strip().split()
    A = [long(input_raw[i]) for i in range(X)]
    input_raw = read_func().strip().split()
    B = [long(input_raw[i]) for i in range(Y)]
    input_raw = read_func().strip().split()
    C = [long(input_raw[i]) for i in range(Z)]

    count = 0
    BC = [0 for i in range(X * Z)]
    for i in range(X):
        for j in range(Z):
            BC[count] = B[i] + C[j]
            count += 1

    A.sort(reverse = True)
    BC.sort(reverse = True)
    T = [0 for i in range(X * min(K, len(BC)))]
    count = 0
    for i in range(X):
        for j in range(min(K, len(BC))):
            T[count] = (A[i] + BC[j])
            count += 1


    for i in range(K):
        print T[i]

if __name__ == '__main__':
    main()