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: Wrong Answer

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

delicious=[]

A=sorted(A,reverse=True)
B=sorted(B,reverse=True)
C=sorted(C,reverse=True)
k=int(K**(0.34))+10

for i in range(min(k,len(A))):
    for j in range(min(k,len(B))):
        for _k in range(min(k,len(C))):
            delicious.append(A[i]+B[j]+C[_k])


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

Submission status: Wrong Answer

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

delicious=[]

A=sorted(A,reverse=True)
B=sorted(B,reverse=True)
C=sorted(C,reverse=True)
k=int(K**(0.34))+10
print(k)
for i in range(min(k,len(A))):
    for j in range(min(k,len(B))):
        for _k in range(min(k,len(C))):
            delicious.append(A[i]+B[j]+C[_k])

print(delicious)

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

Submission status: Wrong Answer

Solution code:
x,y,z,q = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a = sorted(a)
b = sorted(b)
c = sorted(c)

d = (x<16) + (y<16) + (z<16)

if d == 3 or d == 2:
    la = []
    for i in range(x):
        for k in range(y):
            for m in range(z):
                la.append(a[i]+b[k]+c[m])
    la = sorted(la)

    for p in range(q):
        print(la[-p-1])

elif d == 1:
    if x<16:
        la = []
        for v in range(x):
            for i in range(min(y,100)):
                for k in range(min(z,100)):
                    la.append(a[v]+b[-i-1]+c[-k-1])
        la = sorted(la)
        for i in range(q):
            print(la[-i-1])
    if y <16:
        la = []
        for v in range(y):
            for i in range(min(x,100)):
                for k in range(min(z,100)):
                    la.append(b[v]+a[-i-1]+c[-k-1])
        la = sorted(la)
        for i in range(q):
            print(la[-i-1])
    if z<16:
        la = []
        for v in range(z):
            for i in range(min(y,100)):
                for k in range(min(x,100)):
                    la.append(c[v]+b[-i-1]+a[-k-1])
        la = sorted(la)
        for i in range(q):
            print(la[-i-1])

else:
    la  = []
    for i in range(15):
        for k in range(15):
            for m in range(15):
                la.append(a[-i-1]+b[-k-1]+c[-m-1])
    la = sorted(la)
    for i in range(q):
        print(la[-i-1])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import itertools
import sys
import math
from functools import lru_cache

# 1整数
# n = int(input())

# 空白区切り2変数
from queue import Queue
from operator import mul
from functools import reduce
from queue import Queue
from operator import mul
from functools import reduce
from functools import lru_cache

input = sys.stdin.readline

# N個整数
x, y, z, k = list(map(int, input().split()))

# 1整数
# n = int(input())

# 空白区切りリスト整数
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)
ll = [0] * 1000001
count = 0
for i in a:
    for j in b:
        ll[count] = i + j
        if ll[3001] > i + j:
            break
        count += 1

ll.sort(reverse=True)

ll = ll[0:3000]
c.sort(reverse=True)

lll = [0] * 3000001
count = 0
for i in ll:
    for j in c:
        lll[count] = i + j
        if lll[3001] > i + j:
            break
        count += 1
lll.sort(reverse=True)

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

# 空白区切り文字列
# t, d = input().split()

Submission status: Wrong Answer

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

if x*y*z<=10**7:
    res=[]
    for i in range(x):
        for j in range(y):
            for k in range(z):
                res.append(a[i]+b[j]+c[k])
    res.sort()
    for i in range(K):
        print(res[-1-i])
else:
    res=[]
    for i in range(x):
        for j in range(y):
            res.append(a[i]+b[j]+c[-1])
    for i in range(x):
        for k in range(z):
            res.append(a[i]+b[-1]+c[k])
    for j in range(y):
        for z in range(k):
            res.append(a[-1]+b[j]+c[k])
    res.sort()
    for i in range(K):
        print(res[-1-i])

Submission status: Wrong Answer

Solution code:
import sys,bisect
input = sys.stdin.readline

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

ab = []
for e in a:
    for w in b:
        ab.append(e+w)
