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()))
N=X*Y
K1=[0]*(N)
n=0
for i in range(X):
  for j in range(Y):
    K1[n]=A[i]+B[j]
    n+=1
K1.sort(reverse=True)
n=0
K2=[0]*(N*Z)
for i in range(N):
  for j in range(Z):
    K2[n]=K1[i]+C[j]
    n+=1
K2.sort(reverse=True)
for i in range(K):
  print(K2[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, abc = [], []

for i in a:
    for j in b:
        ab.append(i+j)

ab.sort()
s = ab[x*y-k:]
for i in s:
    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 = 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)
LIS = []
for i in range(X):
    INTB = 3000//(j+1)
    for j in range(min(INTB+1,Y)):
        INT = 3000//((i+1)*(j+1))
        for k in range(min(INT+1,Z)):
            SUM = A[i] + B[j] + C[k]
            LIS.append(SUM)
LIS.sort(reverse = True)
for i in range(K):
    print(LIS[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)
LIS = []
for i in range(X):
    INTB = 3000//(j+1)
    for j in range(min(INTB+1,Y):
        INT = 3000//((i+1)*(j+1))
        for k in range(min(INT+1,Z)):
            SUM = A[i] + B[j] + C[k]
            LIS.append(SUM)
LIS.sort(reverse = True)
for i in range(K):
    print(LIS[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)
LIS = []
for i in range(X):
    for j in range(Y):
        for k in range(min((3000//(s+1)*(t+1)),Z)):
            SUM = A[i] + B[j] + C[k]
            LIS.append(SUM)
LIS.sort(reverse = True)
for i in range(K):
    print(LIS[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)
LIS = []
S = 0
T = 0
for s in range(X):
    for t in range(Y):
        for u in range(min((3000//(s+1)*(t+1)),Z)
            SU = A[s] + B[t] + C[u]
            LIS.append(SU)
LIS.sort(reverse = True)
for i in range(K):
    print(LIS[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)
LIS = []
S = 0
T = 0
for s in range(X):
    for t in range(Y):
        for u in range(min((3000//(s+1)*(t+1))+1,Z))
            SU = A[s] + B[t] + C[u]
            LIS.append(SU)
LIS.sort(reverse = True)
for i in range(K):
    print(LIS[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)
LIS = []
LISA = []
LISB = []
S = 0
T = 0
for s in range(X):
    for t in range(Y):
        if (s+1)*(t+1) <= 3000:
            LISA.append(s)
            LISB.append(t)
        elif (s+1)*(t+1) > 3000:
            S += s
            T += t
            break
            
for i in range(len(LISA)):
    PR = A[LISA[i]]+B[LISB[i]]
    for j in range(max(Z,(3000//(S+1)),(3000//(T+1)))):
        LIS.append(PR+C[j])
LIS.sort(reverse = True)
for i in range(min(len(LIS),K)):
    print(LIS[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()]

L=[0]*X*Y*Z
K = min(K, 3000, X*Y*Z)

#for x in range(X):
#    for y in range(Y):
#        for z in range(Z):
#            L.append(A[x]+B[y]+C[z])

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

L=[0]*X*Y*Z
K = min(K, 3000, X*Y*Z)

for x in range(X):
    for y in range(Y):
        for z in range(Z):
            L.append(A[x]+B[y]+C[z])

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

L=[0]*X*Y*Z
K = min(K, 3000, X*Y*Z)

for x in range(X):
    for y in range(Y):
        for z in range(Z):
            L.append(A[x]+B[y]+C[z])

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

bi_comb = []
for i in range(min(X, K)):
    for j in range(min(Y, K)):
        if (i+1)*(j+1) > K:
            break
        bi_comb.append(A[i] + B[j])
bi_comb.sort(reverse=True)

tri_comb = []
for k in range(K):
    for l in range(min(Z, K)):
        if (k+1)*(l+1) > K:
            break
        tri_comb.append(bi_comb[k] + C[l])
tri_comb.sort(reverse=True)

print(*tri_comb[:K], sep="\n")

Submission status: Runtime Error

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

bi_comb = []
for i in range(min(X, K)):
    for j in range(min(Y, K)):
        if (i+1)*(j+1) > K:
            break
        bi_comb.append(A[i] + B[j])
bi_comb.sort(reverse=True)

tri_comb = []
for k in range(K):
    for l in range(min(Z, K)):
        tri_comb.append(bi_comb[k] + C[l])
tri_comb.sort(reverse=True)

print(*tri_comb[:K], sep="\n")

Submission status: Runtime Error

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

bi_comb = []
for i in range(X):
    for j in range(Y):
        if (i+1)*(j+1) > K:
            break
        bi_comb.append(A[i] + B[j])
bi_comb.sort(reverse=True)
# bi_comb = bi_comb[:K]
tri_comb = []
for k in range(K):
    for l in range(Z):
        tri_comb.append(bi_comb[k] + C[l])
tri_comb.sort(reverse=True)

print(*tri_comb[:K], sep="\n")

Submission status: Runtime Error

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


bi_comb = []
for i in A[:K]:
    for j in B[:K]:
        bi_comb.append(i+j)
bi_comb.sort(reverse=True)
bi_comb = bi_comb[:K]
tri_comb = []
for k in range(K):
    for l in range(len(C[:K])):
        tri_comb.append(bi_comb[k] + C[l])
tri_comb.sort(reverse=True)

print(*result_l, sep="\n")

Submission status: Runtime Error

Solution code:
from heapq import heappop,heappush
from collections import defaultdict
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)
q =[]
ans = []
sc = defaultdict(bool)
heapq.heappush(q,(-a[0] - b[0] - c[0], 0, 0, 0))

while len(ans) < K:
    deli, i, j, k = heappop(q)
    print(-deli)
    ans.append(-deli)
    
    if i + 1 < x and not sc[(i + 1, j, k)]:
        heapq.heappush(q,(-a[i + 1] - b[j] - c[k], i + 1, j, k))
        sc[(i + 1, j, k)] = True
    
    if j + 1 < y and not sc[(i, j + 1, k)]:
        heapq.heappush(q,(-a[i] - b[j + 1] - c[k], i, j + 1, k))
        sc[(i, j + 1, k)] = True
    
    if k + 1 < z and not sc[(i, j, k + 1)]:
        heapq.heappush(q,(-a[i] - b[j] - c[k + 1], i, j, k + 1))
        sc[(i, j, k + 1)] = True

Submission status: Runtime Error

Solution code:
import heapq
x,y,z,k = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))
 
al.sort(reverse=True)
bl.sort(reverse=True)
cl.sort(reverse=True)
regist = set()
regist.add((0,0,0))
q = [(-1*(al[0]+bl[0]+cl[0]),0,0,0)]
heapq.heapify(q)
for _ in range(k):
    s,ai,bi,ci = heapq.heappop(q)
    print(-s,flush=True)
 
    if ai+1<x and (ai+1,bi,ci) not in regist:
        heapq.heappush(q, (-1*(al[ai+1]+bl[bi]+cl[ci]), ai+1,bi,ci))
        regist.add((ai+1,bi,ci))
 
    if bi+1<y and (ai,bi+1,ci) not in regist:
        heapq.heappush(q, (-1*(al[ai]+bl[bi+1]+cl[ci]), ai,bi+1,ci))
        regist.add((ai,bi+1,ci))
 
    if ci+1<z and (ai,bi,ci+1) not in regist:
        heapq.heappush(q, (-1*(al[ai]+bl[bi]+cl[ci+1]), ai,bi,ci+1))
        regist.add((ai,bi,ci+1))

Submission status: Runtime Error

Solution code:
import heapq

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)

Q = []
heapq.heappush(Q, (-(A[0]+B[0]+C[0]), 0, 0, 0))
registered = set()
registered.add((0, 0, 0))
for t in range(K):
    s, ai, bi, ci = heapq.heappop(Q)
    print(-s, flush=True)

    if ai+1 < X and (ai+1, bi, ci) not in registered:
        heapq.heappush(Q, (-(A[ai+1]+B[bi]+C[ci]), ai+1, bi, ci))
        registered.add((ai+1, bi, ci))
    if bi+1 < Y and (ai, bi+1, ci) not in registered:
        heapq.heappush(Q, (-(A[ai]+B[bi+1]+C[ci]), ai, bi+1, ci))
        registered.add((ai, bi+1, ci))
    if ci+1 < Z and (ai, bi, ci+1) not in registered:
        heapq.heappush(Q, (-(A[ai]+B[bi]+C[ci+1]), ai, bi, ci+1))
        registered.add((ai, bi, ci+1))

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)

a_b = []
for i in range(x):
    for j in range(y):
        a_b.append(a[i] + b[j])
a_b.sort(reverse=True)
ans = []
for i in range(k):
    for j in range(k):
        ans.append(a_b[i] + c[j])
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])

Submission status: Runtime Error

Solution code:
import sys
import heapq

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)

q = [[(A[0]+B[0]+C[0])*(-1),0,0,0]]
heapq.heapify(q)
count = 0
x, y, z = 0, 0, 0
alr = [[1,1,1]]

while count < K:
    poped = heapq.heappop(q)
    ans = poped[0]*(-1)
    print(ans)
    i, j, k = poped[1], poped[2], poped[3]
    if i+1 < X and not [i+1,j,k] in alr:
        heapq.heappush(q, [(A[i+1]+B[j]+C[k])*(-1), i+1, j, k])
        alr.append([i+1,j,k])
    if j+1 < Y and not [i,j+1,k] in alr:
        heapq.heappush(q, [(A[i]+B[j+1]+C[k])*(-1), i, j+1, k])
        alr.append([i,j+1,k])
    if k+1 < Z and not [i,j,k+1] in alr:
        heapq.heappush(q, [(A[i]+B[j]+C[k+1])*(-1), i, j, k+1])
        alr.append([i,j,k+1])
    count += 1

Submission status: Runtime Error

Solution code:
# coding:utf-8

import sys
import numpy as np

INF = float('inf')
MOD = 10 ** 9 + 7

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 LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    x, y, z, k = LI()
    A = np.array(LI())
    B = np.array(LI())
    C = np.array(LI())
    ABC = np.add.outer(np.add.outer(A, B), C).flatten()
    ABC.sort()
    res = '\n'.join(map(str, reversed(ABC[-k:])))
    print(res)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
x, y, z, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
max_num = a[-1] + b[-1] + c[-1]
a_m = [aa - a[-1] for aa in a[:-1]]
b_m = [bb - b[-1] for bb in b[:-1]]
c_m = [cc - c[-1] for cc in c[:-1]]
d = a_m + b_m + c_m + [0]
d.sort()
d = list(reversed(d))
for i in range(k):
    ans = max_num + d[i]
    print(ans)

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

Submission status: Runtime Error

Solution code:
X, Y, Z, K = input().split()
X = int(X)
Y = int(Y)
Z = int(Z)
K = int(K)
A = [int(a) for a in input().split()]
A = sorted(A, reverse=True)
B = [int(b) for b in input().split()]
B = sorted(B, reverse=True)
C = [int(c) for c in input().split()]
C = sorted(C, reverse=True)
ABC = []
a, b, c = 0, 0, 0
ABC.append(A[a] + B[b] + C[c])
k = 1
while K+10>k:
    if len(A)>=a+2:
        for y in range(b+1):
            for z in range(c+1):
                ABC.append(A[a+1] + B[y] + C[z])
                k += 1
        a += 1
    if len(B)>=b+2:
        for x in range(a+1):
            for z in range(c+1):
                ABC.append(A[x] + B[b+1] + C[z])
                k += 1
        b += 1
    if len(C)>=c+2:
        for x in range(a+1):
            for y in range(b+1):
                ABC.append(A[x] + B[y] + C[c+1])
                k += 1
        c += 1
    k += 1
ABC_sorted = sorted(ABC, reverse=True)
for i in range(K):
    print(ABC_sorted[i])

Submission status: Runtime Error

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

import heapq


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

index_hstr = []
deliciouses = []
# priority queue
pq = []
heapq.heappush(pq, (-a[0] - b[0] - c[0], 0, 0, 0))
index_hstr.append((0, 0, 0))

for t in range(k):
    deli, i, j, k = heapq.heappop(pq)
    if (i+1, j, k) not in index_hstr:
        heapq.heappush(pq, (-a[i+1] - b[j] - c[k], i+1, j, k))
        index_hstr.append((i+1, j, k))
    if (i, j+1, k) not in index_hstr:
        heapq.heappush(pq, (-a[i] - b[j+1] - c[k], i, j+1, k))
        index_hstr.append((i, j+1, k))
    if (i, j, k+1) not in index_hstr:
        heapq.heappush(pq, (-a[i] - b[j] - c[k+1], i, j, k+1))
        index_hstr.append((i, j, k+1))
    deliciouses.append(-deli)


pass

Submission status: Runtime Error

Solution code:
import heapq
X, Y, Z, K = map(int, input().split())
A_array = list(map(int, input().split()))
B_array = list(map(int, input().split()))
C_array = list(map(int, input().split()))

A_array.sort()
B_array.sort()
C_array.sort()

use_array = []
sum_array = []

candidate = []
heapq.heapify(candidate)

max_sum = A_array[-1] + B_array[-1] + C_array[-1]

heapq.heappush(candidate, (0, X - 1, Y - 1, Z - 1))
use_array.append((X - 1, Y - 1, Z - 1))
for i in range(K):

    s, x, y, z = heapq.heappop(candidate)

    sum_array.append(s)
    if x != 0 and (X - 1, Y, Z) not in use_array:
        use_array.append((X - 1, Y, Z))
        diff = A_array[x] - A_array[x - 1]
        heapq.heappush(candidate, (s + diff, x - 1, y, z))

    if y != 0 and (X, Y - 1, Z) not in use_array:
        use_array.append((X, Y - 1, Z))
        diff = B_array[y] - B_array[y - 1]
        heapq.heappush(candidate, (s + diff, x, y - 1, z))

    if z != 0 and (X, Y, Z - 1) not in use_array:
        use_array.append((X, Y, Z - 1))
        diff = C_array[z] - C_array[z - 1]
        heapq.heappush(candidate, (s + diff, x, y, z - 1))

for ans in sum_array:
    print(max_sum - ans)

Submission status: Runtime Error

Solution code:
# どうやって自明な条件で計算量を落としていくか
# 不等式に注目。pythonが耐えるのは10^6程度
import numpy as np
X,Y,Z,K = map(int,input().split())
As = sorted(list(map(int,input().split())),reverse=True)
Bs = sorted(list(map(int,input().split())),reverse=True)
Cs = sorted(list(map(int,input().split())),reverse=True)

# ABでソート
AB = []
for A in As:
    for B in Bs:
        AB.append(A+B)
ABs = sorted(AB,reverse=True)

# その中からK番目まで
ABC = []
for i in range(min(len(ABs),K)):
    for C in Cs:
        ABC.append(ABs[i]+C)

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

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
	int x, y, z, k;
	cin >> x >> y >> z >> k;

	long long a[1001],b[1001],c[1001];
	vector<long long> ab, abc;
	int i;
	for(i=0;i<x;i++) cin >> a[i];
	// printf("%d\n", a[x-1]);
	for(i=0;i<y;i++) cin >> b[i];
	// printf("%d\n", b[y-1]);
	for(i=0;i<z;i++) cin >> c[i];
	// printf("%d\n", c[z-1]);
	// cout << "a:" << a[x-1] << " b:" << b[y-1] << " c:" << c[z-1] << endl;

	for(i=0;i<x;i++){
		for(int j=0;j<y;j++){
			ab.push_back(a[i]+b[j]);
		}
	}
	sort(ab.begin(), ab.end(), greater<long long>());
	for(i=0;i<min(k, x*y);i++){
		for(int j=0;j<z;j++){
			abc.push_back(ab[i]+c[j]);
		}
	}
	sort(abc.begin(), abc.end(), greater<long long>());

	for(i=0;i<k;i++){
		cout << abc[i] << endl;
	}
	return 0;
}

Submission status: Runtime Error

Solution code:
X, Y, Z, K = map(int, input().split())
ListA = list(input().split())
ListB = list(input().split())
ListC = list(input().split())
ListAns =[]
for a in ListA:
    for b in ListB:
        for c in ListC:
            ans = a + b + c
            ListAns.append(ans)
            if len(ListAns) = K:
                break
ListAns.sort()
for i in ListAns:
    print(i)

Submission status: Runtime Error

Solution code:
a = map(int,input().split())
a = list(a)
b = map(int,input().split())
b = list(b)
c = map(int,input().split())
c = list(c)
d = map(int,input().split())
d = list(d)
e = [0]*a[0]*a[1]
f = [0]*a[0]*a[1]*a[2]
print(a,b,c,d)
g1,g2 = 0,0
for i in range(a[0]):
    for j in range(a[1]):
        e[g1] = b[i] + c [j]
        g1 += 1
print(e)
for k in range(a[2]):
    for l in range(len(e)):
        f[g2] = c[k] + e[l]
        g2 += 1
f.reverse()
print(f)
for m in range(a[3]):
    print(f[m])

Submission status: Runtime Error

Solution code:
X,Y,Z,K=map(int,input().split())
q1=list(map(int,input().split()))#要素数 X
q2=list(map(int,input().split()))#要素数 Y
q3=list(map(int,input().split()))#要素数 Z

Q1=sorted(q1)
Q2=sorted(q2)
Q3=sorted(q3)

M=Q1[X-1]+Q2[Y-1]+Q3[Z-1]
print(M)
d1=[]
d2=[]
d3=[]
#となりとの差
for x in range(X-1):
    d1.append(Q1[X-x-2]-Q1[X-x-1])
for y in range(Y-1):
    d2.append(Q2[Y-y-2]-Q2[Y-y-1])
for z in range(Z-1):
    d3.append(Q3[Z-z-2]-Q3[Z-z-1])

m=[d1[0],d2[0],d3[0]]
mm=min([sum(d1),sum(d2),sum(d3)])

count1=0
count2=0
count3=0
D1=[d1[0]]
D2=[d2[0]]
D3=[d3[0]]
for i in range(K-1):
    print(M+max(m))
    if m.index(max(m))==0:
        count1+=1
        try:
            D1.append(d1[count1])
            m[0]=sum(D1)      
        except IndexError:
            m[0]=mm-1       
    elif m.index(max(m))==1:
        count2+=1
        try:
            D2.append(d2[count2])
            m[1]=sum(D2)      
        except IndexError:
            m[1]=mm-1        
    else:
        count3+=1
        try:
            D3.append(d3[count3])
            m[2]=sum(D3)      
        except IndexError:
            m[2]=mm-1

Submission status: Runtime Error

Solution code:
X,Y,Z,K=map(int,input().split())
q1=list(map(int,input().split()))#要素数 X
q2=list(map(int,input().split()))#要素数 Y
q3=list(map(int,input().split()))#要素数 Z

Q1=sorted(q1)
Q2=sorted(q2)
Q3=sorted(q3)

M=Q1[X-1]+Q2[Y-1]+Q3[Z-1]
print(M)
d1=[]
d2=[]
d3=[]
#となりとの差
for x in range(X-1):
    d1.append(Q1[X-x-2]-Q1[X-x-1])
for y in range(Y-1):
    d2.append(Q2[Y-y-2]-Q2[Y-y-1])
for z in range(Z-1):
    d3.append(Q3[Z-z-2]-Q3[Z-z-1])

m=[d1[0],d2[0],d3[0]]
mm=min([sum(d1),sum(d2),sum(d3)])

count1=0
count2=0
count3=0
D1=[d1[0]]
D2=[d2[0]]
D3=[d3[0]]
for i in range(K-1):
    print(M+max(m))
    if m.index(max(m))==0:
        count1+=1
        try:
            D1.append(d1[count1])
            m[0]=sum(D1)      
        except IndexError:
            m[0]=mm-1
        
        
        
    elif m.index(max(m))==1:
        count2+=1
        try:
            D2.append(d2[count2])
            m[1]=sum(D2)      
        except IndexError:
            m[1]=mm-1
        
        
    else:
        count3+=1
        try:
            D3.append(d3[count3])
            m[2]=sum(D1)      
        except IndexError:
            m[2]=mm-1

Submission status: Runtime Error

Solution code:
 # import sys  sys.exit()を使う時に必要

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    # N = int(input())
    X, Y, Z, K = 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()] 
    # S = [input() for _ in range(N)]  縦持ち／行数N
    # t = [0] * N  　　ti xi yi 縦持ち/行数N
    # x = [0] * N
    # y = [0] * N
    # for i in range(N):
    #   t[i], x[i], y[i] = map(int, input().split())
  else:
    A = [1,10,100]
    B = [2,20,200]
    C = [1,10,100]
    X = len(A)
    Y = len(B)
    Z = len(C)
    K = 5

  ans = []
  # Processing
  A.sort(reverse=True)
  B.sort(reverse=True)
  C.sort(reverse=True)
      
  for i in A:
    if i >= A[min(K,X)-1]:
      for j in B:
        if j >= B[min(K,Y)-1] :
          for k in C:
            if k >= C[min(K,Z)-1]:
              ans.append(i+j+k)
            else:
              break
        else:
          break
    else:
      break
    
  ans.sort(reverse=True)
  if 'get_ipython' in globals(): 
    print(ans)

  for i in range(0,K):
    print(ans[i])      

main()

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

m = max(X,Y,Z)


ansl = [0] * 3000
tmp = (5,5,5)
inda = 0
indb = 0
indc = 0

hoge = 10**12

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

sumab.sort()
sumab.reverse()

anslist = []
for k in range(K):
	for cc in range(Z):
		anslist.append(sumab[k] + C[cc])
		
anslist.sort()
anslist.reverse()
for aa in range(K):
	print (anslist[aa])

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)
#A~Cは降順でソート済み
lenA = X
lenB = Y
lenC = Z #分かりにくいので名前を変えただけ

#差分の配列を作る
difA = []
difB = []
difC = []
for i, a in enumerate(A):
  if i == 0:
    preA = a
    continue #0ならpreAに入れるだけ
  difA.append(preA - a)
  preA = a
for i, b in enumerate(B):
  if i == 0:
    preB = b
    continue #0ならpreBに入れるだけ
  difB.append(preB - b)
  preB = b
for i, c in enumerate(C):
  if i == 0:
    preC = c
    continue #0ならpreCに入れるだけ
  difC.append(preC - c)
  preC = c
#print(difA,difB,difC) #デバッグ用

cntA, cntB, cntC = sum(difA), sum(difB), sum(difC)
cntA, cntB, cntC = (1500*cntA)//(cntA+cntB+cntC),(1500*cntB)//(cntA+cntB+cntC),(1500*cntC)//(cntA+cntB+cntC)

setc = []
for i in range(0, min(cntA,lenA)):
  for j in range(0, min(cntB,lenB)):
    for k in range(0, min(cntC,lenC)):
      setc.append(A[i]+B[j]+C[k])
slist = sorted(setc,reverse=True)

for i in range(K):
  print(slist[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)
#A~Cは降順でソート済み
lenA = X
lenB = Y
lenC = Z #分かりにくいので名前を変えただけ

#差分の配列を作る
difA = []
difB = []
difC = []
for i, a in enumerate(A):
  if i == 0:
    preA = a
    continue #0ならpreAに入れるだけ
  difA.append(preA - a)
  preA = a
for i, b in enumerate(B):
  if i == 0:
    preB = b
    continue #0ならpreBに入れるだけ
  difB.append(preB - b)
  preB = b
for i, c in enumerate(C):
  if i == 0:
    preC = c
    continue #0ならpreCに入れるだけ
  difC.append(preC - c)
  preC = c
#print(difA,difB,difC) #デバッグ用

nowsum = A[0]+B[0]+C[0]
print(nowsum)
del A[0]
del B[0]
del C[0]
#ここにi番目の美味しさ合計を入れていく
#初期値は一番美味しいケーキ3種の合計
for i in range(K-1): #[1]~[K-1]についてやればいい
  #delしていくから添字は気にしなくてもいい
  if difA[0] <= min(difB[0], difC[0]):
    nowsum -= difA[0]
    del difA[0]
    del A[0]
    if not difA: difA.append(10e9)
  elif difB[0] <= difC[0]:
    nowsum -= difB[0]
    del difB[0]
    del B[0]
    if not difB: difB.append(10e9)
  else:
    nowsum -= difC[0]
    del difC[0]
    del C[0]
    if not difC: difC.append(10e9)
  print(nowsum)

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()))
sam = []
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
ba,bb,bc = 0,0,0
print(a[0] + b[0] + c[0])
used = set()
for K in range(k - 1):
	if ba < x - 1 and (ba + 1,bb,bc) not in used:
		sam.append([a[ba + 1] + b[bb] + c[bc],ba + 1,bb,bc])
        used.add((ba + 1,bb,bc))
	if bb < y - 1 and (ba,bb + 1,bc) not in used:
		sam.append([a[ba] + b[bb + 1] + c[bc],ba,bb + 1,bc])
        used.add((ba,bb + 1,bc))
	if bc < z - 1 and (ba,bb,bc + 1) not in used:
		sam.append([a[ba] + b[bb] + c[bc + 1],ba,bb,bc + 1])
        used.add((ba,bb,bc + 1))
	big = max(sam)
	sam.remove(big)
	print(big[0])
	ba,bb,bc = big[1],big[2],big[3]

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()))
sam = []
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
ab = a[0] + b[0]
ac = a[0] + c[0]
bc = b[0] + c[0]
sam.append(a[0] + b[0] + c[0])
if len(a) > k:
	A = k
else:
	A = len(b)
if len(b) > k:
	B = k
else:
	B = len(b)
if len(c) > k:
	C = k
else:
	C = len(C)
for i in range(1,C):
	    sam.append(ab + c[K])
for i in range(1,B):
    	sam.append(ac + b[K])
for i in range(1,A):
    	sam.append(bc + a[K])
sam.sort(reverse=True)
for K in range(k):
	print(sam[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)
AnsList =[]
for h in range(K):
    for i in range(K):
        for j in range(K):
            ans = A[h] + B[i] + C[j]
            AnsList.append(ans)
            if len(AnsList) >= K:
                break
AnsList.sort(reverse = True)
for i in range(K):
    print(AnsList[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)
AnsList =[]
for h in range(K):
    for i in range(K):
        for j in range(K):
            ans = A[h] + B[i] + C[j]
            AnsList.append(ans)
            if len(AnsList) == K:
                break
AnsList.sort(reverse = True)
for i in range(K):
    print(AnsList[i])