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:
x,y,z,q=map(int,input().split())
*a,=map(int,input().split())
*b,=map(int,input().split())
*c,=map(int,input().split())
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

class bisect:
  def bisect(self,l,r):
    cnt=(l+r)//2
    if cnt==l:
      return l-1+self.judge(l)
    if self.judge(cnt):
      return self.bisect(cnt+1,r)
    else:
      return self.bisect(l,cnt)
  def judge(self,thr):
    m=0
    for i in a:
      for j in b:
        for k in c:
          if i+j+k>thr:
            m+=1
            if m>=q:
              return True
    return False

def make(thr):
  m=0
  l=[]
  for i in a:
    for j in b:
      for k in c:
        n=i+j+k
        if n>thr:
          m+=1
          l+=[n]
          if m>=q:
            l.sort(reverse=True)
            return l

s=bisect()
thr=s.bisect(0,a[0]+b[0]+c[0]+1,0)
ans=make(thr)
for w in ans:
  print(w)

Submission status: Runtime Error

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)

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

AB.sort(reverse=True)

ABC = []
for i in range(min(a * b, k)):
    for c in C:
        ABC.append(AB[i] + c)

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())
cs = list(map(int, input().split()))
bs = list(map(int, input().split()))
a_s = list(map(int, input().split()))
a_s.sort(reverse=True)
bs.sort(reverse=True)
cs.sort(reverse=True)

list = []
i = -1
m = int(k/4)
minlist = 0
if m < min(len(a_s), len(bs), len(cs)):
    minlist = a_s[m] + bs[m] + cs[m]
for a in a_s:
    if minlist >= (a + bs[0] + cs[0]):
        break
    for b in bs:
        if minlist >= (a + b + cs[0]):
            break
        for c in cs:
            abc = a + b +c
            if minlist >= abc:
                break
            list.append(abc)
            i += 1
list.sort(reverse=True)
for i in range(k):
    print(list[i])

Submission status: Runtime Error

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

list = []
i = -1
m = int(k/3)
minlist = 0
if m < min(len(a_s), len(bs), len(cs)):
    minlist = a_s[m] + bs[m] + cs[m]
for a in a_s:
    if minlist >= (a + bs[0] + cs[0]):
        break
    for b in bs:
        if minlist >= (a + b + cs[0]):
            break
        for c in cs:
            abc = a + b +c
            if minlist >= abc:
                break
            list.append(abc)
            i += 1
list.sort(reverse=True)
for i in range(k):
    print(list[i])

Submission status: Runtime Error

Solution code:
/*
g++ main.cpp --std=c++14; ./a.out < input.txt
*/
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<tuple>

using namespace std;

const auto mod = 1000000007L;

typedef long long ll;

template<typename T>
using V = vector<T>;

template<typename K, typename V>
using M = map<K,V>;

ll sum(tuple<ll,ll,ll> const & t, V<ll> const & A, V<ll> const & B, V<ll> const & C) {
        auto a = get<0>(t);
        auto b = get<1>(t);
        auto c = get<2>(t);
        return A[a]+B[b]+C[c];
}

int main() {
    int X,Y,Z,K;
    cin>>X>>Y>>Z>>K;
    auto A=V<ll>(X);
    for(size_t i = 0; i < X; i++)cin>>A[i];
    sort(A.begin(), A.end(), [](auto a, auto b){return a>b;});
    auto B=V<ll>(Y);
    for(size_t i = 0; i < Y; i++)cin>>B[i];
    sort(B.begin(), B.end(), [](auto a, auto b){return a>b;});
    auto C=V<ll>(Z);
    for(size_t i = 0; i < Z; i++)cin>>C[i];
    sort(C.begin(), C.end(), [](auto a, auto b){return a>b;});
    auto Q=multimap<ll, tuple<ll, ll, ll>, greater<ll>>();
    Q.insert(decltype(Q)::value_type(sum(make_tuple(0,0,0), A, B, C), make_tuple(0,0,0)));
    for(size_t k = 0; k < K; k++)
    {
        auto t = Q.begin();
        cout << t->first << "\n";
        auto a = get<0>(t->second);
        auto b = get<1>(t->second);
        auto c = get<2>(t->second);
        Q.erase(t) ;
        auto d=make_tuple(a, b, c+1);
        if (c+1<X) Q.insert(decltype(Q)::value_type(sum(d, A, B, C), d));
        auto e=make_tuple(a, b+1, c);
        if (c+1<Y) Q.insert(decltype(Q)::value_type(sum(e, A, B, C), e));
        auto f=make_tuple(a+1, b, c);
        if (c+1<Z) Q.insert(decltype(Q)::value_type(sum(f, A, B, C), f));
    }
}

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

