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 = [int(elm) for elm in input().split(" ")]
Xs = [X, Y, Z]
A = sorted([int(elm) for elm in input().split(" ")], reverse=True)
B = sorted([int(elm) for elm in input().split(" ")], reverse=True)
C = sorted([int(elm) for elm in input().split(" ")], reverse=True)


def sum_(kouho):
    a, b, c = kouho
    return sum([A[a], B[b], C[c]])

kouhos = []

kouhos = [[0, 0, 0]]
cur = kouhos[0]
kouhos_vals = [sum_(cur)]
all_ = [cur]

def add_kouhos(kouhos, kouhos_vals, new_kouhos):
    if len(kouhos) == 0:
        kouhos = new_kouhos
        kouhos_vals = [sum_(kouho) for kouho in new_kouhos]
        return kouhos, kouhos_vals

    len_kouhos = len(kouhos)

    new_i = 1
    new_kouho = new_kouhos[-new_i] 

    n_kouhos = len(new_kouhos)

    last_kouho_i = len_kouhos - 1
    while True:
        if sum_(new_kouho) <= sum_(kouhos[-1]):
            #kouhos.append(new_kouho)
            kouhos.insert(last_kouho_i+1, new_kouho)
            new_i += 1
            if new_i == n_kouhos+1:
                return kouhos, kouhos_vals        
            new_kouho = new_kouhos[-new_i]
        else:
            break

    #for kouho_i in range(1, len_kouhos+1):
    for cur_kouho_i in reversed(range(0, len_kouhos)):
        loop = True
        sum_cur_kouho = sum_(kouhos[cur_kouho_i])
        while loop:
            #if sum_(new_kouho) > sum_(kouhos[-kouho_i]):
            if sum_(new_kouho) < sum_cur_kouho: 
                kouhos.insert(cur_kouho_i+1, new_kouho)
                kouhos_vals.insert(cur_kouho_i+1, sum_(new_kouho))
                #kouhos.insert(-kouho_i, new_kouho)
                #kouhos_vals.insert(-kouho_i, sum_(new_kouho))
                new_i += 1
                if new_i == n_kouhos+1:
                    return kouhos, kouhos_vals
                new_kouho = new_kouhos[-new_i]
            else:
                loop = False
                #new_i += 1
                #new_kouho = new_kouhos[-new_i]

    while True:
        #print("add mae", new_kouho)
        kouhos.insert(0, new_kouho) 
        kouhos_vals.insert(0, sum_(new_kouho))
        new_i += 1
        if new_i == n_kouhos+1:
            return kouhos, kouhos_vals
        else:
            new_kouho = new_kouhos[-new_i]

def make_new_kouhos():
    new_kouhos = []
    for i in range(3):
        new_kouho = cur.copy()
        new_kouho[i] += 1
        if new_kouho not in all_ and new_kouho[i] < Xs[i]:
            new_kouhos.append(new_kouho)
    new_kouhos = sorted(new_kouhos, key=lambda x:-sum_(x))
    return new_kouhos

#while True:
for _ in range(K):
    #print("cur_kouho", kouhos[0])
    cur = kouhos[0]
    print(sum_(cur))
    kouhos = kouhos[1:]
    kouhos_vals = kouhos_vals[1:]

    new_kouhos = make_new_kouhos()
    all_ += new_kouhos

    if len(new_kouhos) > 0:
        #print("before add kouhos", kouhos)
        #print("new_kouhos", new_kouhos)
        kouhos, kouhos_vals = add_kouhos(kouhos, kouhos_vals, new_kouhos)
        #print("after add kouhos", kouhos)

Submission status: Runtime Error

Solution code:
x,y,z,k=map(int,input().split())
listx = [int(i) for i in input().split()]
listy = [int(i) for i in input().split()]
listz = [int(i) for i in input().split()]

import numpy as np
listxy = np.zeros([x*y,],dtype=np.int)
c = 0
for i in range(0,x):
    for j in range(0,y):
        listxy[c] = listx[i]+listy[j]
        c+=1

