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

if x * y * z <= 3000:
    ans = []
    for ai in a:
        for bi in b:
            for ci in c:
                ans.append(ai + bi + ci)
    ans.sort(reverse=True)
    for i in range(k):
        print(ans[i])
else:
    ia = 0
    ib = 0
    ic = 0
    len_a = len(a)
    len_b = len(b)
    len_c = len(c)

    while (ia+1) * (ib+1) * (ic+1) < 3000:
        if ia + 1 == len_a:
            diff_a = float('inf')
        else:
            diff_a = a[0] - a[ia+1]
        if ib + 1 == len_b:
            diff_b = float('inf')
        else:
            diff_b = b[0] - b[ib+1]
        if ic + 1 == len_c:
            diff_c = float('inf')
        else:
            diff_c = c[0] - c[ic+1]

        if diff_a <= diff_b and diff_a <= diff_c:
            ia += 1
        if diff_b <= diff_a and diff_b <= diff_c:
            ib += 1
        if diff_c <= diff_a and diff_c <= diff_b:
            ic += 1
    a = a[:ia+1]
    b = b[:ib+1]
    c = c[:ic+1]

    ans = []
    for ai in a:
        for bi in b:
            for ci in c:
                ans.append(ai + bi + ci)
    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=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

l=[]
for s in a:
    for t in b:
        l.append(s+t)
l.sort()
c.sort()
c.reverse()
if x*y*z>3000:
    n=[]
    m=(3000//(x*y))+1
    for s in l:
        for t in c[:m]:
            n.append(s+t)
    n.sort()
    n.reverse()
    for i in range(k):
        print(n[i])
else:
    n=[]
    for s in a:
        for t in b:
            for u in c:
                n.append(s+t+u)
    n.sort()
    n.reverse()
    for i in range(k):
        print(n[i])

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random
import bisect #bisect_left　これで二部探索の大小検索が行える

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


select = round(k**(1/3))+1

A.sort()
A.reverse()
B.sort()
B.reverse()
C.sort()
C.reverse()
ak = A[0:select]
bk = B[0:select]
ck = C[0:select]

anss = []
for i in ak:
    for j in bk:
        for l in ck:
            anss.append(i+j+l)

anss.sort()
anss.reverse()

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

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) + [0]
    B = sorted(B, key=lambda x: -x) + [0]
    C = sorted(C, key=lambda x: -x) + [0]

    A_ = [A[0]]
    B_ = [B[0]]
    C_ = [C[0]]
    i, j, k = 1, 1, 1
    while (i * j * k) < 10**6:
        a, b, c = A[i], B[j], C[k]

        if max(a, b, c) == 0:
            break

        if a == max(a, b, c):
            A_.append(a)
            i += 1
        if b == max(a, b, c):
            B_.append(b)
            j += 1
        if c == max(a, b, c):
            C_.append(c)
            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:
import itertools
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()]
menues = [A,B,C]
for menu in menues:
    menu.sort()
A_sub,B_sub,C_sub = [],[],[]
A_sub.append(A.pop())
B_sub.append(B.pop())
C_sub.append(C.pop())

while(len(A_sub) * len(B_sub) * len(C_sub)<3000) and (len(A_sub) * len(B_sub) * len(C_sub)<K):
    if(A and B and C):#A,B,Cある
        if(A[-1] >= max(B[-1],C[-1])):
            A_sub.append(A.pop())
        elif(B[-1] >= max(A[-1],C[-1])):
            B_sub.append(B.pop())
        else:
            C_sub.append(C.pop())
    elif(A and B and not C):#Cがない
        if(A[-1] >= B[-1]):
            A_sub.append(A.pop())
        else:
            B_sub.append(B.pop())
    elif(A and not B and C):#Bがない
        if(A[-1] >= C[-1]):
            A_sub.append(A.pop())
        else:
            C_sub.append(C.pop())
    elif(not A and B and C):#Cがない
        if(B[-1] >= C[-1]):
            B_sub.append(B.pop())
        else:
            C_sub.append(C.pop())
    elif(A and not B and not C):#Aしかない
        A_sub.append(A.pop())
    elif(not A and B and not C):#Bしかない
        B_sub.append(B.pop())
    elif(not A and not B and C):#Cしかない
        C_sub.append(C.pop())
    elif(not A and not B and not C):#全部なくなる
        break
