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: Runtime Error

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

x.sort(reverse=True)
if len(x)>k[3]:
  x = x[0:k[3]]

y.sort(reverse=True)
if len(y)>k[3]:
  y = y[0:k[3]]

z.sort(reverse=True)
if len(z)>k[3]:
  z = z[0:k[3]]

e = []

for i in x:
  for j in y:
    e.append(i+j)

g = []
for i in range(k[3]):
  g.append(e[i])

f = []

for i in g:
  for j in z:
    f.append(i+j)

f.sort(reverse=True)

for i in range(k[3]):
  print(f[i])

Submission status: Runtime Error

Solution code:
import itertools
x, y, z, k = map(int, input().split())
al = list(map(int,input().split())).sort(reverse=True)
bl = list(map(int,input().split())).sort(reverse=True)
cl = list(map(int,input().split())).sort(reverse=True)
 
sum_list = [sum(i) for i in itertools.product(al[:x//2], bl[:y//2], cl[:z//2])]
sum_list.sort(reverse=True)
for i in sum_list[:k]:
  print(i)

Submission status: Runtime Error

Solution code:
import itertools
x, y, z, k = map(int, input().split())
al = list(map(int,input().split())).sort(reverse=True)
bl = list(map(int,input().split())).sort(reverse=True)
cl = list(map(int,input().split())).sort(reverse=True)

sum_list = [sum(i) for i in itertools.product(al[:x//3], bl[:y//3], cl[:z//3])]
sum_list.sort(reverse=True)
for i in sum_list[:k]:
  print(i)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
using namespace std;
typedef long long ll;

struct Idx { int ia, ib, ic; };
bool used[1003][1003][1003];

int main() {
	int X, Y, Z, K; cin >> X >> Y >> Z >> K;
	vector<ll> a(X), b(Y), c(Z);
	for (int i = 0; i < X; i++) cin >> a[i];
	for (int i = 0; i < Y; i++) cin >> b[i];
	for (int i = 0; i < Z; i++) cin >> c[i];
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	deque<Idx> que;
	vector<ll> ans;
	que.push_back({ 0,0,0 });
	for (int i = 0; i < min(K + 10000, X*Y*Z); i++) {
		auto idx = que.front(); que.pop_front();
		int ia = idx.ia, ib = idx.ib, ic = idx.ic;
		ans.push_back(a[ia] + b[ib] + c[ic]);
		if (ia + 1 < X && !used[ia + 1][ib][ic]) {
			que.push_back({ ia + 1, ib, ic });
			used[ia + 1][ib][ic] = true;
		}
		if (ib + 1 < Y && !used[ia][ib + 1][ic]) {
			que.push_back({ ia, ib + 1, ic });
			used[ia][ib + 1][ic] = true;
		}
		if (ic + 1 < Z && !used[ia][ib][ic + 1]) {
			que.push_back({ ia, ib, ic + 1 });
			used[ia][ib][ic + 1] = true;
		}
	}
	sort(ans.rbegin(), ans.rend());
	for (int i = 0; i < K; i++) cout << ans[i] << endl;
	return 0;
}

Submission status: Runtime Error

Solution code:
from itertools import product

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

def solve():
  AB = []
  for a in A:
    for b in B:
      AB.append(a + b)

  AB.sort(reversed=True)
  AB = AB[:min(3001, X * Y * Z + 1)]
  ABC = []
  for ab in AB:
    for c in C:
      ABC.append(ab + c)
  ABC.sort(reverse=True)
  print(ABC[:K], sep='\n')

solve()

Submission status: Runtime Error

Solution code:
x, y, z, k = map(int, input().split())
a, b, c = [list(map(int, input().split())) for _ in range(3)]
d = sorted([a[i] + b[j] for i in range(x) for j in range(y)], reverse = True)[:k]
e = sorted([d[i] + c[j] for i in range(k) for j in range(z)], reverse = True)[:k]
for i in range(k):
    print(e[i])

Submission status: Runtime Error

Solution code:
import sys
# import bisect
# import math
# import itertools
# import numpy as np
# import collections

"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e, p = range, enumerate, print
    ip = IP()
    id = Idea()
    mod = 10 ** 9 + 7

    """この下から書いてね"""
    x, y, z, k = ip.IL()
    a = ip.IL()
    b = ip.IL()
    c = ip.IL()

    id.S(a, 1)
    id.S(b, 1)
    id.S(c, 1)

    ans = []

    for i, ai in e(x):
        if i > k:
            break
        for j, bi in e(y):
            if i * j > k:
                break
            for o, ci in e(z):
                if i * j * o > k:
                    break
                ans += [ai + bi + ci]

    id.S(ans, 1)
    for ans_p in ans:
        p(ans_p)


main()

Submission status: Runtime Error

Solution code:
N=list(map(int,(input().split(" "))))
teast=[]
K = N[3]
total=[]
c=0
for i in range(3):
    teast.append(list(map(int,input().split(" "))))
A=sorted(teast[0],reverse=True)
B=sorted(teast[1],reverse=True)
C=sorted(teast[2],reverse=True)

for i in range(len(A)):

    for j in range(len(B)):

        for k in range(len(C)):
            if i*j*k>K:
                break
            else:
                total.append(A[i]+B[j]+C[k])

total_s=sorted(total,reverse=True)

for i in range(K):
    print(total_

Submission status: Runtime Error

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)

l=[]
for s in range(a):
    for t in range(b):
        for u in range(c):
            if (s+1)*(t+1)*(u+1)<= k:
                l.append(a[s]+b[t]+c[u])
            else:
                break
l.sort(reverse=True)
for i in range(k):
    print(l[i])

Submission status: Runtime Error

Solution code:
N=list(map(int,(input().split(" "))))
teast=[]
K = N[3]
total=[]
for i in range(3):
    teast.append(list(map(int,input().split(" "))))
A=sorted(teast[0],reverse=True)
B=sorted(teast[1],reverse=True)
C=sorted(teast[2],reverse=True)
for i in range(len(A)):

    for j in range(len(B)):

        for k in range(len(C)):
            if a*b*c>K:
                break
            else:
                total.append(A[i]+B[j]+C[k])

total_s=sorted(total,reverse=True)

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

Submission status: Runtime Error

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

aa = list(map(int,input().split()))
aa.sort(reverse = True)
bb = list(map(int,input().split()))
bb.sort(reverse = True)
cc = list(map(int,input().split()))
cc.sort(reverse = True)
al = []
aal = []
for i in aa:
    for j in bb:
        al.append(i+j)
al.sort()
if len(al) > k:
    al = al[len(al)-k:]

for i in al:
    for j in cc:
        aal.appned(i+j)
aal.sort()

if len(aal) > k:
    aal = aal[len(aal)-k:]
aal.reverse()
for i in aal:
    print(i)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

X,Y,Z,K = (int(i) for i in input().split())
ax = [int(i) for i in input().split()]
by = [int(i) for i in input().split()]
cz = [int(i) for i in input().split()]
ans = [0] * (X*Y*Z)
cnt = 0
for i in ax:
  for j in by:
    for k in cz:
      ans[cnt] = i + j + k
      cnt += 1
ans.sort(reverse=True)
for i in range(K):
  print(ans[i])

Submission status: Runtime Error

Solution code:
import numpy as np
import sys

X,Y,Z,K = map(int,input().split())

A = np.array(sorted(list(map(int,input().split()))))[::-1]
B = np.array(sorted(list(map(int,input().split()))))[::-1]
C = np.array(sorted(list(map(int,input().split()))))[::-1]

zenbu = np.zeros(106307)
k = min(3000, K)

for x in range(len(A)):
    for y in range(len(B)):
        for z in range(len(C)):
            if x*y*z <= k:
                zenbu[x*Y*Z+y*Z+z] = A[x]+B[y]+C[z]

ichibu = np.partition(-zenbu, k-1)[:k]
ichibu.sort()
result = -ichibu.astype(np.int64)
for r in result:
    print(r)

Submission status: Runtime Error

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

e = []

for i in x:
  for j in y:
    e.append(i+j)

e.sort()
e.reverse()
print(e)
g = []
for i in range(k[3]):
  g.append(e[i])


f = []

for i in g:
  for j in z:
    f.append(i+j)

f.sort()
f.reverse()

for i in range(k[3]):
  print(f[i])

Submission status: Runtime Error

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 = []
ans = []
for a in A:
    for b in B:
        AB.append(a + b)
AB.sort(reverse=True)
AB = AB[:min(3001,X*Y*Z+1)]
for c in C:
    for ab in AB:
        ans.append(c + ab)
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
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()))
D = []
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
for i in range(min(K,X)):
    for j in range(min((K//(i+1),Y))):
        for k in range(min(((K//(i+1)+1)//(j+1)),Z)):
            D.append(A[i]+B[j]+C[k])
D.sort(reverse=True)
for i in range(K):
    print(int(D[i]))

Submission status: Runtime Error

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

sum = []

for i in a:
  for j in b:
    for k in c:
      sum.append(i+j+k)
      
sum.sort(reverse=True)

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

Submission status: Runtime Error

Solution code:
import numpy as np
import sys

X,Y,Z,K = map(int,input().split())

A = np.array(sorted(list(map(int,input().split()))))[::-1]
B = np.array(sorted(list(map(int,input().split()))))[::-1]
C = np.array(sorted(list(map(int,input().split()))))[::-1]

zenbu = np.zeros(X*Y*Z)
k = min(3000, K)

for x in range(len(A)):
    for y in range(len(B)):
        for z in range(len(C)):
            if x*y*z <= k:
                zenbu[x*Y*Z+y*Z+z] = A[x]+B[y]+C[z]

ichibu = np.partition(-zenbu, k-1)[:k]
ichibu.sort()
result = -ichibu.astype(np.int64)
for r in result:
    print(r)

Submission status: Runtime Error

Solution code:
def merge(x,y):
    ans = []
    l = len(x) + len(y)
    for i in range(l):
        if x[0] < y[0]:
            ans.append(y[0])
            if(len(y)<=1):
                ans.extend(x)
                break
            y = y[1:]
        else:
            ans.append(x[0])
            if(len(x)<=1):
                ans.extend(y)
                break
            x = x[1:]
    return ans

def sort(L):
    l = len(L)
    if l <= 1:
        return L
    else:
        b = l // 2
        left = sort(L[0:b])
        right = sort(L[b:])
        return merge(left,right)

k = 1
def sortK(L):
    l = len(L)
    if l <= 1:
        return L
    else:
        b = l // 2
        left = sort(L[0:b])
        right = sort(L[b:])
        ret = merge(left,right)
        return ret[0:min(len(ret),k)]

def find(l,t):
    a = 0
    b = len(l)
    while (b-a) > 0:
        c = (a+b) // 2
        tmp = l[c] 
        if c > t:
            a = c
        else:
            b = c
    return a

X,Y,Z,k=(int(x) for x in input().split())
cake = []
for i in range(3):
    tmp=[]
    for x in input().split():
        tmp.append(int(x))
    cake.append(sort(tmp))
mix = sortK(cake[0].append(cake[1]).append(cake[2]))
y = mix[k]
a = find(cake[0],y)
b = find(cake[1],y)
c = find(cake[2],y)

ans = []
for i in range(min(a+1,X)):
    for j in range(min(b+1,Y)):
        for k in range(min(c+1,Z)):
            ans.append(cake[0][i] + cake[1][j] + cake[2][k])

hoge = sort(ans)

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

Submission status: Runtime Error

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

aa = list(map(int,input().split()))
aa.sort(reverse = True)
bb = list(map(int,input().split()))
bb.sort(reverse = True)
cc = list(map(int,input().split()))
cc.sort(reverse = True)
al = []
aal = []
for i in aa:
    for j in bb:
        al.append(i+j)
al.sort()
if len(al) > k:
    al[len(al)-k:]

for i in al:
    for j in cc:
        aal.appned(i+j)
aal.sort()

if len(aal) > k:
    aal[len(aal)-k:]
aal.reverse()
for i in aal:
    print(i)

Submission status: Runtime Error

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

aa = list(map(int,input().split()))
aa.sort(reverse = True)
bb = list(map(int,input().split()))
bb.sort(reverse = True)
cc = list(map(int,input().split()))
cc.sort(reverse = True)
al = []
aal = []
for i in aa:
    for j in bb:
        al.append(i+j)
al.sort()
if len(al) > k:
    al[len(al)-k:]

for i in al:
    for j in cc:
        aal.appned(i+j)
aal.sort()

if len(aal) > k:
    aal[len(aal)-k:]
aal.reverse()
for i in aal:
    print(i)

Submission status: Runtime Error

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

counter = 0
a_idx = 0
b_idx = 0
c_idx = 0
while counter < k:
    print(a[a_idx] + b[b_idx] + b[b_idx])
    counter += 1

    a_diff = -1
    b_diff = -1
    c_diff = -1
    diff = []
    if a_idx < len(a) - 1:
        a_diff = a[a_idx] - a[a_idx + 1]
        diff.append(a_diff)
    if b_idx < len(b) - 1:
        b_diff = b[b_idx] - b[b_idx + 1]
        diff.append(b_diff)
    if c_idx < len(c) - 1:
        c_diff = c[c_idx] - c[c_idx + 1]
        diff.append(c_diff)
    min_diff = min(diff)

    for i, d in enumerate([a_diff, b_diff, c_diff]):
        if d == min_diff:
            if i == 0:
                a_idx += 1
            elif i == 1:
                b_idx += 1
            else:
                c_idx += 1

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

X,Y,Z,K = (int(i) for i in input().split())
ax = [int(i) for i in input().split()]
by = [int(i) for i in input().split()]
cz = [int(i) for i in input().split()]
ans = [0] * max(3000,X*Y*Z)
cnt = 0
for i in ax:
  for j in by:
    for k in cz:
      ans[cnt] = i + j + k
      cnt += 1
ans.sort(reverse=True)
for i in range(K):
  print(ans[i])

Submission status: Runtime Error

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)
s=[]
ss=[]
for i in A:
    for j in B:
        s+=[i+j]
s.sort(reverse=True)
s=s[:K-1]
for i in C:
    for j in s:
        ss+=[i+j]
ss.sort(reverse=True)
for i in range(K):
    print(ss[i])

Submission status: Runtime Error

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

ABC=[]
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i+1)*(j+1)*(k+1)>K:
                break
            else:
                ABC.append(X[i]+Y[j]+Z[k])
                
ABC.sort(reverse=True)

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

Submission status: Runtime Error

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_total_list = []
total_list = []

A.sort()
A.reverse()
if len(A) > K:
    A = A[0:K+1]

B.sort()
B.reverse()
if len(B) > K:
    B = B[0:K+1]

C.sort()
C.reverse()
if len(C) > K:
    C = C[0:K+1]

ab_total_list = []
for i in A:
    for j in B:
        ab_total_list.append(i+j)

ab_total_list.sort()
ab_total_list.reverse()
if len(ab_total_list) > K:
    ab_total_list = ab_total_list[0:K+1]

z = 0
min_total = 0
if K > len(ab_total_list):
    min_total = ab_total_list[-1]
else:
    min_total = ab_total_list[K]

for i in range(0, K):
    for j in range(0, int(K/(i+1))):
        if j >= len(C) or i >= len(ab_total_list):
            break
        total = ab_total_list[i] + C[j]
        total_list.append(total)
        if (i*j) > K:
            break

total_list.sort()
total_list.reverse()
for i in range(0, K):
    print(total_list[i])

Submission status: Runtime Error

Solution code:
#D問題
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 b in range(Y):
    for a in range(X):
        ab=A[a]+B[b]
        AB.append(ab)
AB.sort(reverse=True)
ABC=[]
roopk=max(K,X*Y)
roopz=max(K,Z)
for k in range(roopk):
    for c in range(roopz):
        abc=AB[k]+C[c]
        ABC.append(abc)
ABC.sort(reverse=True)
for i in range(K):
    print(ABC[i])

Submission status: Runtime Error

Solution code:
    # -*- coding: utf-8 -*-
     
    #input
    import numpy as np
    [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()))
     
    D = np.zeros(X*Y*Z+5)
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)
     
    #make list
    for i in range(min(K,X)):
        for j in range(min((K//(i+1))+1,Y)):
            for k in range(min(((K//(i+1))+1)//(j+1),Z)):
                    D.append(A[i]+B[j]+C[k])
    D.sort(reverse=True)
    for i in range(K):
        print(int(D[i]))

Submission status: Runtime Error

Solution code:
#D問題
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 b in range(Y):
    for a in range(X):
        ab=A[a]+B[b]
        AB.append(ab)
AB.sort(reverse=True)
ABC=[]
roopk=min(K,X*Y)
roopz=min(K,Z)
for k in range(roopk):
    for c in range(roopz):
        abc=AB[k]+C[c]
        ABC.append(abc)
ABC.sort(reverse=True)
for i in range(K):
    print(ABC[i])

Submission status: Runtime Error

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_total_list = []
total_list = []

A.sort()
A.reverse()
if len(A) > K:
    A = A[0:K+1]

B.sort()
B.reverse()
if len(B) > K:
    B = B[0:K+1]

C.sort()
C.reverse()
if len(C) > K:
    C = C[0:K+1]

ab_total_list = []
for i in A:
    for j in B:
        ab_total_list.append(i+j)

ab_total_list.sort()
ab_total_list.reverse()
if len(ab_total_list) > K:
    ab_total_list = ab_total_list[0:K+1]

z = 0
min_total = 0
if K > len(ab_total_list):
    min_total = ab_total_list[-1]
else:
    min_total = ab_total_list[K]

for i in range(0, K):
    for j in range(0, int(K/(i+1))):
        if j >= len(C):
            break
        total = ab_total_list[i] + C[j]
        total_list.append(total)
        if (i*j) > K:
            break

total_list.sort()
total_list.reverse()
for i in range(0, K):
    print(total_list[i])

Submission status: Runtime Error

Solution code:
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 = sorted(A)
B  = sorted(B)
C = sorted(C)

AB = []
for a in range(x):
    for b in range(y):
        AB.append(A[a] + B[b])
        
ans = []
for i in AB:
    for c in range(z):
        ans.append(i + C[c])
for i in sorted(ans, reverse=True)[0:k]:
    print(i)

Submission status: Runtime Error

Solution code:
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()]
A_B=[]
SUM=[]
for i in range(X):
  for j in range(Y):
    A_B.append(A[i]+B[j])
A_B.sort(reverse=True)
for i in range(K):
  for j in range(Z):
    SUM.append(A_B[i]+C[j])
SUM.sort(reverse=True)
for i in range(K):
  print(SUM[i])

Submission status: Runtime Error

Solution code:
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()]
C.sort(reverse=True)
A_B=[]
SUM=[]
for i in range(X):
  for j in range(Y):
    A_B.append(A[i]+B[j])
A_B.sort(reverse=True)
for i in range(K):
  for j in range(min(K,Z)):
    SUM.append(A_B[i]+C[j])
SUM.sort(reverse=True)
for i in range(K):
  print(SUM[i])

Submission status: Runtime Error

Solution code:

X, Y, Z, K = map(int, input().split())

A = [0]*X
A[:] = map(int, input().split())
B = [0]*Y
B[:] = map(int, input().split())
C = [0]*Z
C[:] = map(int, input().split())

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ABC = [0]*K
aL = 0
bL = 0
cL = 0
for x in range(X):
    if ABC[-1] > A[x]+B[bL]+C[cX]:
        for y in range(bL):
            for z in range(cL):
                ABC[-1] = max(ABC[-1], A[x]+B[y]+C[z])    
                ABC.sort(reverse=True)
    else:
        for y in range(Y):
            if ABC[-1] > A[x]+B[y]+C[cX]:
                bL = y
                for z in range(cL):
                    if ABC[-1] > A[x]+B[y]+C[z]:
                        cL = z
                        break
                    else:
                        ABC[-1] = max(ABC[-1], A[x]+B[y]+C[z])    
                        ABC.sort(reverse=True)
            else:
                for z in range(Z):
                    if ABC[-1] > A[x]+B[y]+C[z]:
                        cX = z
                        break
                    else:
                        ABC[-1] = max(ABC[-1], A[x]+B[y]+C[z])    
                        ABC.sort(reverse=True)
            
for k in range(K):
    print(ABC[k])

Submission status: Runtime Error

Solution code:
if __name__=="__main__":
    import sys
    import heapq
    readline = sys.stdin.readline
    X,Y,Z,K = map(int, readline().split())
    a = sorted(list(map(int, readline().split())), reverse=True)
    b = sorted(list(map(int, readline().split())), reverse=True)
    c = sorted(list(map(int, readline().split())), reverse=True)

    sums = heapq([])
    lower = a[min(X-1,14)]+b[min(Y-1,14)]+c[min(Z-1,14)]
    b_max,c_max = max(b),max(c)
    for i in range(X):
        if a[i]+b_max+c_max<lower:
            break
        for j in range(Y):
            if a[i]+b[j]+c_max<lower:
                break
            for k in range(Z):
                s = a[i]+b[j]+c[k]
                if s<lower:
                    break
                heapq.heappush(sums, s)
    for si in sums[:K]:
        print(si)

Submission status: Runtime Error

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)
b = sorted(b)
c = sorted(c)

la = []

for i in range(x):
    s = 3000-i
    for n in range(max(y-5-3000/s,0),y):
        u = 3000-n
        for m in range(max(z-5-3000/(s*u),0),z):
            la.append(a[i]+b[n]+c[m])

la = sorted(la)

for i in range(k):
    print(la[-i-1])

Submission status: Runtime Error

Solution code:

X, Y, Z, K = map(int, input().split())

A = [0]*X
A[:] = map(int, input().split())
B = [0]*Y
B[:] = map(int, input().split())
C = [0]*Z
C[:] = map(int, input().split())

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ABC = [0]*K
aL = 0
bL = 0
cL = 0
for x in range(X):
    if ABC[-1] > A[x]+B[bL]+C[cX]:
        for y in range(bL):
            for z in range(cL):
                ABC[-1] = max(ABC[-1], A[x]+B[y]+C[z])    
                ABC.sort(reverse=True)
    else:
        for y in range(Y):
            if ABC[-1] > A[x]+B[y]+C[cX]:
                bL = 
                for z in range(cL):
                    if ABC[-1] > A[x]+B[y]+C[z]:
                        cL = z
                        break
                    else:
                        ABC[-1] = max(ABC[-1], A[x]+B[y]+C[z])    
                        ABC.sort(reverse=True)
            else:
                for z in range(Z):
                    if ABC[-1] > A[x]+B[y]+C[z]:
                        cX = z
                        break
                    else:
                        ABC[-1] = max(ABC[-1], A[x]+B[y]+C[z])    
                        ABC.sort(reverse=True)
            
for k in range(K):
    print(ABC[k])

Submission status: Runtime Error

Solution code:
from collections import OrderedDict
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)

summs_ab = []
summs = []
for a in A:
    for b in B:
        summs_ab.append(a+b)
summs_ab.sort(reverse=True)
summs_ab = summs_ab[0:min(3001, X*Y*Z+1)]

for c in C:
    for sab in summs_ab:
        summs.append(sab+c)
summs.sort(reverse=True)

for i in K:
    print(summs[i])