listxy.sort(reverse=True)
#print(listxy)
if x*y>k:
    listxy=listxy[:k]
    listxyz =np.zeros([k*z,],dtype=np.int)
    c = 0
    for i in range(0,k):
        for j in range(0,z):
            listxyz[c] = listxy[i]+listz[j]
            c+=1
else:
    listxyz =np.zeros([x*y*z,],dtype=np.int)
    c = 0
    for i in range(0,x*y):
        for j in range(0,z):
            listxyz[c] = listxy[i]+listz[j]
            c+=1

listxyz.sort(reverse=True)

for i in range(0,k):
    print(listxyz[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 = [0] * (X * Y)
E = [0] * (K * Z)
m, n = 0, 0

for i in range(X):
    for j in range(Y):
        D[m] = A[i] + B[j]
        m += 1

for k in range(K):
    for l in range(Z):
        E[n] = sorted(D)[:: -1][: K][k] + C[l]
        n += 1

for p in range(K):
    print(sorted(E)[:: -1][p])

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 = [0] * (X * Y)
F = [0] * (X * Y * Z)
m, n = 0, 0

for i in range(X):
	for j in range(Y):
		D[m] = A[i] + B[j]
		m += 1

Dsort = sorted(D)[:: -1]
E = Dsort[: K]

for k in range(len(E)):
	for l in range(Z):
		F[n] = E[k] + C[l]
		n += 1

for p in range(K):
	print(sorted(F)[:: -1][p])

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
lx, ly, lz, k = [int(item) for item in input().split()]
xs = [int(item) for item in input().split()]
ys = [int(item) for item in input().split()]
zs = [int(item) for item in input().split()]
arr = [None] * (lx * ly)
for i, x in enumerate(xs):
  for j, y in enumerate(ys):
    arr[i+j*lx] = x+y
arr.sort(reverse=True)
narr = [None] * (k*lz)
for i,a in enumerate(arr[:k]):
  for j,z in enumerate(zs):
    narr[i+j*k] = a+z
narr.sort(reverse=True)
for v in narr[:k]:
  print(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()))
D = [0] * (X * Y)
F = [0] * (X * Y * Z)
m, n = 0, 0
for i in range(X):
	for j in range(Y):
		D[m] = A[i] + B[j]
		m += 1

Dsort = sorted(D)[:: -1]
E = Dsort[: K]

for k in range(len(E)):
	for l in range(Z):
		F[n] = E[k] + C[l]
		n += 1

G = sorted(F)[:: -1]

for p in range(K):
	print(G[p])

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
E = sorted(D)[:: -1]
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())

AB = []
for i in range(len(A)) :
    for j in range(len(B)) :
        AB.append(A[i] + B[j])

AB.sort(reverse = True)
AB = AB[:K]

ABC = []