flav = [sum(i) for i in itertools.product(A_sub,B_sub,C_sub)]
flav.sort(reverse=True)
for i in range(K):
    print(flav[i])

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) + [0]
    B = sorted(B, key=lambda x: -x) + [0]
    C = sorted(C, key=lambda x: -x) + [0]

    A_ = [A[0]]
    B_ = [B[0]]
    C_ = [C[0]]
    i, j, k = 1, 1, 1
    while (i * j * k) < 10**5:
        a, b, c = A[i], B[j], C[k]

        if max(a, b, c) == 0:
            break

        if a == max(a, b, c):
            A_.append(a)
            i += 1
        if b == max(a, b, c):
            B_.append(b)
            j += 1
        if c == max(a, b, c):
            C_.append(c)
            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:
# coding: utf-8
# Your code here!


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

a = sorted(map(int,input().split()))[::-1]
b = sorted(map(int,input().split()))[::-1]
c = sorted(map(int,input().split()))[::-1]

ans = [i+j+l for l in c for j in b for i in a]

for i in sorted(ans[:k])[::-1]:
    print(i)

Submission status: Wrong Answer

Solution code:
import itertools
x,y,z,k = map(int,input().split())
X = sorted(list(map(int,input().split())),reverse=True)
Y = sorted(list(map(int,input().split())),reverse=True)
Z = sorted(list(map(int,input().split())),reverse=True)
if x*y*z < 3000:
    L = list(itertools.product(X,Y,Z))
    J = sorted([sum(i) for i in L],reverse=True)
    for i in range(k):
        print(J[i])
    exit()
else:
    L = list(itertools.product(X[0:17],Y[0:17],Z[0:17]))
    J = sorted([sum(i) for i in L],reverse=True)
    for i in range(k):
        print(J[i])
    exit()

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)
L=[]
N=0
n=0
while(N<min(800*K,X*Y*Z)):
    #p+q+r=n
    for p in range(0,n+1):
        for q in range(0,n+1-p):
            r=n-p-q
            if p<X and q<Y and r<Z:
                L.append(A[p]+B[q]+C[r])
                N+=1
    n+=1
L.sort(reverse=True)
for i in range(K):
    print(L[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()))

l=[]
for s in a:
    for t in b:
        l.append(s+t)
l.sort()
c.sort()
c.reverse()
if x*y*z>3000:
    n=[]
    m=(3000//(x*y))+1
    for s in l:
        for t in l[:m]:
            n.append(s+t)
    n.sort()
    n.reverse()
    for i in range(k):
        print(n[i])
else:
    n=[]
    for s in a:
        for t in b:
            for u in c:
                n.append(s+t+u)
    n.sort()
    n.reverse()
    for i in range(k):
        print(n[i])

Submission status: Wrong Answer

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

a = sorted(a,reverse=True)
b = sorted(b,reverse=True)
c = sorted(c,reverse=True)

l = []
for i in range(min(150,x)):
    for j in range(min(150,y)):
        for t in range(min(150,z)):
            l.append(a[i] + b[j] + c[t])
l = sorted(l,reverse=True)
for i in range(k):
    print(l[i])

Submission status: Wrong Answer

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

import math

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()
a.reverse()
b.sort()
b.reverse()
c.sort()
c.reverse()

cnum = []

takadaka = math.ceil(k ** 0.66)

for i in range(min(takadaka,x)):
    for j in range(min(takadaka,y)):
        for l in range(min(takadaka,z)):
            cnum.append(a[i] + b[j] + c[l])

cnum.sort()
cnum.reverse()

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

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

a = [A[i] - A[i+1] for i in range(len(A)-1) ]
b = [B[i] - B[i+1] for i in range(len(B)-1) ]
c = [C[i] - C[i+1] for i in range(len(C)-1) ]

st = A[-1]+B[-1]+C[-1]

s_a,s_b,s_c = 1,1,1
for i in range(K-1):
    # どれを取るか選ぶ
    m = min(a[0] if len(a)>0 else 100000000001
            ,b[0] if len(b)>0 else 100000000001
            ,c[0] if len(c)>0 else 100000000001)
    #print(a[0],b[0],c[0])
    consider_list = [0]*3
    if len(a)>0 and a[0] == m:
        consider_list[0] = (s_a+1) * s_b * s_c

    if len(b)>0 and b[0] == m:
        consider_list[1] = (s_a) * (s_b+1) * s_c
    if len(c)>0 and c[0] == m:        
        consider_list[2] = (s_a) * (s_b) * (s_c+1)
    #print(consider_list.index(max(consider_list)))
    if consider_list.index(max(consider_list)) == 0:
        a.pop(0)
        s_a += 1
    elif consider_list.index(max(consider_list)) == 1:
        b.pop(0)
        s_b += 1
    else:
        c.pop(0)
        s_c += 1
    if s_a * s_b*s_c >= K:
        break

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[:s_a+10], B[:s_b+10],C[:s_c+10]))])[::-1]):
  if idx > K-1:
    break
  print(value)

