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, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
W = X * Y * Z
D = [0] * W
m = 0
for i in range(X):
	for j in range(Y):
		for k in range(Z):
			D[m] = A[i] + B[j] + C[k]
			m = m + 1
print(D)
E = sorted(D, reverse = True)
for n in range(K):
	print(E[n])

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)

class Combination():
    def __init__(self, a, b, c):
        self.a = a
        self.b = b
        self.c = c
        self.val = A[self.a] + B[self.b] + C[self.c]

    @property
    def param(self):
        return self.a, self.b, self.c

    def __lt__(self, other):
        return self.val < other.val

class Heap():
    nodes = []

    @property
    def size(self):
        return len(self.nodes)

    def pop(self):
        if self.size == 1:
            val = self.nodes[0]
            self.nodes = []
            return val
        if self.size > 1:
            val = self.nodes[0]
            target = self.nodes[-1]
            self.nodes = self.nodes[:-1]
            idx = 0
            size = len(self.nodes)
            while 2*idx+1 < size:
                if 2*idx+2 < size and self.nodes[2*idx+1] < self.nodes[2*idx+2]:
                    target_id = 2 * idx + 2
                else:
                    target_id = 2 * idx + 1
                if self.nodes[target_id] < target:
                    break
                else:
                    self.nodes[idx] = self.nodes[target_id]
                    idx = target_id
            self.nodes[idx] = target
            return val
        return Combination(0, 0, 0)

    def push(self, node):
        val = node.val
        self.nodes.append(node)
        idx = len(self.nodes) - 1
        while idx > 0:
            target_id = int((idx - 1) / 2)
            if self.nodes[target_id] < node:
                self.nodes[idx] = self.nodes[target_id]
                idx = target_id
            else:
                break
        self.nodes[idx] = node

class Leaf():
    def __init__(self, val):
        self.val = val
        self.left = None
        self.right = None

    def add(self, val):
        if self.val == val:
            return False
        elif val < self.val:
            if self.left is None:
                self.left = Leaf(val)
            else:
                return self.left.add(val)
        else:
            if self.right is None:
                self.right = Leaf(val)
            else:
                return self.right.add(val)
        return True

A_off = 10 ** 20
B_off = 10 ** 10

def get_hash(a, b, c):
    return a * A_off + b * B_off + c

heap = Heap()
heap.push(Combination(0, 0, 0))
bt = Leaf(get_hash(0, 0, 0))