for i in range(len(AB)) :
    for j in range(len(C)) :
        ABC.append(AB[i] + C[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 = sorted(list(map(int, input().split())
C = sorted(list(map(int, input().split())

AB = []
for i in range(len(A)) :
    for j in range(len(B)) :
        AB.append(A[i] + B[j])

AB.sort(reverse = True)
AB = AB[:K]

ABC = []

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

ABC.sort(reverse = True)

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

Submission status: Runtime Error

Solution code:
import numpy as np
numbers = input().split()
x = input().split()
y = input().split()
z = input().split()

k = int(numbers[3])
x.sort(reverse=True)
y.sort(reverse=True)
z.sort(reverse=True)

answer = []
for i in x:
    for j in y:
        price = int(i)+int(j)
        answer.append(price)
del answer[k::]
for m in range(k):
    answer[m] = answer[m] + z[m]

"""
answer.sort(reverse=True)
del answer[k::]
"""
for l in answer:
    print(l)

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

ABl = []
for a in Al:
    for b in Bl:
        ABl.append(a+b)

result = []
ABl = sorted(ABl,reverse=True)[:K]
for ab in ABl:
    for c in Cl:
        result.append(ab+c)

result.sort(reverse=True)

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

Submission status: Runtime Error

Solution code:
numbers = input().split()
x = input().split()
y = input().split()
z = input().split()

k = int(numbers[3])


def cutting(c, k):
    del c[k::]


x.sort(reverse=True)
cutting(x)
y.sort(reverse=True)
cutting(y)
z.sort(reverse=True)
cutting(z)

answer = []

for i in x:
    for j in y:
        for m in z:
            price = int(i)+int(j)+int(m)
            answer.append(price)

answer.sort(reverse=True)
del answer[k::]

for l in answer:
    print(l)

Submission status: Runtime Error

Solution code:
numbers = input().split()
x = input().split()
y = input().split()
z = input().split()

k = int(numbers[3])

x.sort(reverse=True)
if len(x) > k:
    del x[k::]
y.sort(reverse=True)
if len(y) > k:
    del y[k::]
z.sort(reverse=True)
if len(z) > k:
    del z[k::]

answer = []

for i in x:
    for j in y:
        price = int(i)+int(j)
        answer.append(price)
answer[k::]

for m, mn in enumerate(z):
    price = answer[m] + mn
    answer.append(price)

answer.sort(reverse=True)
del answer[int(numbers[3])::]

for l in answer:
    print(l)

Submission status: Runtime Error

Solution code:
x, y, z, k = map(int, input().split())
l_a = list(map(int, input().split()))
l_b = list(map(int, input().split()))
l_c = list(map(int, input().split()))
l = [sum(i) for i in list(itertools.product(l_a, l_b, l_c))]
print(sorted(l, reverse=True)[:k])

Submission status: Runtime Error

Solution code:
import itertools
 
l_1 = [int(input()) for s in range(4)]
l_a = [int(input()) for a in range(l_1[0])]
l_b = [int(input()) for b in range(l_1[1])]
l_c = [int(input()) for c in range(l_1[2])]
l = [sum(i) for i in list(itertools.product(l_a, l_b, l_c))]
print(sorted(l, reverse=True)[:l_1[3]])

Submission status: Runtime Error

Solution code:
import itertools

l_1 = [int(input()) for _ in range(4)]
l_a = [int(input()) for _ in range(l_1[0])]
l_b = [int(input()) for _ in range(l_1[1])]
l_c = [int(input()) for _ in range(l_1[2])]
l = [sum(i) for i in list(itertools.product(l_a, l_b, l_c))]
print(sorted(l, reverse=True)[:l_1[3]])

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
const ll mo=1000000007;
vector<ll> ans;
ll dp[0][0];
using Data = pair<long long, vector<int> >;

int main()
{
ll x,y,z,K;

cin >> x>>y>>z>>K;
ll tabx[x]={};
rep(i,x) {
    cin >> tabx[i];
}
ll taby[y]={};
rep(i,y) {
    cin >> taby[i];
}
ll tabz[z]={};
rep(i,z) {
    cin >> tabz[i];
}
sort(tabx, tabx + x, greater<ll>());
sort(taby, taby + y, greater<ll>());
sort(tabz, tabz + z, greater<ll>());

priority_queue<Data> que;
set<Data> se;
que.push(Data(tabx[0] + taby[0] + tabz[0], vector<int>({0, 0, 0})));
ll N[3]={x,y,z};
ll sum[3];

for (int k = 0; k < K; ++k) {
    auto c = que.top();que.pop();
    ans.push_back(c.first);
    sum[0]=c.first - tabx[c.second[0]] + tabx[c.second[0] + 1];
    sum[1]=c.first - taby[c.second[1]] + taby[c.second[1] + 1];
    sum[2]=c.first - tabz[c.second[2]] + tabz[c.second[2] + 1];

    // 次の三候補
    for (int iter = 0; iter < 3; ++iter) {
        if (c.second[iter] + 1 < N[iter]) {
            auto num = c.second; num[iter]++;
            auto d = Data(sum[iter], num);
            
            // すでに push されたもの以外
            if (!se.count(d)) se.insert(d), que.push(d);
        }
    }
}

rep(i,K){
cout << ans[i]<< endl;
}

return 0;
}

Submission status: Runtime Error

Solution code:
import numpy as np

x, y, z, k = (int(i) for i in input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ary_a = np.array([a for _ in range(y)])
ary_b = np.array([b for _ in range(x)]).T
mat = np.add(ary_a, ary_b)
mats = np.sort(np.ravel(np.array([np.add(mat,c[i]) for i in range(z)])))[::-1]
for i in range(k):
    print(mats[i])

Submission status: Runtime Error

Solution code:
import numpy as np

l = list(map(int, input().split()))
x = l[0]
y = l[1]
z = l[2]
k = l[3]
a = l[4:4+x]
b = l[4+x:4+x+y]
c = l[4+x+y:]

mat = np.add(np.array([a for _ in range(y)]), np.array([b for _ in range(x)]).T)
mats = np.sort(np.ravel(np.array([np.add(mat,c[i]) for i in range(z)])))[::-1]
for i in range(k):
    print(mats[i])

Submission status: Runtime Error

Solution code:

K = [int(n) for n in input().rstrip().split()][3]

A = sorted([int(n) for n in input().rstrip().split()],reverse=True)
B = sorted([int(n) for n in input().rstrip().split()],reverse=True)
C = sorted(int(n) for n in input().rstrip().split()],reverse=True)

List = []

for n in A:
    for m in B:
        List.append(n+m)

List2 =[]

for k in List[:K]:
    for i in C:
        List2.append(k + i)


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

Submission status: Runtime Error

Solution code:
[XYZK,A,B,C] = [input() for i in range(4)]
[X,Y,Z,K] = [int(i) for i in XYZK.split()]
A = [int(i) for i in A.split()]
B = [int(i) for i in B.split()]
C = [int(i) for i in C.split()]
Ans = [0 for i in range(K)]
for a in A:
    for b in B:
        for c in C:
            abc = a+b+c
            if min(Ans) < a + b + c:
                Ans[Ans.index(min(Ans))] = a+b+c
Ans = sorted(Ans,reverse=True)
for i in range(Ans):
    print(Ans[i])

Submission status: Runtime Error

Solution code:
X,Y,Z,K = (int(num) for num in input().split())
a = [int(num) for num in input().split()]
b = [int(num) for num in input().split()]
c = [int(num) for num in input().split()]
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

l = []
for i in range(X):
    if i+1 > K:
        break
    
    for j in range(Y):
        if (i+1) + (j+1) > K:
            break
        
        for k in range(Z):
            if (i+1) + (j+1) + (k+1) > K:
                break
            
            l.append(a[i]+b[j]+c[k])
            
            
l.sort(reverse=True)
for i in range(K):
    print(l[i])

Submission status: Runtime Error

Solution code:
X,Y,Z,K = (int(num) for num in input().split())
a = [int(num) for num in input().split()]
b = [int(num) for num in input().split()]
c = [int(num) for num in input().split()]
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

l = []
for i in range(X):
    if i+1 > K break
    
    for j in range(Y):
        if (i+1) + (j+1) > K break
        
        for k in range(Z):
            if (i+1) + (j+1) + (k+1) > K break
            
            l.append(a[i]+b[j]+c[k])
            
            
l.sort(reverse=True)
for i in range(K):
    print(l[i])

Submission status: Runtime Error

Solution code:
x, y, z, k = map(int, input().split())
A = list(sorted(list(map(int, input().split())), reverse=True))
B = list(sorted(list(map(int, input().split())), reverse=True))
C = list(sorted(list(map(int, input().split())), reverse=True))
D = [A[a] + B[b] + C[c] for a in range(x) for b in range(y) for c in range(z) if a + b + c + 3 <= k]
D.sort(reverse=True)
for i in range(k):
    print(D[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)

delicious_list = []
for a in A:
    for b in B:
        for c in C:
            if a*b*c>K: continue
            delicious_list.append(a+b+c)
delicious_list.sort(reverse=True)
for i in range(K):
    print(delicious_list[i])

Submission status: Runtime Error

Solution code:
a,b,c,k=map(int,input().split())
cake1=sort(map(int,input().split()),reverse=True)[:max(a,k)]
cake2=sort(map(int,input().split()),reverse=True)[:max(b,k)]
cake3=sort(map(int,input().split()),reverse=True)[:max(c,k)]
res=[]
for i in range(min(a,k)):
  for j in range(min(b,k)):
    for l in range(min(c,k)):
      if (a+1)*(b+1)*(c+1)<k:
        res.append(cake1[i]+cake2[j]+cake3[l])
res.sort(reverse=True)
for i in range(k):
  print(res[i])

Submission status: Runtime Error

Solution code:
#from collections import deque
#import copy

x,y,z,ansk=(int(i) for i in input().split())
#print(x,y,z,k)

a=list(int(i) for i in input().split())
a.sort(reverse=True)
b=list(int(i) for i in input().split())
b.sort(reverse=True)
c=list(int(i) for i in input().split())
c.sort(reverse=True)
#print(a,b,c)

mylist=[0 for i in range(x*y)]
k=0
for i in range(x):
  for j in range(y):
    mylist[k]=a[i]+b[j]
    k+=1
mylist.sort(reverse=True)
if len(mylist)>3001:
  xy=len(mylist)
  mylist=mylist[:3001]
#print(mylist)

k=0
mylist1=[0 for i in range(xy*z)]
for i in range(xy):
  for j in range(z):
    mylist1[k]=mylist[i]+c[j]
    k+=1
mylist1.sort(reverse=True)

if len(mylist1) > 3001:
  mylist1 = mylist1[:3001]
  
for i in range(ansk):
  print(mylist1[i])

Submission status: Runtime Error

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

cakes_types = [[int(i) for i in input().split()] for _ in range(3)]


for types in cakes_types:
    types.extend([0 for _ in range(max(x,y,z)-len(types))])
    types.sort(reverse=True)

sum_list = list()

for i in range(k):
    sum_taste = 0;
    for j in range(3):
        sum_taste += cakes_types[j][i]
    sum_list.append(sum_taste)

print(sum_list)

Submission status: Runtime Error

Solution code:
x, y, z, k = map(int, input().split())
LA = list(map(int, input().split()))
LB = list(map(int, input().split()))
LC = list(map(int, input().split()))
LAB = []
L = []

for i in range(x):
    for j in range(y):
        LAB.append(LA[i]+LB[j])
LAB.sort(reverse=True)
LAB = LAB[:k]

for i in range(k):
    for j in range(z):
        L.append(LAB[i]+LC[j])
L.sort(reverse=True)

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

Submission status: Runtime Error

Solution code:
import heapq
x,y,z,k = list(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)

ans = []
log = set()

total = (a[0] + b[0] + c[0]) * (-1)
heapq.heappush(ans, (total, 0, 0, 0))
log.add((0, 0, 0))

for i in range(k):
  (total, aa, bb, cc) = heapq.heappop(ans)
  print(total * (-1))
  if (aa+1, bb, cc) not in log:
    if aa+1 <= x:
      total = (a[aa+1] + b[bb] + c[cc]) * (-1)
      heapq.heappush(ans, (total, aa+1, bb, cc))
      log.add((aa+1, bb, cc))
  if (aa, bb+1, cc) not in log:
    if bb+1 <= y:
      total = (a[aa] + b[bb+1] + c[cc]) * (-1)
      heapq.heappush(ans, (total, aa, bb+1, cc))
      log.add((aa, bb+1, cc))
  if (aa, bb, cc+1) not in log:
    if cc+1 <= z:
      total = (a[aa] + b[bb] + c[cc+1]) * (-1)
      heapq.heappush(ans, (total, aa, bb, cc+1))
      log.add((aa, bb, cc+1))

Submission status: Runtime Error

Solution code:
import heapq
x,y,z,k = list(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)

del a[min(k,x):]
del b[min(k,y):]
del c[min(k,z):]

ans = []
log = set()

total = (a[0] + b[0] + c[0]) * (-1)
heapq.heappush(ans, (total, 0, 0, 0))
log.add((0, 0, 0))

for i in range(k):
  (total, aa, bb, cc) = heapq.heappop(ans)
  print(total * (-1))
  if (aa+1, bb, cc) not in log:
    if aa+1 <= x:
      total = (a[aa+1] + b[bb] + c[cc]) * (-1)
      heapq.heappush(ans, (total, aa+1, bb, cc))
      log.add((aa+1, bb, cc))
  if (aa, bb+1, cc) not in log:
    if bb+1 <= y:
      total = (a[aa] + b[bb+1] + c[cc]) * (-1)
      heapq.heappush(ans, (total, aa, bb+1, cc))
      log.add((aa, bb+1, cc))
  if (aa, bb, cc+1) not in log:
    if cc+1 <= z:
      total = (a[aa] + b[bb] + c[cc+1]) * (-1)
      heapq.heappush(ans, (total, aa, bb, cc+1))
      log.add((aa, bb, cc+1))

Submission status: Runtime Error

Solution code:
import heapq
x,y,z,k = list(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)

del a[min(k,x):]
del b[min(k,y):]
del c[min(k,z):]

ans = []
log = set()

total = (a[0] + b[0] + c[0]) * (-1)
heapq.heappush(ans, (total, 0, 0, 0))
log.add((0, 0, 0))

for i in range(k):
  (total, aa, bb, cc) = heapq.heappop(ans)
  print(total * (-1))
  if (aa+1, bb, cc) not in log:
    if aa+1 <= x:
      total = (a[aa+1] + b[bb] + c[cc]) * (-1)
      heapq.heappush(ans, (total, aa+1, bb, cc))
      log.add((aa+1, bb, cc))
  if (aa, bb+1, cc) not in log:
    if bb+1 <= y:
      total = (a[aa] + b[bb+1] + c[cc]) * (-1)
      heapq.heappush(ans, (total, aa, bb+1, cc))
      log.add((aa, bb+1, cc))
  if (aa, bb, cc+1) not in log:
    if cc+1 <= y:
      total = (a[aa] + b[bb] + c[cc+1]) * (-1)
      heapq.heappush(ans, (total, aa, bb, cc+1))
      log.add((aa, bb, cc+1))

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

Submission status: Runtime Error

Solution code:
X, Y, Z, K = map(int,input().split())
A_list = sorted(list(map(int,input().split())), reverse=True)
B_list = sorted(list(map(int,input().split())), reverse=True)
C_list = sorted(list(map(int,input().split())), reverse=True)

E_list = sorted([ai+bi for ai in A_list for bi in B_list], reverse=True)[:K]
sum_list = sorted([ei+ci for ci in E_list for ci in C_list], reverse=True)[:K]

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

Submission status: Runtime Error

Solution code:
import numpy as np
X, Y, Z, K = [int(i) for i in input().split()]

A = sorted([int(i) for i in input().split()], reverse=True)
B = sorted([int(i) for i in input().split()], reverse=True)
C = sorted([int(i) for i in input().split()], reverse=True)

Anum = 0
Bnum = 0
Cnum = 0

AB=np.zeros(X*Y)
for i in range(X):
    for j in range(Y):
        AB[Y*i+j] = A[i]+B[j]

AB = sorted(AB, reverse=True)
AB = AB[:min(X*Y,K)]

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

ABC = sorted(ABC, 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 = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]
C = [int(n) for n in input().split()]
A_B = []
for a in A:
    for b in B):
        A_B.append(a+b)
A_B_K = sorted(A_B)[:K]
A_B_C=[]
for ab in A_B_K:
    for c in C):
        A_B_C.append(ab+c)
A_B_C.sort(reverse=True)
for i in range(min(K,len(A_B_C))):
    print(A_B_C[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()))))
 
ar = []
history = set()
 
 
def push(x, y, z):
    if (x, y, z) in history:
        pass
    else:
        v = aa[x] + bb[y] + cc[z]
        heapq.heappush(ar, (-v, x, y, z))
        history.add((x, y, z))
 
 
def pop():
    (v, x, y, z) = heapq.heappop(ar)
    return (-v, x, y, z)
 
 
push(0, 0, 0)
for _ in range(k):
    (total, x, y, z) = pop()
    print(total)
    if x + 1 < len(aa):
        push(x + 1, y, z)
    if y + 1 < len(bb):
        push(x, y + 1, z)
    if z + 1 < len(cc):
        push(x, y, z + 1)
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()))))