ab.sort()

ok = -1
ng = 10**12
while abs(ok-ng)>1:
    mid = (ok+ng)//2
    cnt = 0
    for e in c:
        cnt += len(ab)-bisect.bisect_left(ab,mid-e)
    if cnt >= k:
        ok = mid
    else:
        ng = mid

res = []
for e in c:
    ind = bisect.bisect_left(ab,ok-e)
    for i in range(ind,len(ab)):
        res.append(e+ab[i])
res.sort()
for i in range(k):
    print(res[-i])

Submission status: Wrong Answer

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()
ans=[]
if min(x,y,z)>=20:
  p=20
  q=20
  r=20
elif x*y*z<=3000:
  p=x
  q=y
  r=z
else:
  p=min(x,3000)
  q=min(y,3000)
  r=min(z,3000)
for i in range(p):
  for j in range(q):
    for h in range(r):
      ans.append(a[i]+b[j]+c[h])
ans.sort()
ans.reverse()
for i in range(k):
  print(ans[i])

Submission status: Wrong Answer

Solution code:
x,y,z,q = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a = sorted(a)
b = sorted(b)
c = sorted(c)

d = (x<16) + (y<16) + (z<16)

if d == 3 or d == 2:
    la = []
    for i in range(x):
        for k in range(y):
            for m in range(z):
                la.append(a[i]+b[k]+c[m])
    la = sorted(la)

    for p in range(q):
        print(la[-p-1])

elif d == 1:
    if x<16:
        la = []
        for v in range(x):
            for i in range(15):
                for k in range(15):
                    la.append(a[v]+b[-i-1]+c[-k-1])
        la = sorted(la)
        for i in range(q):
            print(la[-i-1])
    if y <16:
        la = []
        for v in range(y):
            for i in range(15):
                for k in range(15):
                    la.append(b[v]+a[-i-1]+c[-k-1])
        la = sorted(la)
        for i in range(q):
            print(la[-i-1])
    if z<16:
        la = []
        for v in range(z):
            for i in range(15):
                for k in range(15):
                    la.append(c[v]+b[-i-1]+a[-k-1])
        la = sorted(la)
        for i in range(q):
            print(la[-i-1])

else:
    la  = []
    for i in range(15):
        for k in range(15):
            for m in range(15):
                la.append(a[-i-1]+b[-k-1]+c[-m-1])
    la = sorted(la)
    for i in range(q):
        print(la[-i-1])

Submission status: Wrong Answer

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

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

AB_list = [0]*(X*Y)
for i in range(X):
    for j in range(Y):
        AB_list[i*Y+j] = A_list[i] + B_list[j]
AB_list_s = sorted(AB_list)
if len(AB_list_s) > 3000:
    AB_list_s = AB_list_s[-3000:]
W = len(AB_list_s)
ABC_list = [0]*(W*Z)
for i in range(W):
    for j in range(Z):
        ABC_list[i*Z+j] = AB_list[i] + C_list[j]
ABC_list_s = sorted(ABC_list)
for i in range(K):
    print(ABC_list_s[-(i+1)])

Submission status: Wrong Answer

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

res = []
for a in range(min(X, 100)):
    for b in range(min(Y, 100)):
        for c in range(min(Z, 100)):
            res.append(A[-a-1] + B[-b-1] + C[-c-1])
            
res.sort(reverse=True)

for r in res:
    print(r)

Submission status: Wrong Answer

Solution code:
x,y,z,q = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a = sorted(a)
b = sorted(b)
c = sorted(c)

d = (x<16) + (y<16) + (z<16)

if d == 3 or d == 2:
    la = []
    for i in range(x):
        for k in range(y):
            for m in range(z):
                la.append(a[i]+b[k]+c[m])
    la = sorted(la)

    for p in range(q):
        print(la[-p-1])