li = []

for i in a:
    for j in rangeb:
        li.append(i + j)
        
li.sort(reverse = True)
li = li[:min(k,x*y)]

box = []

for i in li:
    for j in c:
        box.append(i + j)

box.sort(reverse = True)

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

Submission status: Runtime Error

Solution code:
import itertools
x,y,z,t = 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(reveres = True)
c.sort(reverse = True)
ans = []
for i in range(x):
    for k in range(y):
        ans.append(a[i]+b[k])
ans.sort(reverse = True)
if x*y > t:
    ans = ans[0:t]
    l = t
else:
    l = x*y
out = []

for i in range(l):
    for k in range(z):
        out.append(ans[i]+c[k])
out.sort(reverse = True)
for i in range(t):
    print(out[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)
tem=[]
ans=[]

for i in a:
  for j in b:
    tem.append(i+j)
    
tem=tem[:min(3001,x*y*z+1)]

for k in c:
  for l in tem:
    ans.append(k+l)
    
ans.sort()

for m in range(k):
  print(ans[m])

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from string import ascii_uppercase
import sys, bisect
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

X, Y, Z, K = read_int()
A = read_int()
A.sort(reverse=True)
B = sorted(read_int())
C = sorted(read_int())

maxd = max(A) + max(B) + max(C)
mind = min(A) + min(B) + min(C)

yz = []
def solve():
    for i in range(Y):
        for j in range(Z):
            yz.append(B[i] + C[j])
    yz.sort(reverse=True)

    res = []
    for i in range(X):
        for j in range(K):
            res.append(A[i] + yz[j])
    res.sort(reverse=True)
    for i in range(K):
        print(res[i])


if __name__ == "__main__":
    solve()

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 = []
for i in range(X):
    for j in range(Y):
        ab.append(A[i] + B[j])

ab.sort()
ab.reverse()

del ab[K-1:]

abc = []
for i in range(len(ab)):
    for j in range(Z):
        abc.append(ab[i] + C[j])

abc.sort()
abc.reverse()

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

Submission status: Runtime Error

Solution code:
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")

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

A = sorted(list( map(int, input().split()) ), reverse=True)	# 1 2 3 4 5 ...(ソート付き)
B = sorted(list( map(int, input().split()) ), reverse=True)	# 1 2 3 4 5 ...(ソート付き)
C = sorted(list( map(int, input().split()) ), reverse=True)	# 1 2 3 4 5 ...(ソート付き)

p(X,Y,Z,K)
p(A)
p(B)
p(C)

#ABC=[]
#for a in range(X):
#	for b in range(Y):
#		if (a+b)>K: break
#		for c in range(Z):
#			if (a+b+c)>K: break
#			ABC.append(A[a]+B[b]+C[c])
#
#ABC.sort(reverse=True)

AB=[]
for a in range(X):
  for b in range(Y):
    AB.append(A[a]+B[b])

AB.sort(reverse=True)
p("AB=",AB)

ABC=[]
for ab in range(min(k,len(AB))):
  for c in range(Z):
    ABC.append(AB[ab]+C[c])

ABC.sort(reverse=True)
p("ABC=",ABC)

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

Submission status: Runtime Error

Solution code:
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")

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

A = sorted(list( map(int, input().split()) ), reverse=True)	# 1 2 3 4 5 ...(ソート付き)
B = sorted(list( map(int, input().split()) ), reverse=True)	# 1 2 3 4 5 ...(ソート付き)
C = sorted(list( map(int, input().split()) ), reverse=True)	# 1 2 3 4 5 ...(ソート付き)

p(X,Y,Z,K)
p(A)
p(B)
p(C)

#ABC=[]
#for a in range(X):
#	for b in range(Y):
#		if (a+b)>K: break
#		for c in range(Z):
#			if (a+b+c)>K: break
#			ABC.append(A[a]+B[b]+C[c])
#
#ABC.sort(reverse=True)

AB=[]
for a in range(X):
	for b in range(Y):
		AB.append(A[a]+B[b])

AB.sort(reverse=True)
p("AB=",AB)

ABC=[]
for ab in range(min(k,len(AB))):
	for c in range(Z):
		ABC.append(AB[ab]+C[c])

ABC.sort(reverse=True)
p("ABC=",ABC)

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

Submission status: Runtime Error

Solution code:
import heapq
hq=[]
X, Y, Z, K= map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
B=list(map(int,input().split()))
B.sort(reverse=True)
C=list(map(int,input().split()))
C.sort(reverse=True)
searched={(0,0,0)}
heapq.heappush(hq,(-(A[0]+B[0]+C[0]),0,0,0))
D=[[1,0,0],[0,1,0],[0,0,1]]

for _ in range(K):
    abc,x,y,z=heapq._heappop_max(hq)
    print(-abc)
    for dx,dy,dz in D:
        if x+dx<X and y+dy < Y and z+dz < Z and (x+dx,y+dy,z+dz) not in searched:
            heapq.heappush(hq,(-(A[x+dx]+B[y+dy]+C[z+dz]),x+dx,y+dy,z+dz))
            searched.add((x+dx,y+dy,z+dz))

Submission status: Runtime Error

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

A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

def qsort(inlist, reverse=True):
    if inlist == []: 
        return []
    else:
        pivot = inlist[0]
        if reverse == False:
            lesser = qsort([x for x in inlist[1:] if x < pivot])
            greater = qsort([x for x in inlist[1:] if x >= pivot])
        else:
            lesser = qsort([x for x in inlist[1:] if x >= pivot])
            greater = qsort([x for x in inlist[1:] if x < pivot])
        return lesser + [pivot] + greater
      
val_list = []


A_list = qsort(A_list, reverse=True)
B_list = qsort(B_list, reverse=True)
C_list = qsort(C_list, reverse=True)

#print(A_list)
#print(B_list)
#print(C_list)

for a in range(len(A_list)):
    if a + 1 > K:
        break
    for b in range(len(B_list)):
        if b + 1 > K:
            break
        if (a+1) * (b+1) > K:
            break
            
        for c in range(len(C_list)):
            if c + 1 > K:
                break
            if (a+1) * (b+1) * (c+1) > K:
                break
        
            val_list.append(A_list[a] + B_list[b] + C_list[c])

val_list = qsort(val_list, reverse=True)
for i in range(K):
    print(val_list[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()))

r=[]
out=[]

for i in range(X):
    for j in range(Y):
        r.append(A[i]+B[j])

r.sort(reverse=True)

for i in range(K):
    for j in range(Z):
        out.append(r[i]+C[j])

out.sort(reverse=True)

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

Submission status: Runtime Error

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

A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

def qsort(inlist, reverse=True):
    if inlist == []: 
        return []
    else:
        pivot = inlist[0]
        if reverse == False:
            lesser = qsort([x for x in inlist[1:] if x < pivot])
            greater = qsort([x for x in inlist[1:] if x >= pivot])
        else:
            lesser = qsort([x for x in inlist[1:] if x >= pivot])
            greater = qsort([x for x in inlist[1:] if x < pivot])
        return lesser + [pivot] + greater
      
val_list = []


A_list = qsort(A_list, reverse=True)
B_list = qsort(B_list, reverse=True)
C_list = qsort(C_list, reverse=True)

#print(A_list)
#print(B_list)
#print(C_list)

for a in range(len(A_list)):
    if a + 1 > K:
        break
    for b in range(len(B_list)):
        if b + 1 > K:
            break
        if (a+1) * (b+1) > K:
            continue
            
        for c in range(len(C_list)):
            if c + 1 > K:
                break
            if (a+1) * (b+1) * (c+1) > K:
                continue
        
            val_list.append(A_list[a] + B_list[b] + C_list[c])

val_list = qsort(val_list, reverse=True)
for i in range(K):
    print(val_list[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 = []
count = 0
for i in range(X):
    for j in range(Y):
        ab.append(A[i] + B[j])

ab.sort()
ab.reverse()

del ab[K-1:]

abc = []
for i in range(len(ab)):
    for j in range(Y):
        abc.append(ab[i] + C[j])

abc.sort()
abc.reverse()

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

Submission status: Runtime Error

Solution code:
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")

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

A = sorted(list( map(int, input().split()) ), reverse=True)	# 1 2 3 4 5 ...(ソート付き)
B = sorted(list( map(int, input().split()) ), reverse=True)	# 1 2 3 4 5 ...(ソート付き)
C = sorted(list( map(int, input().split()) ), reverse=True)	# 1 2 3 4 5 ...(ソート付き)

p(X,Y,Z,K)
p(A)
p(B)
p(C)

#ABC=[]
#for a in range(X):
#	for b in range(Y):
#		if (a+b)>K: break
#		for c in range(Z):
#			if (a+b+c)>K: break
#			ABC.append(A[a]+B[b]+C[c])
#
#ABC.sort(reverse=True)

AB=[]
for a in range(X):
	for b in range(Y):
		if (a+b)>K: break
		AB.append(A[a]+B[b])

AB.sorted(reverse=True)

ABC=[]
for ab in range(len(AB)):
	if ab>K: break
	for c in range(Z):
		if (ab+c)>K: break
		ABC.append(AB[ab]+C[c]

ABC.sorted(reverse=True)

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

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 = []
count = 0
for i in range(X):
    for j in range(Y):
        ab.append(A[i] + B[j])

C.sort()
C.reverse()
ab.sort()
ab.reverse()

del ab[K-1:]

abc = []
for i in range(len(ab)):
    for j in range(Z):
        abc.append(ab[i] + C[j])

abc.sort()
abc.reverse()

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

Submission status: Runtime Error

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

A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

K = 2

import itertools
val_list = []


A_list = sorted(A_list, reverse=True)
B_list = sorted(B_list, reverse=True)
C_list = sorted(C_list, reverse=True)

#print(A_list)
#print(B_list)
#print(C_list)

for a, b, c in itertools.product(range(len(A_list)), range(len(B_list)), range(len(C_list))):
    if (a+1) * (b+1) * (c+1) > K:
        continue
        
    val_list.append(A_list[a] + B_list[b] + C_list[c])

val_list = sorted(val_list, reverse=True)
for i in range(K):
    print(val_list[i])

Submission status: Runtime Error

Solution code:
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")

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

A = sorted(list( map(int, input().split()) ), reverse=True)	# 1 2 3 4 5 ...(ソート付き)
B = sorted(list( map(int, input().split()) ), reverse=True)	# 1 2 3 4 5 ...(ソート付き)
C = sorted(list( map(int, input().split()) ), reverse=True)	# 1 2 3 4 5 ...(ソート付き)

p(X,Y,Z,K)
p(A)
p(B)
p(C)

ABC=[]
for a in range(X):
	for b in range(Y):
		if (a+1+b+1)>K: break
		for c in range(Z):
			if (a+1+b+1+c+1)>K: break
			ABC.append(A[a]+B[b]+C[c])

ABC.sort(reverse=True)

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

Submission status: Runtime Error

Solution code:
#実験をしっかりとしよう
X,Y,Z,K = (int(_) for _ in input().split())
A = (int(_) for _ in input().split())
B = (int(_) for _ in input().split())
C = (int(_) for _ in input().split())
#この手の問題はまずsortする(今回は大きい順の方がすっきり)
A = sorted(A)
B = sorted(B)
C = sorted(C)
#Aのa位とb位とc位ならその上にはa*b*c-1(自分以外)が上にいる。
A.reverse()
B.reverse()
C.reverse()

ABC = []
for i in range(len(A)):
    for j in range(len(B)):
        if (i+1)*(j+1) > K:
            break
        for k in range(len(C)):
            if (i+1)*(j+1)*(k+1) > K:
                break
            ABC.append(A[i]+B[j]+C[k])
ABC.sort().reverse()

for i in range(K):
    print(ABC[i])
#pythonだとTLEになる?

Submission status: Runtime Error

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 = 0
# flag = True
minlist = 0
for a in a_s:
    if minlist >= (a + bs[0] + cs[0]):
        break
    for b in bs:
        if minlist >= (a + b + cs[0]):
            break
        for c in cs:
            abc = a + b +c
            if i >= k:
            # if flag and i >= k:
                list.sort(reverse=True)
                minlist = list[k]
                # flag = False
            if minlist >= abc:
                break
            list.append(a + b + c)
            i += 1
list.sort(reverse=True)
for i in range(k):
    print(list[i])

Submission status: Runtime Error

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

res = []
x, y, z, K = na()
a_li = na()
b_li = na()
c_li = na()
list.sort(a_li,reverse=True)
list.sort(b_li,reverse=True)
list.sort(c_li,reverse=True)
for i in range(x):
    for j in range(y):
        for k in range(z):
            if (i + 1) * (j + 1) * (k + 1) <= k:
                res.append(a_li[i] * b_li[j] + c_li[k])
            else:
                break

list.sort(res, reverse=True)
for i in range(K):
    print(res[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)

result = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i + 1) * (j + 1) * (k + 1) <= K:
                result.append(A[i] + B[j] + C[k])
            else:
                break
result.sort(reversed=True)
for rs in result[:K]:
    print(rs)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
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)

abc = []

for i, _a in enumerate(a):
    for j, _b in enumerate(b):
        if (i+1) * (j+1) > k:
            break
        for l, _c in enumerate(c):
            if (i+1) * (j+1) * (l+1) > k:
                break
            abc.append(_a + _b + _c)

for x in abc.sort(reverse=True)[:k]:
    print(x)

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

q = [(a[0]+b[0]+c[0], 0, 0, 0)]
t = []
for i in range(min(x*y*z, k)):
  m = q.pop(q.index(max(q, key=lambda x: x[0])))
  print(m[0])
  if m[1] < x-1:
    next_a = (a[m[1]+1]+b[m[2]]+c[m[3]], m[1]+1, m[2], m[3])
  if m[2] < y-1:
    next_b = (a[m[1]]+b[m[2]+1]+c[m[3]], m[1], m[2]+1, m[3])
  if m[3] < z-1:
    next_c = (a[m[1]]+b[m[2]]+c[m[3]+1], m[1], m[2], m[3]+1)
  if next_a not in t:
    q.append(next_a)
    t.append(next_a)
  if next_b not in t:
    q.append(next_b)
    t.append(next_b)
  if next_c not in t:
    q.append(next_c)
    t.append(next_c)

Submission status: Runtime Error

Solution code:
import sys,bisect
input = sys.stdin.readline
X,Y,Z,K = map(int,input().split())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))
ABC = [A[0]+B[0]+C[0]]
SumABC = []
i,j,k = 0,0,0
while len(SumABC) < K:
	if i < X-2:
		bisect.insort(ABC,A[i+1]+B[j]+C[k])
	if j < Y-2:
		bisect.insort(ABC,A[i]+B[j+1]+C[k])
	if k < Z-2:
		bisect.insort(ABC,A[i]+B[j]+C[k+1])
	SumABC.append(ABC.pop(0))
	if i < X-2:
		i += 1
	if j < Y-2:
		j += 1
	if k < Z-2:
		k += 1
SumABC.reverse()
for i in SumABC:
	print(i)

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)
y.sort(reverse=True)
z.sort(reverse=True)