Submission status: Wrong Answer

Solution code:
import itertools
import sys

input = sys.stdin.readline

maxn = 10000000000

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.append(-maxn)
B.append(-maxn)
C.append(-maxn)

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

apos, bpos, cpos = 0, 0, 0

while (apos + 1) * (bpos + 1) * (cpos + 1) < min(10 * K, X * Y * Z):
    if (
        apos < len(A) - 2
        and abs(A[apos] - A[apos + 1]) < abs(B[bpos] - B[bpos + 1])
        and abs(A[apos] - A[apos + 1]) < abs(C[cpos] - C[cpos + 1])
    ):
        apos += 1
    elif bpos < len(B) - 2 and B[bpos] - B[bpos + 1] < C[cpos] - C[cpos + 1]:
        bpos += 1
    else:
        cpos += 1

res = []
for a in list(itertools.product(A[: apos + 1], B[: bpos + 1], C[: cpos + 1])):
    res.append(a[0] + a[1] + a[2])

res.sort(reverse=True)
for k in range(K):
    print(res[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)
L=[]
N=0
n=0
while(N<min(100*K,X*Y*Z)):
    #p+q+r=n
    for p in range(0,n+1):
        for q in range(0,n+1-p):
            r=n-p-q
            if p<X and q<Y and r<Z:
                L.append(A[p]+B[q]+C[r])
                N+=1
    n+=1
L.sort(reverse=True)
for i in range(K):
    print(L[i])

Submission status: Wrong Answer

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

import math

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()
a.reverse()
b.sort()
b.reverse()
c.sort()
c.reverse()

cnum = []

takadaka = math.ceil(k ** 0.55)

for i in range(min(takadaka,x)):
    for j in range(min(takadaka,y)):
        for l in range(min(takadaka,z)):
            cnum.append(a[i] + b[j] + c[l])

cnum.sort()
cnum.reverse()

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

Submission status: Wrong Answer

Solution code:
x,y,z,k=map(int,input().split());a,b,c=list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split()));a.sort(reverse=1);b.sort(reverse=1);c.sort(reverse=1);ma=a[0]+b[0]+c[0];d=[[0],[0],[0]]
for i in range(len(a)-1):d[0].append(d[0][-1]+a[i]-a[i+1])
for i in range(len(b)-1):d[1].append(d[1][-1]+b[i]-b[i+1])
for i in range(len(c)-1):d[2].append(d[2][-1]+c[i]-c[i+1])
e=d[0]+d[1]+d[2]
if x*y*z>3000:
  f,i=[1,1,1],1
  while f[0]*f[1]*f[2]<3000:
    for z in range(3):
      if f[z]<len(d[z]):
        while d[z][f[z]]==i:
          f[z]+=1
          if f[z]==len(d[z]):break
    i+=1
  for i in range(3):d[i]=d[i][:f[i]+1]
s=[]
for i in d[0]:
  for j in d[1]:
    for h in d[2]:s.append(i+h+j)
s.sort()
for i in range(k):print(ma-s[i])

Submission status: Wrong Answer

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

a = sorted(a,reverse=True)
b = sorted(b,reverse=True)
c = sorted(c,reverse=True)

l = []
for i in range(min(100,x)):
    for j in range(min(100,y)):
        for t in range(min(100,z)):
            l.append(a[i] + b[j] + c[t])