elif d == 1:
    if x<16:
        la = []
        for v in range(x):
            for i in range(15):
                for k in range(15):
                    la.append(a[-v-1]+b[-i-1]+c[-k-1])
        la = sorted(la)
        for i in range(q):
            print(la[-i-1])
    if y <16:
        la = []
        for v in range(y):
            for i in range(15):
                for k in range(15):
                    la.append(b[-v-1]+a[-i-1]+c[-k-1])
        la = sorted(la)
        for i in range(q):
            print(la[-i-1])
    if z<16:
        la = []
        for v in range(z):
            for i in range(15):
                for k in range(15):
                    la.append(c[-v-1]+b[-i-1]+a[-k-1])
        la = sorted(la)
        for i in range(q):
            print(la[-i-1])

else:
    la  = []
    for i in range(15):
        for k in range(15):
            for m in range(15):
                la.append(a[-i-1]+b[-k-1]+c[-m-1])
    la = sorted(la)
    for i in range(q):
        print(la[-i-1])

Submission status: Wrong Answer

Solution code:
import sys,bisect
input = sys.stdin.readline

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

ab = []
for e in a:
    for w in b:
        ab.append(e+w)
ab.sort()

ok = -1
ng = 10**11
while abs(ok-ng)>1:
    mid = (ok+ng)//2
    cnt = 0
    for e in c:
        cnt += len(ab)-bisect.bisect_left(ab,mid-e)
    if cnt >= k:
        ok = mid
    else:
        ng = mid

res = []
for e in c:
    ind = bisect.bisect_left(ab,ok-e)
    for i in range(ind,len(ab)):
        res.append(e+ab[i])
res.sort()
for i in range(k-1,-1,-1):
    print(res[i])

Submission status: Wrong Answer

Solution code:
x,y,z,q = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a = sorted(a)
b = sorted(b)
c = sorted(c)

d = (x<16) + (y<16) + (z<16)

if d == 3 or d == 2:
    la = []
    for i in range(x):
        for k in range(y):
            for m in range(z):
                la.append(a[i]+b[k]+c[m])
    la = sorted(la)

    for p in range(q):
        print(la[-p-1])

elif d == 1:
    if x<16:
        la = []
        for v in range(x):
            for i in range(100):
                for k in range(100):
                    sla.append(a[-v-1]+b[-i-1]+c[-k-1])
        la = sorted(la)
        for i in range(q):
            print(la[-i-1])
    if y <16:
        la = []
        for v in range(y):
            for i in range(100):
                for k in range(100):
                    la.append(b[-v-1]+a[-i-1]+c[-k-1])
        la = sorted(la)
        for i in range(q):
            print(la[-i-1])
    if z<16:
        la = []
        for v in range(z):
            for i in range(100):
                for k in range(100):
                    la.append(c[-v-1]+b[-i-1]+a[-k-1])
        la = sorted(la)
        for i in range(q):
            print(la[-i-1])

else:
    la  = []
    for i in range(20):
        for k in range(20):
            for m in range(20):
                la.append(a[-i-1]+b[-k-1]+c[-m-1])
    la = sorted(la)
    for i in range(q):
        print(la[-i-1])

Submission status: Wrong Answer

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

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

for a in range(min(X, 100)):
    for b in range(min(Y, 100)):
        for c in range(min(Z, 100)):
            print(A[-a-1] + B[-b-1] + C[-c-1])

Submission status: Wrong Answer

Solution code:
x,y,z,q = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a = sorted(a)
b = sorted(b)
c = sorted(c)

d = (x<16) + (y<16) + (z<16)

if d == 3 or d == 2:
    la = []
    for i in range(x):
        for k in range(y):
            for m in range(z):
                la.append(a[i]+b[k]+c[m])
    la = sorted(la)

    for p in range(q):
        print(la[-p-1])

elif d == 1:
    if x<16:
        la = []
        for i in range(100):
            for k in range(100):
                la.append(a[-1]+b[-i-1]+c[-k-1])
        la = sorted(la)
        for i in range(q):
            print(la[-i-1])
    if y <16:
        la = []
        for i in range(100):
            for k in range(100):
                la.append(b[-1]+a[-i-1]+c[-k-1])
        la = sorted(la)
        for i in range(q):
            print(la[-i-1])
    if z<16:
        la = []
        for i in range(100):
            for k in range(100):
                la.append(c[-1]+b[-i-1]+a[-k-1])
        la = sorted(la)
        for i in range(q):
            print(la[-i-1])

