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:
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

// An Item is something we manage in a priority queue.
type Item struct {
	value    []int
	priority int
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	//We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority >= pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func Equal(a, b []int) bool {
	if len(a) != len(b) {
		return false
	}
	for i, v := range a {
		if v != b[i] {
			return false
		}
	}
	return true
}

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func exists(pq PriorityQueue, item *Item) bool {
	for i := 0; i < pq.Len(); i++ {
		if pq[i].priority == item.priority && Equal(pq[i].value, item.value) {
			return true
		}
	}
	return false
}

func main() {
	line1 := nextLine()
	XYZK := strings.Split(line1, " ")
	X, _ := strconv.Atoi(XYZK[0])
	Y, _ := strconv.Atoi(XYZK[1])
	Z, _ := strconv.Atoi(XYZK[2])
	K, _ := strconv.Atoi(XYZK[3])
	line2 := nextLine()
	line3 := nextLine()
	line4 := nextLine()
	a := strings.Split(line2, " ")
	b := strings.Split(line3, " ")
	c := strings.Split(line4, " ")
	A := make([]int, X)
	B := make([]int, Y)
	C := make([]int, Z)

	for i := 0; i < X; i++ {
		A[i], _ = strconv.Atoi(a[i])
	}
	for i := 0; i < Y; i++ {
		B[i], _ = strconv.Atoi(b[i])
	}
	for i := 0; i < Z; i++ {
		C[i], _ = strconv.Atoi(c[i])
	}
	sort.Slice(A, func(i, j int) bool {
		return A[i] >= A[j]
	})
	sort.Slice(B, func(i, j int) bool {
		return B[i] >= B[j]
	})
	sort.Slice(C, func(i, j int) bool {
		return C[i] >= C[j]
	})
	pq := make(PriorityQueue, 1)
	item0 := &Item{
		value:    []int{0, 0, 0},
		priority: A[0] + B[0] + C[0],
		index:    0,
	}
	pq[0] = item0
	heap.Init(&pq)
	ans := make([]int, K)
	for ind := 0; ind < K; ind++ {
		item := heap.Pop(&pq).(*Item)
		p := item.priority
		i := item.value[0]
		j := item.value[1]
		k := item.value[2]
		ans[ind] = p

		if i+1 < X && j < Y && k < Z {
			item1 := &Item{
				value:    []int{i + 1, j, k},
				priority: A[i+1] + B[j] + C[k],
			}
			if !exists(pq, item1) {
				heap.Push(&pq, item1)
			}
		}

		if i < X && j+1 < Y && k < Z {
			item2 := &Item{
				value:    []int{i, j + 1, k},
				priority: A[i] + B[j+1] + C[k],
			}
			if !exists(pq, item2) {
				heap.Push(&pq, item2)
			}
		}

		if i < X && j < Y && k+1 < Z {
			item3 := &Item{
				value:    []int{i, j, k + 1},
				priority: A[i] + B[j] + C[k+1],
			}
			if !exists(pq, item3) {
				heap.Push(&pq, item3)
			}
		}
	}
	for _, v := range ans {
		fmt.Println(v)
	}
}

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)
t = []
for i in range(x):
    for j in range(y):
        for l in (range(z):
            if (i+1) * (j+1) * (l+1) <= k:
                t.append(a[i]+b[j]+c[l])
            else:
                break
t.sort(reverse=True)
for i in range(k):
    print(t[i])

Submission status: Runtime Error

Solution code:
X, Y, Z, K = map(int, input().split())
A = [int(x) for x in input().split()]
B = list(map(int, input().split()))
C = [int(x) for x in input().split()]
AB = []
for i in A:
  for j in B:
    AB.append(i + j)
AB.sort(reverse = True)
ABC = []
for i in range(K):
  for j in C:
    ABC.append(AB[i] + j)
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()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
ans = []
for i in set(range(x)):
    for j in set(range(y)):
        for l in set(range(z)):
            if (i+1) * (j+1) * (l+1) <= k:
                ans.append(a[i]+b[j]+c[l])
            else:
                break
ans.sort(reverse=True)
for ans in range(k):
    print(ans[i])

Submission status: Runtime Error

Solution code:
import sys; sys.setrecursionlimit(50000)
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.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

cnt = 0
result = [0]*200000
for x in range(X):
    for y in range(Y):
        if x * y > K: break
        for z in range(Z):
            if x * y * z > K: break
            result[cnt] = A[x]+B[y]+C[z]
            cnt += 1
result.sort(reverse=True)
for i in range(K):
    print(result[i])

Submission status: Runtime Error

Solution code:
import sys; sys.setrecursionlimit(50000)
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.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

cnt = 0
result = [0]*(X*Y*Z)
for x in range(X):
    for y in range(Y):
        if x * y > K: break
        for z in range(Z):
            if x * y * z > K: break
            result[cnt] = A[x]+B[y]+C[z]
            cnt += 1
result.sort(reverse=True)
for i in range(K):
    print(result[i])

Submission status: Runtime Error

Solution code:
import sys; sys.setrecursionlimit(50000)
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.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

cnt = 0
result = [0]*X*Y*Z
for x in range(X):
    for y in range(Y):
        if x * y > K: break
        for z in range(Z):
            if x * y * z > K: break
            result[cnt] = A[x]+B[y]+C[z]
            cnt += 1
result.sort(reverse=True)
for i in range(K):
    print(result[i])

Submission status: Runtime Error

Solution code:
import sys; sys.setrecursionlimit(50000)
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.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

cnt = 0
result = [0]*K
for x in range(X):
    for y in range(Y):
        if x * y > K: break
        for z in range(Z):
            if x * y * z > K: break
            result[cnt] = A[x]+B[y]+C[z]
            cnt += 1
result.sort(reverse=True)
for i in range(K):
    print(result[i])

Submission status: Runtime Error

Solution code:
# solution 3
import heapq
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)
Q = []
s = set()
heapq.heappush(Q, (-A[0]-B[0]-C[0], 0, 0, 0))
for n in range(K):
    q, i, j, k = heapq.heappop(Q)
    print(-q)
    if i < X-1 and [i+1, j, k] not in s:
            heapq.heappush(Q, (- A[i+1] - B[j] - C[k], i+1, j, k))
            s.add((i + 1, j, k))
    if j < Y-1 and [i, j+1, k] not in s:
            heapq.heappush(Q, (- A[i] - B[j+1] - C[k], i, j+1, k))
            s.add((i, j + 1, k))
    if k < Z-1 and [i, j, k+1] not in s:
            heapq.heappush(Q, (- A[i] - B[j] - C[k+1], i, j, k+1))
            s.add((i, j, k + 1))