for i in len(x):
  for j in len(y):
    for l in len(z):
      if (x+1)*(y+1)*(z+1) <= k[3]:
        SUM.append(x[i]+y[j]+z[l])
      else:
        break

SUM.sort(reverse=True)

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

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)
y.sort(reverse=True)
z.sort(reverse=True)

for i in len(x)
  for j in len(y)
    for l in len(z)
      if x*y*z =< k[3]:
        SUM.append(x[i+1]+y[j+1]+z[l+1])
      else:
        break

SUM.sort(reverse=True)

for i in range(k[3])
  print(SUM[i])

Submission status: Runtime Error

Solution code:
#実験をしっかりとしよう
X,Y,Z,K = (int(_) for _ in input().split())
A = (int(_) for _ in input().split())
B = (int(_) for _ in input().split())
C = (int(_) for _ in input().split())
#この手の問題はまずsortする(今回は大きい順の方がすっきり)
A = sorted(A).reverse()
B = sorted(B).reverse()
C = sorted(C).reverse()
#総和は変わらないので残ったやつの累積和で考えてみる。
#1000*1000なら全列挙できるそのうち3000個を取り除いて、3の1000個を
#それに組み合わせて全探索する。(2重forかな)
AB = []

for i in range(X):
    for j in range(Y):
        AB.append(A[i]+B[i])