else:
    la  = []
    for i in range(20):
        for k in range(20):
            for m in range(20):
                la.append(a[-i-1]+b[-k-1]+c[-m-1])
    la = sorted(la)
    for i in range(q):
        print(la[-i-1])

Submission status: Time Limit Exceeded

Solution code:
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())
import sys
sys.setrecursionlimit(10**6)

A,B,C,K=sep()
a=lis()
b=lis()
c=lis()
a.sort()
b.sort()
c.sort()
s=set()
ans=[]
def dfs(i,j,k):
    if i<0 or j<0 or k<0:
        return
    if (i,j,k) in s:
        return
    if len(ans)>500000:
        return
    ans.append(a[i]+b[j]+c[k])
    s.add((i,j,k))
    dfs(i-1,j,k)
    dfs(i,j-1,k)
    dfs(i,j,k-1)

dfs(A-1,B-1,C-1)
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())
import sys
sys.setrecursionlimit(10**6)

A,B,C,k=sep()
a=lis()
b=lis()
c=lis()
a.sort()
b.sort()
c.sort()
s=set()
ans=[]
def dfs(i,j,k):
    if i<0 or j<0 or k<0:
        return
    if (i,j,k) in s:
        return
    if len(ans)>1000000:
        return
    ans.append(a[i]+b[j]+c[k])
    s.add((i,j,k))
    dfs(i-1,j,k)
    dfs(i,j-1,k)
    dfs(i,j,k-1)

dfs(A-1,B-1,C-1)
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    X, Y, Z, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)

    ANS = []

    for a in A[:K]:
        for b in B[:K]:
            for c in C[:K]:
                ANS.append(a + b + c)
    
    ANS.sort(reverse=True)

    [print(ans) for ans in ANS[:K]]

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    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()))

    ANS = []

    for a in A:
        for b in B:
            for c in C:
                ANS.append(a + b + c)
    
    ANS.sort(reverse=True)

    [print(ans) for ans in ANS[:K]]

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
'''
Created on 2020/09/08

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write

  X,Y,Z,K=map(int,pin().split())
  A=list(map(int,pin().split()))
  B=list(map(int,pin().split()))
  C=list(map(int,pin().split()))
#   A.sort(reverse=True)
#   B.sort(reverse=True)
#   C.sort(reverse=True)

  d=[]
  for i in A:
    for j in B:
      d.append(i+j)
  d.sort(reverse=True)
  d=d[:K]
  ans=[]
  for k in d:
    for l in C:
      ans.append(k+l)
  ans.sort(reverse=True)
  for m in range(K):
    print(ans[m])
  return
main()

Submission status: Time Limit Exceeded

Solution code:
'''
Created on 2020/09/08

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write

  X,Y,Z,K=map(int,pin().split())
  A=list(map(int,pin().split()))
  B=list(map(int,pin().split()))
  C=list(map(int,pin().split()))
#   A.sort(reverse=True)
#   B.sort(reverse=True)
#   C.sort(reverse=True)

  d=[]
  for i in A:
    for j in B:
      d.append(i+j)
#   d.sort(reverse=True)
  ans=[]
  for k in d:
    for l in C:
      ans.append(k+l)
  ans.sort(reverse=True)
  for m in range(K):
    print(ans[m])
  return 
main()

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted(list(map(int, input().split())))[::-1]

a1 = sorted(a[i] + b[j] for i in range(x) for j in range(y))[::-1]
a2 = sorted(a1[i] + c[j] for i in range(min(len(a1), k))
            for j in range(z))[::-1]
for i in range(k):
    print(a2[i])

Submission status: Time Limit Exceeded

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 = []
AC = []
BC = []
for a in A:
    for b in B:
        AB.append(a+b)
    for c in C:
        AC.append(a+c)