Submission status: Runtime Error

Solution code:
from collections import defaultdict
import heapq
inpl = lambda: list(map(int,input().split()))

X, Y, Z, K = inpl()
A = [ sorted(inpl(), reverse=True) for _ in range(3) ]
N = [X, Y, Z]

mem = defaultdict(int)
score = sum([A[i][0] for i in range(3)])
mem[(0,0,0)] = 1
candidates = []
heapq._heappush_max(candidates, (score,(0,0,0)))

for i in range(K):
    c = heapq._heappop_max(candidates)
    print(c[0])
    n = list(c[1])
    
    for p in range(3):
        if n[p] < N[p]-1:
            n[p] += 1
            if mem[tuple(n)] == 0:
                mem[tuple(n)] = 1
                score = sum([A[j][n[j]] for j in range(3)])
                heapq._heappush_max(candidates, (score,tuple(n)))
            n[p] -= 1

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(key=lambda x:-x)
b.sort(key=lambda x:-x)
c.sort(key=lambda x:-x)
# queue=[beauty, indexa, indexb, indexc]
queue=[(a[0]+b[0]+c[0],0,0,0)]
beauty=[0 for _ in range(k)]
index=0
indexq=0
while index<k:
    queue.sort(key=lambda x:-x[0])
    # print(queue)
    beauty[index],indexa,indexb,indexc=queue[indexq]
    index+=1
    indexq+=1
    for da,db,dc in [(1,0,0),(0,1,0),(0,0,1)]:
        # print(indexa+da,indexb+db,indexc+dc)
        if indexa+da<x and indexb+db<y and indexc+dc<z:
            queue.append((a[indexa+da]+b[indexb+db]+c[indexc+dc],indexa+da,indexb+db,indexc+dc))
    queue=list(set(queue))