ar = []
history = set()


def push(x, y, z):
    if (x, y, z) in history:
        pass
    else:
        v = aa[x] + bb[y] + cc[z]
        heapq.heappush(ar, (-v, x, y, z))
        history.add((x, y, z))


def pop():
    (v, x, y, z) = heapq.heappop(ar)
    return (-v, x, y, z)


push(0, 0, 0)
for _ in range(k):
    (total, x, y, z) = pop()
    print(total)
    if x + 1 < len(aa):
        push(x + 1, y, z)
    if y + 1 < len(bb):
        push(x, y + 1, z)
    if z + 1 < len(cc):
        push(x, y, z + 1)

Submission status: Runtime Error

Solution code:
Vimport 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 = []
heapq.heapify(q)
heapq.heappush(q,(-(A[0] + B[0] + C[0]),0,0,0))
for _ in range(K):
    m, i, j, k = heapq.heappop(q) #mに和、ijkにインデックス
    print(-m) #親から取り出すが、親は子よりも小さい、大きい順にするために-を入れている
    if i + 1 < X: #最初にiには０が挿入されている,pythonではインデックスが０から始まるから<xでいい
        s = (-(A[i+1] + B[j] + C[k]), i+1, j, k)
        if s not in q:
            heapq.heappush(q,s)
    if j + 1 < Y:
        s = (-(A[i] + B[j+1] + C[k]), i, j+1, k)
        if s not in q:
            heapq.heappush(q, s)
    if k + 1 < Z:
        s = (-(A[i] + B[j] + C[k+1]), i, j, k+1)
        if s not in q:
            heapq.heappush(q,s)