AB = sorted(AB).reverse()[:3001]

ABC = []
for i in range(len(AB)):
    for j in range(Z):
        ABC.append(AB[i]+C[j])

ABC = sorted(ABC).reverse()
for i in range(3000):
    print(ABC[i])

Submission status: Runtime Error

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):
		if((i+1) * (j+1) > in_k) break
		for k in range(z):
			ans_arr.append(in_x[i] + in_y[j] + in_z[k])
			if((i+1) * (j+1) * (k+1) > in_k) break

ans_arr = sorted(ans_arr,reverse=True)

for i in range(in_k):
	print(ans_arr[i])

Submission status: Runtime Error

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

X, Y, Z, K = map(int, input().split())
A = sorted(map(int, input().split()), reverse=True)
B = sorted(map(int, input().split()), reverse=True)
C = sorted(map(int, input().split()), reverse=True)

ABC = []

for x in X:
    for y in Y:
        if (x + 1) * (y + 1) > K:
            break
        for z in Z:
            if (x + 1) * (y + 1) + (z + 1) > K:
                break
            ABC.append(A[x] + B[y] + C[z])

ABC = sorted(ABC, reverse=True)

ABC = ABC[:K]
ABC = [str(abc) for abc in ABC]

print("\n".join(ABC))

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)
y.sort(reverse=True)
z.sort(reverse=True)