for i in range(k):
    print(beauty[i])

Submission status: Runtime Error

Solution code:
#入力
l = [int(i) for i in input().split()] #X,Y,Z,K
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

K = l[3]

#並べ替え(降順)
A.sort(reverse=True)
B.sort(reverse=True)
B.sort(reverse=True)

##ABで和を出す
ABsum = [0] * len(A) * len(B)
t = 0
for i in range(len(A)):
    for j in range(len(B)):
            ABsum[t] = A[i] + B[j]
            t += 1
ABsum.sort(reverse=True)

#Cを含めた探索の上限を決める
kz = K
if l[2] - kz < 0:
    kz = l[2]

#ABCで和を出す
ABCsum = [0] * len(ABsum) * kz
t = 0
for i in range(len(ABsum)):
    for j in range(kz):
        ABCsum[t] = ABsum[i] + C[j]
        t += 1

ABCsum.sort(reverse=True)

#出力
for i in range(K):
    print(ABCsum[i])

Submission status: Runtime Error

Solution code:
#入力
l = [int(i) for i in input().split()] #X,Y,Z,K
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)
B.sort(reverse=True)

#探索の上限を決める
kx = l[3]
ky = l[3]
kz = l[3]
if l[0] - kx < 0:
    kx = l[0]
if l[1] - ky < 0:
    ky = l[1]
if l[2] - kz < 0:
    kz = l[2]

ABCsum=[0] * kx * ky * kz
t = 0
for i in range(kx):
    for j in range(ky):
            for k in range(kz):
                ABCsum[t] = A[i] + B[j] + C[k]
                t += 1
ABCsum.sort(reverse=True)
#print(ABsum)

for i in range(l[3]):
    print(ABCsum[i])

Submission status: Runtime Error

Solution code:
from heapq import heappush, heappop
s=set()
q=[]
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)
heapq.heappush(q, (-(a[0]+b[0]+c[0]), 0, 0, 0))
def push(d, e, f):
    if (d, e, f) not in s and 0<=d<x and 0<=e<y and 0<=f<z:
        heapq.heappush(q, (-(a[d]+b[e]+c[f]), d, e, f))
        s.add((d, e, f))
for i in range(k):
    p, d, e, f =heapq.heappop(q)
    print(-p)
    push(d+1, e, f)
    push(d, e+1, f)
    push(d, e, f+1)

Submission status: Runtime Error

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

A = map(int,raw_input().split())
B = map(int,raw_input().split())
C = map(int,raw_input().split())