Submission status: Runtime Error

Solution code:
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 = []
heapq.heapify(q)
heapq.heappush(q,(-(a[0] + b[0] + c[0]),0,0,0))
for _ in range(K):
    m, i, j, k = heapq.heappop(q) #mに和、ijkにインデックス
    print(-m) #親から取り出すが、親は子よりも小さい、大きい順にするために-を入れている
    if i + 1 < X: #最初にiには０が挿入されている,pythonではインデックスが０から始まるから<xでいい
        s = (-(A[i+1] + B[j] + C[k]), i+1, j, k)
        if s not in q:
            heapq.heappush(q,s)
    if j + 1 < Y:
        s = (-(A[i] + B[j+1] + C[k]), i, j+1, k)
        if s not in q:
            heapq.heappush(q, s)
    if k + 1 < Z:
        s = (-(A[i] + B[j] + C[k+1]), i, j, k+1)
        if s not in q:
            heapq.heappush(q,s)

Submission status: Runtime Error

Solution code:
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 = []
heapq.heapify(q)
heapq.heappush(q,(-(a[0] + b[0] + c[0]),0,0,0))
for _ in range(K):
    m, i, j, k = heapq.heappop(q) #mに和、ijkにインデックス
    print(-m) #親から取り出すが、親は子よりも小さい、大きい順にするために-を入れている
    if i + 1 < X: #最初にiには０が挿入されている,pythonではインデックスが０から始まるから<xでいい
        s = (-(A[i+1] + B[j] + C[k]), i+1, j, k)
        if s not in q:
            heapq.heappush(q,s)
    if j + 1 < Y:
        s = (-(A[i] + B[j+1] + C[k]), i, j+1, k)
        if s not in q:
            heapq.heappush(q, s)
    if k + 1 < Z:
        s = (-(A[i] + B[j] + C[k+1]), i, j, k+1)
        if s not in q:
            heapq.heappush(q,s)

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

a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)

for i in range(x):
    for j in range(y):
        for l in range(z):
            if i + j + l + 3 <= k:
                anss.append(a[i] + b[j] + c[l])
            else:
                break
anss.sort(reverse = True)

for i in range(k):
    print(anss[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()))
anss = []

a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)

for i in range(x):
    for j in range(y):
        for l in range(z):
            if i + j + l + 3 <= k:
                anss.append(a[i] + b[j] + c[l])

anss.sort(reverse = True)

for i in range(k):
    print(anss[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()))
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
E = sorted(D, reverse = True)
for n in range(K):
	print(E[n])