for i in len(x)
  for j in len(y)
    for l in len(z)
      if x*y*z =< k[3]:
        SUM.append(x[i]+y[j]+z[l])
      else:
        break

SUM.sort(reverse=True)

for i in range(k[3])
  print(SUM[i])

Submission status: Runtime Error

Solution code:
x,y,z,w=map(int,input().split())
lx=list(map(int,input().split()))
ly=list(map(int,input().split()))
lz=list(map(int,input().split()))
lxy=[]
for i in range(x):
  for j in range(y):
    lxy.append(lx[i]+ly[j])
lxy=sorted(lxy)
lxy=lxy[::-1]
l=[]
for i in range(w):
  l.append(lxy[i])
lxyz=[]
for i in range(z):
  for j in range(w):
    lxyz.append(lz[i]+l[j])
lxyz=sorted(lxyz)
lxyz=lxyz[::-1]
for i in range(w):
  print(lxyz[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)
ans = []

ApB = []

for i in range(min(X, K)):
  for j in range(min(Y, K)):
      ApB.append(A[i] + B[j])

ApB.sort(reverse = True)

for i in range(min(Z, K)):
  for j in range(int(min(len(ApB), K) / (i + 1)):
    ans.append(C[i] + ApB[j])

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 = sorted(a, reverse=True)
b = sorted(b, reverse=True)
c = sorted(c, reverse=True)

q = [(a[0]+b[0]+c[0], 0, 0, 0)]
for i in range(min(x*y*z, k)):
  m = q.pop(q.index(max(q, key=lambda x: x[0])))
  print(m[0])
  if m[1] < x-1:
  	next_a = (a[m[1]+1]+b[m[2]]+c[m[3]], m[1]+1, m[2], m[3])
  if m[2] < y-1:
    next_b = (a[m[1]]+b[m[2]+1]+c[m[3]], m[1], m[2]+1, m[3])
  if m[3] < z-1:
    next_c = (a[m[1]]+b[m[2]]+c[m[3]+1], m[1], m[2], m[3]+1)
  if next_a not in q:
    q.append(next_a)
  if next_b not in q:
    q.append(next_b)
  if next_c not in q:
    q.append(next_c)

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

q = [(a[0]+b[0]+c[0], 0, 0, 0)]
for i in range(min(x*y*z, k)):
  m = q.pop(q.index(max(q, key=lambda x: x[0])))
  print(m[0])
  next_a = (a[m[1]+1]+b[m[2]]+c[m[3]], m[1]+1, m[2], m[3])
  next_b = (a[m[1]]+b[m[2]+1]+c[m[3]], m[1], m[2]+1, m[3])
  next_c = (a[m[1]]+b[m[2]]+c[m[3]+1], m[1], m[2], m[3]+1)
  if next_a not in q:
    q.append(next_a)
  if next_b not in q:
    q.append(next_b)
  if next_c not in q:
    q.append(next_c)

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]+1]

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

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

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

q = [(a[0]+b[0]+c[0], 0, 0, 0)]
for i in range(k):
  m = q.pop(q.index(max(q, key=lambda x: x[0])))
  print(m[0])
  next_a = (a[m[1]+1]+b[m[2]]+c[m[3]], m[1]+1, m[2], m[3])
  next_b = (a[m[1]]+b[m[2]+1]+c[m[3]], m[1], m[2]+1, m[3])
  next_c = (a[m[1]]+b[m[2]]+c[m[3]+1], m[1], m[2], m[3]+1)
  if next_a not in q:
    q.append(next_a)
  if next_b not in q:
    q.append(next_b)
  if next_c not in q:
    q.append(next_c)

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)
ans = []

ApB = []

for i in range(min(X, K)):
  for j in range(min(Y, K)):
      ApB.append(A[i] + B[j])

ApB.sort(reverse = True)

for i in range(min(Z, K)):
  for j in range(min(ApB.count() + 1, K)):
    ans.append(C[i] + ApB[j])

ans.sort(reverse = True)
    
for i in range(K):
  print(ans[i])