D = []
for i in xrange(min(len(A)):
    for j in xrange(min(len(B)):
        D.append(A[i]+B[i])

D.sort(reverse = True)
E = []
for i in xrange(min(len(D),K)):
    for j in xrange(min(len(C),K)):
        E.append(D[i]+C[j])

E.sort(reverse = True)
for i in range(K):
    print E[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()))
for i in range(K):
  print(A[i] + B[i] + C[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)
ab =[]
abc = []
for i in a:
    for j in b:
        ab.append(i+j)
ab.sort(reverse = True)
m = min(K, X*Y)
ab = ab[:m]
for i in ab:
    for j in c:
        abc.append(i +j)
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 = 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)

def f(thres:int)->bool:
    """return (おいしさが thres を超える組み合わせ) >= K
    """
    global K
    cnt = 0
    for a in range(X):
        for b in range(Y):
            for c in range(Z):
                if A[a]+B[b]+C[c]<thres:
                    break
                cnt += 1
                if cnt > K:
                    return False
    return True

def binary_search(f, s:int, t:int)->int:
    """f: function(x:int)->bool
    f(s)=False, f(t)=True，f は広義単調増加
    return : [s, t) での f(x)=True なる最小のx
    """
    ng = s-1
    ok = t
    while ok - ng > 1:
        mid = (ok + ng)//2
        if f(mid): ok = mid
        else:      ng = mid
        # print(ng, ok, ok-ng)

    if ok==t:
        raise(ValueError("For all x, f(x)=False"))
    return ok

M = A[0]+B[0]+C[0]
m = A[-1]+B[-1]+C[-1]
# print(f(m), f(M))
thres = binary_search(f, m, M+1)
ans = []
for a in range(X):
    for b in range(Y):
        for c in range(Z):
            if A[a]+B[b]+C[c]<thres:
                break
            ans.append(A[a]+B[b]+C[c])
            if len(ans)==K:
                ans.sort(reverse=True)
                print("\n".join(map(str, ans)))

Submission status: Runtime Error

Solution code:
X,Y,Z,K = map(int(input()))
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

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)
ab =[]
abc = []
for i in a:
    for j in b:
        ab.append(i+j)
ab.sort(reverse = True)
m = min(K, X*Y)
ab = ab[:m]
for i in ab:
    for j in c:
        abc.append(i +j)
abc.sort(reverse = True)
for i in range(c):
    print(abc[i])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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)
ab =[]
abc = []
for i in a:
    for j in b:
        ab.append(i+j)
ab.sort(reverse = True)
m = min(K, X*Y)
ab = ab[:m+1]
for i in ab:
    for j in c:
        abc.append(i +j)
abc.sort(reverse = True)
for i in abc:
    print(i)

Submission status: Runtime Error

Solution code:
imort sys
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)

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)
print("\n".join(map(str, ABC[:K])))

Submission status: Runtime Error

Solution code:
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()))

AA, BB = np.meshgrid(A,B)
AB = AA+BB
AB = np.sort(AB.flatten())[::-1]

ABAB, CC = np.meshgrid(AB,C)
ABC = ABAB+CC
ABC = np.sort(ABC.flatten())[::-1]

for abc in ABC:
    print(abc)

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

a_list.sort(reverse = True)
b_list.sort(reverse = True)
c_list.sort(reverse = True)

max_k_list = [0] * (X * Y * Z)
i = 0
for a_i in range(X):
    for b_i in range(Y):
        for c_i in range(Z):
            if (a_i + 1) * (b_i + 1) * (c_i + 1) <= K:
                max_k_list[i] = a_list[a_i] + b_list[b_i] + c_list[c_i]
                i += 1

max_k_list.sort(reverse = True)
[print(k) for k in max_k_list[: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()))
C.sort()
C.reverse()


array = []
tmp = []

for a in A:
  for b in B:
    tmp.append(a+b)
tmp.sort()
tmp.reverse()

for i in range(K):
  for c in C:
    array.append(tmp[i]+c)

array.sort()
array.reverse()

for i in range(K):
  print(array[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()
A.reverse()
B.sort()
B.reverse()
C.sort()
C.reverse()


array = []
tmp = []

for a in A:
  for b in B:
    tmp.append(a+b)
tmp.sort()
tmp.reverse()

for i in range(K):
  for c in C:
    array.append(tmp[i]+c)

array.sort()
array.reverse()

for i in range(K):
  print(array[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 = reversed(sorted(A))
B = reversed(sorted(B))
C = reversed(sorted(C))
abc_list=[]

for i in A:
    for j in B:
        for k in C:
            if i * j * k <= K:
                abc_list.append(i+j+k)
            else:
                break

abc_list = reversed(sorted(abc_list))

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

ab.sort()
ab.reverse()

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

abc.sort()
abc.reverse()

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