for b in B:
    for c in C:
        BC.append(b+c)
AB.sort(reverse=True)
AC.sort(reverse=True)
BC.sort(reverse=True)

ABC = []
for x in AB[:K]:
    for c in C:
        ABC.append(x+c)
for x in BC[:K]:
    for a in A:
        ABC.append(x+a)
for x in AC[:K]:
    for b in B:
        ABC.append(x+b)
ABC.sort(reverse=True)
print(*ABC[::3][:K], sep='\n')

Submission status: Time Limit Exceeded

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 = list()
for a in A:
    for b in B:
        ab.append(a+b)
ab.sort(reverse=True)
C.sort(reverse=True)
abc = []
for a in ab[:k]:
    for b in C:
        abc.append(a+b)
abc.sort(reverse=True)
print(*abc[:k], sep="\n")

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k=map(int,input().split())
a=sorted(list(map(int,input().split())))[::-1]
b=sorted(list(map(int,input().split())))[::-1]
c=sorted(list(map(int,input().split())))[::-1]
d=[]
for i in a:
  for j in b:
    d+=[i+j]
ans=[]
for i in c:
  for j in sorted(d)[::-1][:k]:
    ans+=[i+j]
print(*sorted(ans)[::-1][:k],sep='\n')

Submission status: Time Limit Exceeded

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()))
tmp = []
for a in A:
    for b in B:
        tmp.append(a + b)
ans = []
for ab in tmp:
    for c in C:
        ans.append(ab + c)
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(X, Y, Z, K, As, Bs, Cs):
    ABs = []
    for A in As:
        for B in Bs:
            ABs.append(A + B)
    ABs.sort(reverse=True)
    ABCs = []
    for i in range(min(X * Y, K)):
        AB = ABs[i]
        for C in Cs:
            ABCs.append(AB + C)
    ABCs.sort(reverse=True)
    for i in range(K):
        print(ABCs[i])


if __name__ == '__main__':
    # S = input()
    # N = int(input())
    X, Y, Z, K = map(int, input().split())
    As = [int(i) for i in input().split()]
    Bs = [int(i) for i in input().split()]
    Cs = [int(i) for i in input().split()]
    # import random
    # X, Y, Z, K = 1000,1000,1000,3000
    # As = [random.randint(1, 10 ** 10) for _ in range(X)]
    # Bs = [random.randint(1, 10 ** 10) for _ in range(Y)]
    # Cs = [random.randint(1, 10 ** 10) for _ in range(Z)]
    solve(X, Y, Z, K, As, Bs, Cs)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k=map(int,input().split())

a=list(map(int,input().split()))
A=len(a)
b=list(map(int,input().split()))
B=len(b)
c=list(map(int,input().split()))
C=len(c)
S=min(A,B,C)
s=[]

for i in range(S):
    for j in range(S):
        for m in range(S):
            s.append(a[i]+b[j]+c[m])

s.sort(reverse=True)
for i in s[:k]:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k=map(int,input().split())

a=list(map(int,input().split()))
A=len(a)
b=list(map(int,input().split()))
B=len(b)
c=list(map(int,input().split()))
C=len(c)
S=max(A,B,C)
s=[]

for i in range(S):
    for j in range(S):
        for m in range(S):
            s.append(a[i]+b[j]+c[m])

s.sort(reverse=True)
for i in s[:k]:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k=map(int,input().split())

a=list(map(int,input().split()))
A=len(a)
b=list(map(int,input().split()))
B=len(b)
c=list(map(int,input().split()))
C=len(c)

s=[]

for i in range(A):
    for j in range(B):
        for m in range(C):
            s.append(a[i]+b[j]+c[m])

s.sort(reverse=True)
for i in s[:k]:
    print(i)

Submission status: Time Limit Exceeded

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

res = []
for a in A:
    for b in B:
        for c in C:
            res.append(a + b + c)

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