l = sorted(l,reverse=True)
for i in range(k):
    print(l[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()
b.sort()
c.sort()
d = []
for i in range(max(0,len(a)-120), len(a)):
    for j in range(max(0,len(b)-120), len(b)):
        for l in range(max(0,len(c)-120), len(c)):
            d.append(a[i]+b[j]+c[l])
d.sort()
for i in range(1,k+1):
    print(d[-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()
b.sort()
c.sort()

if x * y * z <= 3000:
    ans = []
    for ai in a:
        for bi in b:
            for ci in c:
                ans.append(ai + bi + ci)
    ans.sort(reverse=True)
    for i in range(k):
        print(ans[i])
else:
    ia = 0
    ib = 0
    ic = 0
    len_a = len(a)
    len_b = len(b)
    len_c = len(c)

    while (ia+1) * (ib+1) * (ic+1) < 3000:
        if ia + 1 == len_a:
            diff_a = float('inf')
        else:
            diff_a = a[0] - a[ia+1]
        if ib + 1 == len_b:
            diff_b = float('inf')
        else:
            diff_b = b[0] - b[ib+1]
        if ic + 1 == len_c:
            diff_c = float('inf')
        else:
            diff_c = c[0] - c[ic+1]

        if diff_a <= diff_b and diff_a <= diff_c:
            ia += 1
            while ia+1 < len_a and a[ia+1] == a[ia]:
                ia += 1
        if diff_b <= diff_a and diff_b <= diff_c:
            ib += 1
            while ib+1 < len_b and b[ib+1] == b[ib]:
                ib += 1
        if diff_c <= diff_a and diff_c <= diff_b:
            ic += 1
            while ic+1 < len_c and c[ic+1] == c[ic]:
                ic += 1

    a = a[:ia+1]
    b = b[:ib+1]
    c = c[:ic+1]

    ans = []
    for ai in a:
        for bi in b:
            for ci in c:
                ans.append(ai + bi + ci)
    ans.sort(reverse=True)
    for i in range(k):
        print(ans[i])

Submission status: Wrong Answer

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

import math

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()
a.reverse()
b.sort()
b.reverse()
c.sort()
c.reverse()

cnum = []

takadaka = math.ceil(k ** 0.5)

for i in range(min(takadaka,x)):
    for j in range(min(takadaka,y)):
        for l in range(min(takadaka,z)):
            cnum.append(a[i] + b[j] + c[l])

cnum.sort()
cnum.reverse()

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

Submission status: Wrong Answer

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

lst = []
for x in xs:
    for y in ys:
        for z in zs:
            lst.append(x+y+z)
lst_s = sorted(lst)
for i in range(min(3000, X*Y*Z)):
    print(lst_s[-(i+1)])

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 = []
for i in range(max(0,len(a)-150), len(a)):
    for j in range(max(0,len(b)-150), len(b)):
        for l in range(max(0,len(c)-150), len(c)):
            d.append(a[i]+b[j]+c[l])
d.sort()
for i in range(1,k+1):
    print(d[-i])

Submission status: Wrong Answer

Solution code:
import numpy as np


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 ai in a:
    for bi in b:
        for ci in c:
            ans.append(ai+bi+ci)

ans.sort(reverse=True)

for item in ans:
    print(item)

Submission status: Wrong Answer

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

import math

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()
a.reverse()
b.sort()
b.reverse()
c.sort()
c.reverse()

cnum = []

takadaka = math.ceil(k ** 0.34)

for i in range(min(takadaka,x)):
    for j in range(min(takadaka,y)):
        for l in range(min(takadaka,z)):
            cnum.append(a[i] + b[j] + c[l])

cnum.sort()
cnum.reverse()

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

Submission status: Wrong Answer

Solution code:
x, y, z, k = map(int, input().split())
alist = list(sorted(map(int, input().split()), key=lambda x: -x)) + [-pow(10, 10)]
blist = list(sorted(map(int, input().split()), key=lambda x: -x)) + [-pow(10, 10)]
clist = list(sorted(map(int, input().split()), key=lambda x: -x)) + [-pow(10, 10)]

setk = set([(0, 0, 0, alist[0] + blist[0] + clist[0])])
outk = set()

for _ in range(k):
  tmpk = None
  tmpi = 0
  for i, _k in enumerate(setk):
    if tmpk is None:
      tmpk = _k
      tmpi = i
    elif tmpk[3] < _k[3]:
      tmpk = _k
      tmpi = i
  print(tmpk[3])
  outk.add(tmpk)
  setk.discard(tmpk)
  setk.add((tmpk[0] + 1, tmpk[1], tmpk[2], tmpk[3] - alist[tmpk[0]] + alist[tmpk[0] + 1]))
  setk.add((tmpk[0], tmpk[1] + 1, tmpk[2], tmpk[3] - blist[tmpk[1]] + blist[tmpk[1] + 1]))
  setk.add((tmpk[0], tmpk[1], tmpk[2] + 1, tmpk[3] - clist[tmpk[2]] + clist[tmpk[2] + 1]))

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()))
import heapq
q = []
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
def val(i, j, k):
  return -(A[i] + B[j] + C[k])
heapq.heappush(q, (val(0,0,0), 0,0,0))
visited = set((0,0,0))
for _ in range(k):
  v, aa, bb, cc = heapq.heappop(q)
  print(-v)
  if aa + 1 < len(A) and (aa+1, bb, cc) not in visited:
    visited.add((aa+1, bb, cc))
    heapq.heappush(q, (val(aa+1, bb, cc), aa+1, bb, cc))
  if bb + 1 < len(B) and (aa, bb+1, cc) not in visited:
    visited.add((aa, bb+1, cc))
    heapq.heappush(q, (val(aa, bb+1, cc), aa, bb+1, cc))
  if cc + 1 < len(C) and (aa, bb, cc+1):
    visited.add((aa, bb, cc+1))
    heapq.heappush(q, (val(aa, bb, cc+1), aa, bb, cc+1))

Submission status: Wrong Answer

Solution code:
import itertools
x,y,z,k = map(int,input().split())
X = sorted(list(map(int,input().split())),reverse=True)
Y = sorted(list(map(int,input().split())),reverse=True)
Z = sorted(list(map(int,input().split())),reverse=True)
if k > x*y*z:
    L = list(itertools.product(X,Y,Z))
    J = sorted([sum(i) for i in L],reverse=True)
    for i in range(k):
        print(J[i])
    exit()
else:
    L = list(itertools.product(X[0:20],Y[0:20],Z[0:20]))
    J = sorted([sum(i) for i in L],reverse=True)
    for i in range(k):
        print(J[i])
    exit()

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

X, Y, Z, K = LI()
A = sorted(LI(), reverse=True)
B = sorted(LI(), reverse=True)
C = sorted(LI(), reverse=True)

A = A[:min(250, X)]
B = B[:min(250, Y)]
C = C[:min(250, Z)]
# Aの中で最大の数字足すBの最大、Cの最大は全体の中で最大
# 3000個大きい順に求めれば良い

# iが決まれば、j,kのおおきさは分かる
BC = []
# 1000*1000 で10**6の計算量
#  for j in range(len(B)):
#      for k in range(len(C)):
#          BC.append(B[j] + C[k])

points = []
# 10**3 と 10** 6
#  for i in range(len(A)):
#      points += [bc + A[i] for bc in BC]
for i in range(len(A)):
    #  for bc in BC:
    #      points.append(A[i]+bc)
    for j in range(len(B)):
        for k in range(len(C)):
            points.append(A[i] + B[j] + C[k])
for i in sorted(points, reverse=True)[:K]:
    print(i)

Submission status: Wrong Answer

Solution code:
x, y, z, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

def m():
    a = A[:100]
    b = B[:100]
    c = C[:100]
    ans = []
    l = len(a)
    for i in range(l):
        for j in range(l):
            for p in range(l):
                ans.append(a[i]+b[j]+c[p])
    ans.sort(reverse=True)
    for i in range(k):
        print(ans[i])

m()

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

X, Y, Z, K = LI()
A = sorted(LI(), reverse=True)
B = sorted(LI(), reverse=True)
C = sorted(LI(), reverse=True)

A = A[:min(200, X)]
B = B[:min(200, Y)]
C = C[:min(200, Z)]
# Aの中で最大の数字足すBの最大、Cの最大は全体の中で最大
# 3000個大きい順に求めれば良い

# iが決まれば、j,kのおおきさは分かる
BC = []
# 1000*1000 で10**6の計算量
for j in range(len(B)):
    for k in range(len(C)):
        BC.append(B[j] + C[k])

points = []
# 10**3 と 10** 6
#  for i in range(len(A)):
#      points += [bc + A[i] for bc in BC]
for i in range(len(A)):
    #  for bc in BC:
    #      points.append(A[i]+bc)
    for j in range(len(B)):
        for k in range(len(C)):
            points.append(A[i] + B[j] + C[k])
for i in sorted(points, reverse=True)[:K]:
    print(i)

Submission status: Wrong Answer

Solution code:
INF = -10**11
x, y, z, k = [int(item) for item in input().split()]
a = sorted([int(item) for item in input().split()], reverse=True) + [INF]
b = sorted([int(item) for item in input().split()], reverse=True) + [INF]
c = sorted([int(item) for item in input().split()], reverse=True) + [INF]

num = x + y + z
ac, bc, cc = 0, 0, 0
ad = a[0] - a[1]
bd = b[0] - b[1]
cd = c[0] - c[1]
kadd = min(k, x*y*z)
while (ac+1) * (bc+1) * (cc+1) < kadd:
    if ad <= bd and ad <= cd:
        ac += 1
        ad = a[ac] - a[ac+1]
        while ad == 0:
            ac += 1
            ad = a[ac] - a[ac+1]
    elif bd <= ad and bd <= cd:
        bc += 1
        bd = b[bc] - b[bc+1]
        while bd == 0:
            bc += 1
            bd = b[bc] - b[bc+1]
    elif cd <= ad and cd <= bd:
        cc += 1
        cd = c[cc] - c[cc+1]
        while cd == 0:
            cc += 1
            cd = c[cc] - c[cc+1]

for i in range(5):
    if ac+1 < x:
        ac += 1
    if bc+1 < y:
        bc += 1
    if cc+1 < z:
        cc += 1

vals = []
for ai in a[:ac+1]:
    for bi in b[:bc+1]:
        for ci in c[:cc+1]:
            vals.append(ai+bi+ci)
vals.sort(reverse=True)
for i in range(k):
    print(vals[i])

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

a = [A[i] - A[i+1] for i in range(len(A)-1) ]
b = [B[i] - B[i+1] for i in range(len(B)-1) ]
c = [C[i] - C[i+1] for i in range(len(C)-1) ]

st = A[-1]+B[-1]+C[-1]

s_a,s_b,s_c = 1,1,1
for i in range(K-1):
    # どれを取るか選ぶ
    m = min(a[0] if len(a)>0 else 100000000001
            ,b[0] if len(b)>0 else 100000000001
            ,c[0] if len(c)>0 else 100000000001)
    #print(a[0],b[0],c[0])
    consider_list = [0]*3
    if len(a)>0 and a[0] == m:
        consider_list[0] = (s_a+1) * s_b * s_c

    if len(b)>0 and b[0] == m:
        consider_list[1] = (s_a) * (s_b+1) * s_c
    if len(c)>0 and c[0] == m:        
        consider_list[2] = (s_a) * (s_b) * (s_c+1)
    #print(consider_list.index(max(consider_list)))
    if consider_list.index(max(consider_list)) == 0:
        a.pop(0)
        s_a += 1
    elif consider_list.index(max(consider_list)) == 1:
        b.pop(0)
        s_b += 1
    else:
        c.pop(0)
        s_c += 1
    if s_a * s_b*s_c >= K:
        break

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[:s_a+2], B[:s_b+2],C[:s_c+2]))])[::-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()
b.sort()
c.sort()
d = []
for i in range(max(0,len(a)-100), len(a)):
    for j in range(max(0,len(b)-100), len(b)):
        for l in range(max(0,len(c)-100), len(c)):
            d.append(a[i]+b[j]+c[l])
d.sort()
for i in range(1,k+1):
    print(d[-i])

Submission status: Wrong Answer

Solution code:
import itertools
x,y,z,k = map(int,input().split())
X = sorted(list(map(int,input().split())),reverse=True)
Y = sorted(list(map(int,input().split())),reverse=True)
Z = sorted(list(map(int,input().split())),reverse=True)
if k > x*y*z:
    L = list(itertools.product(X,Y,Z))
    J = sorted([sum(i) for i in L],reverse=True)
    for i in range(k):
        print(J[i])
    exit()
else:
    L = list(itertools.product(X[0:16],Y[0:16],Z[0:16]))
    J = sorted([sum(i) for i in L],reverse=True)
    for i in range(k):
        print(J[i])
    exit()

Submission status: Wrong Answer

Solution code:
x, y, z, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

def m():
    a = A[:16]
    b = B[:16]
    c = C[:16]
    ans = []
    l = len(a)
    for i in range(l):
        for j in range(l):
            for p in range(l):
                ans.append(a[i]+b[j]+c[p])
    ans.sort(reverse=True)
    for i in range(k):
        print(ans[i])

m()