for _ in range(K):
    comb = heap.pop()
    print(comb.val)
    a, b, c = comb.param
    if a+1 < X and bt.add(get_hash(a+1, b, c)):
        heap.push(Combination(a+1, b, c))
    if b+1 < Y and bt.add(get_hash(a, b+1, c)):
        heap.push(Combination(a, b+1, c))
    if c+1 < Z and bt.add(get_hash(a, b, c+1)):
        heap.push(Combination(a, b, c+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(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

class Combination():
    def __init__(self, a, b, c):
        self.a = a
        self.b = b
        self.c = c
        self.val = A[self.a] + B[self.b] + C[self.c]

    @property
    def param(self):
        return self.a, self.b, self.c

    def __lt__(self, other):
        return self.val < other.val

class Heap():
    nodes = []

    @property
    def size(self):
        return len(self.nodes)

    def pop(self):
        if self.size == 1:
            val = self.nodes[0]
            self.nodes = []
            return val
        if self.size > 1:
            val = self.nodes[0]
            target = self.nodes[-1]
            self.nodes = self.nodes[:-1]
            idx = 0
            size = len(self.nodes)
            while 2*idx+1 < size:
                if 2*idx+2 < size and self.nodes[2*idx+1] < self.nodes[2*idx+2]:
                    target_id = 2 * idx + 2
                else:
                    target_id = 2 * idx + 1
                if self.nodes[target_id] < target:
                    break
                else:
                    self.nodes[idx] = self.nodes[target_id]
                    idx = target_id
            self.nodes[idx] = target
            return val
        return None

    def push(self, node):
        val = node.val
        self.nodes.append(node)
        idx = len(self.nodes) - 1
        while idx > 0:
            target_id = int((idx - 1) / 2)
            if self.nodes[target_id] < node:
                self.nodes[idx] = self.nodes[target_id]
                idx = target_id
            else:
                break
        self.nodes[idx] = node

class Leaf():
    def __init__(self, val):
        self.val = val
        self.left = None
        self.right = None

    def add(self, val):
        if self.val == val:
            return False
        elif val < self.val:
            if self.left is None:
                self.left = Leaf(val)
            else:
                return self.left.add(val)
        else:
            if self.right is None:
                self.right = Leaf(val)
            else:
                return self.right.add(val)
        return True

A_off = 10 ** 20
B_off = 10 ** 10

def get_hash(a, b, c):
    return a * A_off + b * B_off + c

heap = Heap()
heap.push(Combination(0, 0, 0))
bt = Leaf(get_hash(0, 0, 0))

for _ in range(K):
    comb = heap.pop()
    print(comb.val)
    a, b, c = comb.param
    if a+1 < X and bt.add(get_hash(a+1, b, c)):
        heap.push(Combination(a+1, b, c))
    if b+1 < Y and bt.add(get_hash(a, b+1, c)):
        heap.push(Combination(a, b+1, c))
    if c+1 < Z and bt.add(get_hash(a, b, c+1)):
        heap.push(Combination(a, b, c+1))

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 = sorted([int(x) for x in A], reverse=True)
B = sorted([int(x) for x in B], reverse=True)
C = sorted([int(x) for x in C], reverse=True)

res = []
memo = []
i, j, k = 0, 0, 0
while len(res) < K:
  if [i, j, k] not in memo:
    res.append(A[i]+B[j]+C[k])
    memo.append([i,j,k])
  if i+1 < X and [i+1, j, k] not in memo:
    res.append(A[i+1]+B[j]+C[k])
    memo.append([i+1, j, k])
  if j+1 < Y and [i, j+1, k] not in memo:
    res.append(A[i]+B[j+1]+C[k])
    memo.append([i, j+1, k])
  if k+1 < Z and [i, j, k+1] not in memo:
    res.append(A[i]+B[j]+C[k+1])
    memo.append([i, j, k+1])
  if i < X:
    i += 1
  if j < Y:
    j += 1
  if k < Z:
    k += 1
res = sorted(res, reverse=True)[:K]
for i in res:
  print(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 = sorted([int(x) for x in A], reverse=True)
B = sorted([int(x) for x in B], reverse=True)
C = sorted([int(x) for x in C], reverse=True)

res = []
memo = []
i, j, k = 0, 0, 0
while len(res) < K:
  if [i, j, k] not in memo:
  	res.append(A[i]+B[j]+C[k])
    memo.append([i,j,k])
  if i+1 < X and [i+1, j, k] not in memo:
  	res.append(A[i+1]+B[j]+C[k])
    memo.append([i+1, j, k])
  if j+1 < Y and [i, j+1, k[ not in memo:
  	res.append(A[i]+B[j+1]+C[k])
    memo.append([i, j+1, k])
  if k+1 < Z and [i, j, k+1] not in memo:
  	res.append(A[i]+B[j]+C[k+1])
    memo.append([i, j, k+1])
  if i < X:
    i += 1
  if j < Y:
    j += 1
  if k < Z:
    k += 1
res = sorted(res, reverse=True)[:K]
for i in res:
  print(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 = sorted([int(x) for x in A], reverse=True)
B = sorted([int(x) for x in B], reverse=True)
C = sorted([int(x) for x in C], reverse=True)

res = []
memo = []
i, j, k = 0, 0, 0
while len(res) < K:
  if (i, j, k) not in memo:
  	res.append(A[i]+B[j]+C[k])
    memo.append((i,j,k))
  if i+1 < X and (i+1, j, k) not in memo:
  	res.append(A[i+1]+B[j]+C[k])
    memo.append((i+1, j, k))
  if j+1 < Y and (i, j+1, k) not in memo:
  	res.append(A[i]+B[j+1]+C[k])
    memo.append((i, j+1, k))
  if k+1 < Z and (i, j, k+1) not in memo:
  	res.append(A[i]+B[j]+C[k+1])
    memo.append((i, j, k+1))
  if i < X:
    i += 1
  if j < Y:
    j += 1
  if k < Z:
    k += 1
res = sorted(res, reverse=True)[:K]
for i in res:
  print(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 = sorted([int(x) for x in A], reverse=True)
B = sorted([int(x) for x in B], reverse=True)
C = sorted([int(x) for x in C], reverse=True)

res = []
i, j, k = 0, 0, 0
while len(res) < K:
  res.append(A[i]+B[j]+C[k])
  if i+1 < X:
  	res.append(A[i+1]+B[j]+C[k])
  if j+1 < Y:
  	res.append(A[i]+B[j+1]+C[k])
  if k+1 < Z:
  	res.append(A[i]+B[j]+C[k+1])
  if i < X:
    i += 1
  if j < Y:
    j += 1
  if k < Z:
    k += 1
res = sorted(res, reverse=True)[:K]
for i in res:
  print(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 = sorted([int(x) for x in A], reverse=True)
B = sorted([int(x) for x in B], reverse=True)
C = sorted([int(x) for x in C], reverse=True)

res = []
i, j, k = 0, 0, 0
while len(res) < K:
  res.append(A[i]+B[j]+C[k])
  res.append(A[i+1]+B[j]+C[k])
  res.append(A[i]+B[j+1]+C[k])
  res.append(A[i]+B[j]+C[k+1])
  if i < X:
    i += 1
  if j < Y:
    j += 1
  if k < Z:
    k += 1
res = sorted(res, reverse=True)[:K]
for i in res:
  print(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 = sorted([int(x) for x in A], reverse=True)
B = sorted([int(x) for x in B], reverse=True)
C = sorted([int(x) for x in C], reverse=True)

res = []
i, j, k = 0, 0, 0
while len(res) < K:
  res.append(A[i]+B[j]+C[k])
  res.append(A[i+1]+B[j]+C[k])
  res.append(A[i]+B[j+1]+C[k])
  res.append(A[i]+B[j]+C[k+1])
  i,j,k = i+1, j+1, k+1
res = sorted(res, reverse=True)[:K]
for i in res:
  print(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 = sorted([int(x) for x in A], reversed=True)
B = sorted([int(x) for x in B], reversed=True)
C = sorted([int(x) for x in C], reversed=True)

res = []
i, j, k = 0, 0, 0
while len(res) < K:
  res.append(A[i]+B[j]+C[k])
  res.append(A[i+1]+B[j]+C[k])
  res.append(A[i]+B[j+1]+C[k])
  res.append(A[i]+B[j]+C[k+1])
  i,j,k = i+1, j+1, k+1
res = sorted(res, reversed=True)[:K]
for i in res:
  print(i)

Submission status: Runtime Error

Solution code:
line = input()
K = int(line.split(' ')[-1])
A = input().split(' ')
B = input().split(' ')
C = input().split(' ')
A = sorted([int(x) for x in A], reversed=True)
B = sorted([int(x) for x in B], reversed=True)
C = sorted([int(x) for x in C], reversed=True)

res = []
i, j, k = 0, 0, 0
while len(res) < K:
  res.append(A[i]+B[j]+C[k])
  res.append(A[i+1]+B[j]+C[k])
  res.append(A[i]+B[j+1]+C[k])
  res.append(A[i]+B[j]+C[k+1])
  i,j,k = i+1, j+1, k+1
res = sorted(res, reversed=True)[:K]
for i in res:
  print(i)

Submission status: Runtime Error

Solution code:
a,b,c,K = int(input()),int(input()),int(input()),int(input())
A = input().split(' ')
B = input().split(' ')
C = input().split(' ')
A = sorted([int(x) for x in A], reversed=True)
B = sorted([int(x) for x in B], reversed=True)
C = sorted([int(x) for x in C], reversed=True)

res = []
i, j, k = 0, 0, 0
while len(res) < K:
  res.append(A[i]+B[j]+C[k])
  res.append(A[i+1]+B[j]+C[k])
  res.append(A[i]+B[j+1]+C[k])
  res.append(A[i]+B[j]+C[k+1])
  i,j,k = i+1, j+1, k+1
res = sorted(res, reversed=True)[:K]
for i in res:
  print(i)

Submission status: Runtime Error

Solution code:
a,b,c,K = int(input()),int(input()),int(input()),int(input())
A = sorted([int(x) for x in input().split(' ')], reversed=True)
B = sorted([int(x) for x in input().split(' ')], reversed=True)
C = sorted([int(x) for x in input().split(' ')], reversed=True)

res = []
i, j, k = 0, 0, 0
while len(res) < K:
  res.append(A[i]+B[j]+C[k])
  res.append(A[i+1]+B[j]+C[k])
  res.append(A[i]+B[j+1]+C[k])
  res.append(A[i]+B[j]+C[k+1])
  i,j,k = i+1, j+1, k+1
res = sorted(res, reversed=True)[:K]
for i in res:
  print(i)

Submission status: Runtime Error

Solution code:
from heapq import *

a,b,c,K = int(input()),int(input()),int(input()),int(input())
A = sorted([int(x) for x in input().split(' ')], reversed=True)
B = sorted([int(x) for x in input().split(' ')], reversed=True)
C = sorted([int(x) for x in input().split(' ')], reversed=True)

res = []
i, j, k = 0, 0, 0
while len(res) < K:
  res.append(A[i]+B[j]+C[k])
  res.append(A[i+1]+B[j]+C[k])
  res.append(A[i]+B[j+1]+C[k])
  res.append(A[i]+B[j]+C[k+1])
  i,j,k = i+1, j+1, k+1
res = sorted(res, reversed=True)[:K]
for i in res:
  print(i)

Submission status: Runtime Error

Solution code:
from heapq import *

a,b,c,K = int(input()),int(input()),int(input()),int(input())
A = sorted([int(x) for x in input().split(' ')], reversed=True)
B = sorted([int(x) for x in input().split(' ')], reversed=True)
C = sorted([int(x) for x in input().split(' ')], reversed=True)

res = []
i, j, k = 0, 0, 0
while len(res) < K:
  heappush(res, A[i]+B[j]+C[k])
  heappush(res, A[i+1]+B[j]+C[k])
  heappush(res, A[i]+B[j+1]+C[k])
  heappush(res, A[i]+B[j]+C[k+1])
  i,j,k = i+1, j+1, k+1
res = nlargest(K, res)
for i in res:
  print(i)

Submission status: Runtime Error

Solution code:
from heapq import *

a,b,c,K = int(input()),int(input()),int(input()),int(input())
A = sorted([int(x) for x in input().split(' ')], reversed=True)
B = sorted([int(x) for x in input().split(' ')], reversed=True)
C = sorted([int(x) for x in input().split(' ')], reversed=True)

res = []
i, j, k = 0, 0, 0
while len(res) < K:
  heappush(res, A[i]+B[j]+C[k])
  heappush(res, A[i+1]+B[j]+C[k])
  heappush(res, A[i]+B[j+1]+C[k])
  heappush(res, A[i]+B[j]+C[k+1])
  i,j,k = i+1, j+1, k+1
res = nlargeest(K, res)
for i in res:
  print(i)

Submission status: Runtime Error

Solution code:
from heapq import *

a,b,c,K = int(input()),int(input()),int(input()),int(input())
A = sorted([int(x) for x in input().split(' ')], reversed=True)
B = sorted([int(x) for x in input().split(' ')], reversed=True)
C = sorted([int(x) for x in input().split(' ')], reversed=True)

res = []
i, j, k = 0, 0, 0
while len(res) < K:
  heappush(res, A[i]+B[j]+C[k])
  heappush(res, A[i+1]+B[j]+C[k])
  heappush(res, A[i]+B[j+1]+C[k])
  heappush(res, A[i]+B[j]+C[k+1])
res = nlargeest(K, res)
for i in res:
  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.sort(reverse=True)
# B.sort(reverse=True)
# C.sort(reverse=True)

AB = []
for eA in A:
    for eB in B:
        AB.append(eA + eB)

AB.sort(reverse=True)

ABC = []
for i in range(K):
    for eC in C:
        ABC.append(AB[i] + eC)

ABC.sort(reverse=True)

for i in range(K):
    print(ABC[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.sort(reverse=True)
# B.sort(reverse=True)
C.sort(reverse=True)

AB = []
for eA in A:
    for eB in B:
        AB.append(eA + eB)

AB.sort(reverse=True)

ABC = []
for i in range(K):
    for eC in C:
        ABC.append(AB[i] + eC)

ABC.sort(reverse=True)

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

Submission status: Runtime Error

Solution code:
import heapq
 
_x, _y, _z, k = map(int, input().split())
aa = list(reversed(sorted(map(int, input().split()))))
bb = list(reversed(sorted(map(int, input().split()))))
cc = list(reversed(sorted(map(int, input().split()))))

ab=[]
for i in range(_x):
  for j in range(_y):
    ab.append(aa[i]+bb[j])

ab.sort()
hq=[]
for z in range(_z):
  for l in range(_x*_y):
    temp = cc[z] + ab[l] 
    if len(hq) < k:
      heapq.heappush(hq,temp)
    else:
      heapq.heapreplace[hq,temp]
hq.sort()
for i in range(k):
  print(hq[k-1-i])

Submission status: Runtime Error

Solution code:
import heapq
 
_x, _y, _z, k = map(int, input().split())
aa = list(reversed(sorted(map(int, input().split()))))
bb = list(reversed(sorted(map(int, input().split()))))
cc = list(reversed(sorted(map(int, input().split()))))

ab=[]
for i in range(_x):
  for j in range(_y):
    ab.append(aa[i]+bb[j])

ab.sort()
hq=[]
for z in range(_z):
  for l in range(_x*_y):
    temp = cc[z] + ab[l] 
    if len(hq) < k:
      heapq.heappush(hq,temp)
    else:
      heapq.heapreplace[hq,temp]
for i in range(k):
  print(hq[k-1-i])

Submission status: Runtime Error

Solution code:
import heapq
 
_x, _y, _z, k = map(int, input().split())
aa = list(reversed(sorted(map(int, input().split()))))
bb = list(reversed(sorted(map(int, input().split()))))
cc = list(reversed(sorted(map(int, input().split()))))

ab=[]
for i in range(_x):
  for j in range(_y):
    ab.append(aa[i]+bb[j])

ab.sort()
hq=[]
for z in range(_z):
  for l in range(_x*_y):
    temp = cc[z] + ab[l] 
    if len(hq) < k:
      heapq.heappush(hq,temp)
    else:
      heapq.heapreplace[hq,temp]
for i in range(k):
  print(hq[k-i])

Submission status: Runtime Error

Solution code:
import heapq
 
_x, _y, _z, k = map(int, input().split())
aa = list(reversed(sorted(map(int, input().split()))))
bb = list(reversed(sorted(map(int, input().split()))))
cc = list(reversed(sorted(map(int, input().split()))))

ab=[]
for i in range(_x):
  for j in range(_y):
    ab.append(aa[i]+bb[j])

ab.sort()
hq=[]
for z in range(_z):
  for l in range(_x*_y):
    temp = cc[z] + ab[l] 
    if hq.size() < k:
      heapq.push(hq,temp)
    else:
      heapq.heapreplace[hq,temp]
for i in range(k):
  print(hq[k-i])

Submission status: Runtime Error

Solution code:
import numpy as np
k = int(input().split(" ")[-1])

a_ = np.array([int(i) for i in input().split(" ")])
b_ = np.array([int(i) for i in input().split(" ")])
c_ = np.array([int(i) for i in input().split(" ")])

res = np.array([], dtype="int32")
for a in a_:
    for b in b_:
        for c in c_:
            if len(res) == k:
                i = np.argmin(res)
                res[i] = np.max(res[i], a+b+c)
            else:
                res = np.append(res,a+b+c)

res = np.sort(res)[::-1]

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

Submission status: Runtime Error

Solution code:
import numpy as np
k = int(input().split(" ")[-1])

a = np.array([int(i) for i in input().split(" ")])
b = np.array([int(i) for i in input().split(" ")])
c = np.array([int(i) for i in input().split(" ")])

res = a.reshape(1,len(a)) + b.reshape(len(b),1)
res = c.reshape(1,1,len(c)) + res.reshape(len(b),len(a),1)
res = res.reshape(len(a)*len(b)*len(c),1,1)[:,0,0]
res = np.sort(res)[::-1]

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()))
d = []
for i in a:
  for j in b:
    for k in c:
      d.append(i+j+k)
d.sort(reverse=True)
for i in range(k):
  print(d[i])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import heapq
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
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()))


def solve1():
    que = []
    for a in a:
        for b in b:
            for c in c:
                heapq.heappush(que, -(a+b+c))
    for _ in range(k):
        print(-heapq.heappop(que))


solve1()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import heapq

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)

anslist = []
flag = {}

heapq.heappush(anslist, (-(A[0]+B[0]+C[0]), "000"))
count = 0


while count < K:
    p = heapq.heappop(anslist)
    while p[1] in flag:
        p = heapq.heappop(anslist)
    print(p[0]*(-1))
    flag[p[1]] = True
    count += 1
    # push
    a, b, c = map(int, p[1])
    for i, j, k in [[1, 0, 0], [0, 1, 0], [0, 0, 1]]:
        if a+i >= X or b+j >= Y or c+k >= Z:
            continue
        tmp = str(a+i)+str(b+j)+str(c+k)
        heapq.heappush(anslist, (-(A[a+i]+B[b+j]+C[c+k]), tmp))

Submission status: Runtime Error

Solution code:
X,Y,Z,K = list(map(int,input().split()))
A = [(sorted(list(map(int,input().split())))[::-1]) for i in range(3)]

import heapq

heap = []
item = (0,(0,0,0))
heapq.heappush(heap, item)
considered_dict = set(item[1])

ret = []
max_ = A[0][0]+A[1][0]+A[2][0]
while len(ret) < K:
    task  = heapq.heappop(heap)
    score,(x,y,z) =task
    ret.append(score)
    # assign next task
    if x+1 != X-1 and (x+1,y,z) not in considered_dict:
        heapq.heappush(heap, (max_-A[0][x+1]-A[1][y]-A[2][z],(x+1,y,z) ))
        considered_dict |= {(x+1,y,z)}
        
                       
    if y+1 != Y-1 and (x,y+1,z) not in considered_dict:
        heapq.heappush(heap, (max_-A[0][x]-A[1][y+1]-A[2][z],(x,y+1,z) ))
        considered_dict |= {(x,y+1,z)}
                       
    if z+1 != Z-1 and (x,y,z+1) not in considered_dict:
        heapq.heappush(heap, (max_-A[0][x]-A[1][y]-A[2][z+1],(x,y,z+1) ))
        considered_dict |= {(x,y,z+1)}


for i in ret:
    print(max_-i)

Submission status: Runtime Error

Solution code:
X,Y,Z,K = list(map(int,input().split()))
A = [(sorted(list(map(int,input().split())))[::-1]) for i in range(3)]

import heapq

heap = []
item = (0,(0,0,0))
heapq.heappush(heap, item)

considered_dict = set()

ret = []
max_ = A[0][0]+A[1][0]+A[2][0]
while len(considered_dict) < K:
    task  = heapq.heappop(heap)
    score,(x,y,z) =task
    ret.append(score)
    considered_dict |= {(x,y,z)}
    # assign next task
    if x+1 != X-1 and (x+1,y,z) not in considered_dict:
        heapq.heappush(heap, (max_-A[0][x+1]-A[1][y]-A[2][z],(x+1,y,z) ))
                       
    if y+1 != Y-1 and (x,y+1,z) not in considered_dict:
        heapq.heappush(heap, (max_-A[0][x]-A[1][y+1]-A[2][z],(x,y+1,z) ))
                       
    if z+1 != Z-1 and (x,y,z+1) not in considered_dict:
        heapq.heappush(heap, (max_-A[0][x]-A[1][y]-A[2][z+1],(x,y,z+1) ))


for i in ret:
    print(max_-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()))
l = []

for i in a:
    for j in b:
        l.append(a + b)
l.sort(reverse = True)
l = l[:K]

L = []

for i in l:
    for j in c:
        L.append(i + j)

L.sort(reverse = True)
print(*L[:K], sep = "\n")

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)
A += [-1e10]
B += [-1e10]
C += [-1e10]

memo = [A[i] + B[0] + C[0] for i in range(X + 1)]
L = [[0 for i in range(Y + 1)] for j in range(X + 1)]

for i in range(K):
  ma = 0
  for j in range(X):
    if memo[ma] < memo[j]:
      ma = j
  print(memo[ma])
  mb = 0
  mn = 0
  for j in range(Y):
    x = B[j] + C[L[ma][j]]
    if mb < x:
      mb = x
      mn = j
  L[ma][mn] += 1
  n = 0
  for j in range(Y):
    n = max(n, B[j] + C[L[ma][j]])
  memo[ma] = A[ma] + n
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)
A += [-1e10]
B += [-1e10]
C += [-1e10]

memo = [A[i] + B[0] + C[0] for i in range(X + 1)]
L = [[0 for i in range(Y + 1)] for j in range(X + 1)]

for i in range(K):
  ma = 0
  for j in range(X):
    if memo[ma] < memo[j]:
      ma = j
  print(memo[ma])
  mb = 0
  mn = 0
  for j in range(Y):
    x = B[j] + C[L[ma][j]]
    if mb < x:
      mb = x
      mn = j
  L[ma][mn] += 1
  n = 0
  for j in range(Y):
    n = max(n, B[j] + C[L[ma][j]])
  memo[ma] = A[ma] + n

Submission status: Runtime Error

Solution code:
import math,itertools,fractions,heapq,collections,re,bisect,sys,functools

sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
dy = [-1,0,1,0]
dx = [0,1,0,-1]
ddy = [-1,-1,0,1,1,1,0,-1]
ddx = [0,1,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 S(): return input()
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)

ab = []
for a in A:
    for b in B:
            ab.append(a+b)
ab.sort(reverse=True)
res = []
for i in range(k):
    for c in C:
        res.append(ab[i]+c)
res.sort(reverse=True)

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

Submission status: Runtime Error

Solution code:
x,y,z,K=list(map(int,input().split()))
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))
a=sorted(alist).reverse()
b=sorted(blist).reverse()
c=sorted(clist).reverse()
azi=[i+j+k for i in a[0:K] for j in b[0:K] for k in c[0:K]]
azilist=sorted(azi)
azilist.reverse()
print(azilist[0:K])

Submission status: Runtime Error

Solution code:
x,y,z,K=list(map(int,input().split()))
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))
for i in range(x):
  alist.append(int(input()))
for i in range(y):
  blist.append(int(input()))
for i in range(z):
  clist.append(int(input()))
azi=[i+j+k for i in alist for j in blist for k in clist]
azilist=sorted(azi).reverse()
print(azilist[0:K])

Submission status: Runtime Error

Solution code:
x,y,z=list(map(int,input().split()))
K=int(input())
alist=[]
blist=[]
clist=[]
for i in range(x):
  alist.append(int(input()))
for i in range(y):
  blist.append(int(input()))
for i in range(z):
  clist.append(int(input()))
azi=[i+j+k for i in alist for j in blist for k in clist]
azilist=sorted(azi).reverse()
print(azilist[0: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()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
num = []
for a in A:
    for b in B:
        num.append(a+b)
num.sort(reverse = True)
num2 = []
for i in range(k):
    for j in C:
        num2.append(num[i]+j)
num2.sort(reverse = True)
for i in range(k):
    print(num2[i])