Submission status: Time Limit Exceeded

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    X, Y, Z, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))
    C = list(map(int, readline().split()))

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

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

    ABC = []
    for ab in AB:
        for c in C:
            ABC.append(ab + c)

    ABC.sort(reverse=True)

    print('\n'.join(map(str, ABC[:K])))

    return


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def binary_search_int(ok, ng, test, k, A, B):
    """
    :param ok: solve(x) = True を必ず満たす点
    :param ng: solve(x) = False を必ず満たす点
    """
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if test(mid, k, A, B):
            ok = mid
        else:
            ng = mid
    return ok

def get_cnt(x, A, B):
    """
    a+b<=x となるようなAの要素とBの要素の組の数 (A, Bはソート済み)
    """
    cnt = 0
    L = len(B)
    for a in A:
        cnt += L-bisect_left(B, x-a)
    return cnt

def test(x, k, A, B):
    """
    場合の数が k 個(以上)となるような最小の x を探索する関数
    a+b <= x で get_cnt(x,A,B) は同じ値を返すので、最小の x は A, Bの要素の和そのものに一致する
    """
    return get_cnt(x,A,B) >= k

###########################################################

import sys
input = sys.stdin.readline
from bisect import *

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()
B.sort()
C.sort()

P = []
for k in range(1,K+1):
    tmp = binary_search_int(0, 10**11,test, k, A, B)
    if tmp != 0:
        P.append(tmp)
Q = []
P.sort()
for k in range(1,K+1):
    Q.append(binary_search_int(1, 10**11,test, k, P, C))
print(*Q, sep="\n")

Submission status: Time Limit Exceeded

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)
list1=[]
for i in range(X):
  for j in range(Y):
      list1.append(A[i]+B[j])
list1.sort(reverse=True)
list1=list1[:K+1]
list2=[]
for i in range(min(X*Y,K)):
  for j in range(Z):
    list2.append(list1[i]+C[j])
list2.sort(reverse=True)
for i in range(K):
  print(list2[i])

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    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 a in A:
        for b in B:
            AB.append(a + b)
    AB = sorted(AB, reverse=True)[:k]

    res = []
    for ab in AB:
        for c in C:
            res.append(ab + c)
    res = sorted(res, reverse=True)[:k]
    print(*res, sep="\n")


if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=list(map(int, input().split()))

ab=[]
for i in range(x):
    for j in range(y):
        ab.append(a[i]+b[j])

if len(ab)>k:
    ab.sort(reverse=True)
    ab=ab[:k]
else:
    ab.sort(reverse=True)

ans=[]
for i in range(len(ab)):
    for j in range(z):
        ans.append(ab[i]+c[j])
ans.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import heapq

input = sys.stdin.readline


def main():
    X, Y, Z, K = map(int, input().split())
    A = list(map(lambda x: -int(x), input().split()))
    B = list(map(lambda x: -int(x), input().split()))
    C = list(map(lambda x: -int(x), input().split()))

    A.sort()
    B.sort()
    C.sort()

    p_queue = [(A[0] + B[0] + C[0], 0, 0, 0)]
    appear = [[[False for _ in range(Z)] for _ in range(Y)] for _ in range(X)]
    appear[0][0][0] = True
    ans = []
    while len(ans) < K:
        s, i_A, i_B, i_C = heapq.heappop(p_queue)
        ans.append(-s)
        if i_A < X - 1 and not appear[i_A + 1][i_B][i_C]:
            appear[i_A + 1][i_B][i_C] = True
            t = s - A[i_A] + A[i_A + 1]
            heapq.heappush(p_queue, (t, i_A + 1, i_B, i_C))
        if i_B < Y - 1 and not appear[i_A][i_B + 1][i_C]:
            appear[i_A][i_B + 1][i_C] = True
            t = s - B[i_B] + B[i_B + 1]
            heapq.heappush(p_queue, (t, i_A, i_B + 1, i_C))
        if i_C < Z - 1 and not appear[i_A][i_B][i_C + 1]:
            appear[i_A][i_B][i_C + 1] = True
            t = s - C[i_C] + C[i_C + 1]
            heapq.heappush(p_queue, (t, i_A, i_B, i_C + 1))

    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()