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:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr  6 20:40:01 2019

@author: Yamazaki Kenichi
"""

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()
a,b,c = [],[],[]
for i in range(X):
    a.append(A[-1] - A[-i-1])
for i in range(Y):
    b.append(B[-1] - B[-i-1])
for i in range(Z):
    c.append(C[-1] - C[-i-1])
a.append(10**11)
b.append(10**11)
c.append(10**11)
s1,s2,s3,tmp = 1,1,1,min(a[0],b[0],c[0])
while s1*s2*s3 < K:
    if a[s1] - tmp < b[s2] - tmp and a[s1] - tmp < c[s3] - tmp:
        s1 += 1
    if b[s2] - tmp < c[s3] - tmp:
        s2 += 1
    else:
        s3 += 1
ans = []
for i in range(s1):
    for j in range(s2):
        for k in range(s3):
            ans.append(A[-i-1]+B[-j-1]+C[-k-1])
ans.sort()
for i in range(K):
    print(ans[-i-1])

Submission status: Wrong Answer

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

aa = list(map(int,input().split()))
aa.sort(reverse = True)
bb = list(map(int,input().split()))
bb.sort(reverse = True)
cc = list(map(int,input().split()))
cc.sort(reverse = True)
al = []
aal = []
for i in aa:
    for j in bb:
        al.append(i+j)
al.sort()
if len(al) > k:
    al[len(al)-k:]

for i in al:
    for j in cc:
        aal.append(i+j)
aal.sort()

if len(aal) > k:
    aal[len(aal)-k:]
aal.reverse()
for i in aal:
    print(i)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import product
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 = list(product(a, b, c))
print(d)
e = [x+y+z for x, y, z in d]
e.sort(reverse=True)
for i in e[:K]:
  print(i)

Submission status: Wrong Answer

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

l = [0,0,0]
res = []

da = [a[0]-a[i+1] for i in range(n[0]-1)]
db = [b[0]-b[i+1] for i in range(n[1]-1)]
dc = [c[0]-c[i+1] for i in range(n[2]-1)]
da.append(30000000000)
db.append(30000000000)
dc.append(30000000000)
a.append(-30000000000)
b.append(-30000000000)
c.append(-30000000000)

for i in range(n[3]):
    if da[l[0]] <= min(db[l[1]],dc[l[2]]):
        l[0] = l[0] + 1
    elif db[l[1]] <= dc[l[2]]:
        l[1] = l[1] + 1
    else:
        l[2] = l[2] + 1
    if (l[0] + 1) * (l[1] + 1) + (l[2] + 1) >= n[3]:
        break
        
for i0 in range(l[0]+1):
    for i1 in range(l[1]+1):
        for i2 in range(l[2]+1):
            res.append(a[i0]+b[i1]+c[i2])

res = sorted(res,reverse=True)

for i in range(n[3]):
    print(res[i])

Submission status: Wrong Answer

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

l = [0,0,0]
res = []

da = [a[0]-a[i+1] for i in range(n[0]-1)]
db = [b[0]-b[i+1] for i in range(n[1]-1)]
dc = [c[0]-c[i+1] for i in range(n[2]-1)]
da.append(10000000000)
db.append(10000000000)
dc.append(10000000000)
a.append(-10000000000)
b.append(-10000000000)
c.append(-10000000000)

for i in range(n[3]):
    if (l[0] + 1) * (l[1] + 1) + (l[2] + 1) >= n[3]:
        break
    if da[l[0]] <= min(db[l[1]],dc[l[2]]):
        l[0] = l[0] + 1
    elif db[l[1]] <= dc[l[2]]:
        l[1] = l[1] + 1
    else:
        l[2] = l[2] + 1
        
for i0 in range(l[0]+1):
    for i1 in range(l[1]+1):
        for i2 in range(l[2]+1):
            res.append(a[i0]+b[i1]+c[i2])

res = sorted(res,reverse=True)

for i in range(n[3]):
    print(res[i])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
input = sys.stdin.readline

# bisect_left(lists, 3)
# bisect_right(lists, 3)

def main():
	X, Y, Z, K = map(int, input().split(" "))
	As = []
	Bs = []
	Cs = []
	As = input().split()
	As = [int(s) for s in As]
	Bs = input().split()
	Bs = [int(s) for s in Bs]
	Cs = input().split()
	Cs = [int(s) for s in Cs]

	As.sort(reverse=True)
	Bs.sort(reverse=True)
	Cs.sort(reverse=True)

	As = As[:15]
	Bs = Bs[:15]
	Cs = Cs[:15]

	ans = []
	for i, val in enumerate(As):
		for j, vol in enumerate(Bs):
			for k, ogi in enumerate(Cs):
				ans.append(val+vol+ogi)

	ans.sort(reverse=True)
	for i in range(K):
		print(ans[i])
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=list(map(int,(input().split(" "))))
teast=[]
K = N[3]
total=[]
all=[]
c=0
for i in range(3):
    teast.append(list(map(int,input().split(" "))))

for i in teast[0]:
    for j in teast[1]:
        total.append(i+j)

total_s = sorted(total,reverse=True)

del total_s[K:]

for i in total_s:
    for k in teast[2]:
        all.append(i+k)
all_s=sorted(all,reverse=True)

for i in all_s:
    print(i)

Submission status: Wrong Answer

Solution code:
# 2019/04/06
# AtCoder Beginner Contest 123 - D

# Input
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.append(0)
b.append(0)
c.append(0)

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

aidx = 0
bidx = 0
cidx = 0

wa = list()
wb = list()
wc = list()

wflg = True
loopend = min(3000, x*y*z)

while(wflg):
    if a[aidx] > b[bidx]:
        if a[aidx] > c[cidx]:
            wa.append(a[aidx])
            aidx += 1
        else:
            if b[bidx] > c[cidx]:
                wb.append(b[bidx])
                bidx += 1
            else:
                wc.append(c[cidx])
                cidx += 1
    else:
        if b[bidx] > c[cidx]:
            wb.append(b[bidx])
            bidx += 1
        else:
            if c[cidx] > 0:
                wc.append(c[cidx])
                cidx += 1
            else:
                wflg = False
    wval = aidx * bidx * cidx
    if wval > loopend:
        wflg = False

delival = list()

for i in range(len(wa)):
    for j in range(len(wb)):
        for l in range(len(wc)):
            delival.append(wa[i]+wb[j]+wc[l])

ansl = sorted(delival, reverse=True)

sum = 0
for i in range(k):
    print(ansl[i])

Submission status: Wrong Answer

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

l = [0,0,0]
res = []

da = [a[0]-a[i+1] for i in range(n[0]-1)]
db = [b[0]-b[i+1] for i in range(n[1]-1)]
dc = [c[0]-c[i+1] for i in range(n[2]-1)]
da.append(10000000000)
db.append(10000000000)
dc.append(10000000000)
a.append(0)
b.append(0)
c.append(0)

for i in range(n[3]):
    if (l[0] + 1) * (l[1] + 1) + (l[2] + 1) >= n[3]:
        break

    if da[l[0]] <= min(db[l[1]],dc[l[2]]):
        l[0] = l[0] + 1
    elif db[l[1]] <= dc[l[2]]:
        l[1] = l[1] + 1
    else:
        l[2] = l[2] + 1

for i0 in range(l[0]+1):
    for i1 in range(l[1]+1):
        for i2 in range(l[2]+1):
            res.append(a[i0]+b[i1]+c[i2])

res = sorted(res,reverse=True)

for i in range(n[3]):
    print(res[i])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

e = []

for i in x:
  for j in y:
    e.append(i+j)

f = []

for i in e:
  for j in z:
    f.append(i+j)

f.sort()

for i in range(k[3]):
  print(f[(k[3]-i-1)])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import math

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

cnum = []

takadaka = math.ceil(103)

for i in range(min(takadaka,x)):
    for j in range(min(takadaka,y)):
        for l in range(min(takadaka,z)):
            cnum.append(a[i] + b[j] + c[l])

cnum.sort()
cnum.reverse()

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

Submission status: Wrong Answer

Solution code:
if __name__=="__main__":
    import sys
    import heapq
    readline = sys.stdin.readline
    X,Y,Z,K = map(int, readline().split())
    a = sorted(list(map(int, readline().split())), reverse=True)
    b = sorted(list(map(int, readline().split())), reverse=True)
    c = sorted(list(map(int, readline().split())), reverse=True)

    sums = []
    lower = a[min(X-1,14)]+b[min(Y-1,14)]+c[min(Z-1,14)]
    b_max,c_max = max(b),max(c)
    for i in range(X):
        if a[i]+b_max+c_max<lower:
            break
        for j in range(Y):
            if a[i]+b[j]+c_max<lower:
                break
            for k in range(Z):
                s = a[i]+b[j]+c[k]
                if s<lower:
                    break
                heapq.heappush(sums, s)
    for si in sums[:K]:
        print(si)

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 = sorted(a)
b = sorted(b)
c = sorted(c)

la = []

for i in range(x):
    s = 3000-i
    for n in range(max(y-5-3000//s,0),y):
        u = 3000-n
        for m in range(max(z-5-3000//(s*u),0),z):
            la.append(a[i]+b[n]+c[m])

la = sorted(la)

for i in range(k):
    print(la[-i-1])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

Comb = []
for i in range(X):
    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
            Comb.append(A[i] + B[j] + C[k])

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

Submission status: Wrong Answer

Solution code:
import bisect

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)
sum_AB = []
k = 0
for x in range(X):
    for y in range(Y):
        sum_AB.append(A[x]+B[y])
sum_AB.sort(reverse=True) #10**6
sum_count = []
for z in range(Z):
    if z>500:
        break
    for xy in range(min(X*Y,K)):
        sum_count.append(C[z]+sum_AB[xy])


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

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a = IR(5)
    k = II()
    if max(a) - min(a) > k:
        print(":(")
    else:
        print("Yay!")
    return

#B
def B():
    a = IR(5)
    b = a[0]
    ans = 0
    for a_ in a:
        if a_ % 10 != 0:
            if b % 10> a_ % 10:
                b = a_
    flg = 0
    for a_ in a:
        if a_ != b or flg:
            ans += math.ceil(a_ / 10) * 10
        else:
            ans += b
            flg = 1
    print(ans)
            
    
    return

#C
def C():
    n = II()
    ai = IR(5)
    print(math.ceil(n / min(ai)) + 4)
        
        
    return

#D
def D():
    x, y, z, K = LI()
    a = LI()
    a.sort(reverse=True)
    b = LI()
    b.sort(reverse = True)
    c = LI()
    c.sort(reverse=True)
    ab = []
    for a_ in a:
        for b_ in b:
            ab.append(a_ + b_)
    ab.sort(reverse = True)
    ab = ab[:min(x + y, K)]
    ans = []
    for ab_ in ab:
        for c_ in c:
            ans.append(ab_ + c_)
    ans.sort(reverse = True)
    for k in range(K):
        print(ans[k])



        
                    

    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Wrong Answer

Solution code:
import bisect

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)
sum_AB = []
k = 0
for x in range(X):
    for y in range(Y):
        sum_AB.append(A[x]+B[y])
sum_AB.sort(reverse=True) #10**6
sum_count = []
for z in range(Z):
    if z>5:
        break
    for xy in range(min(X*Y,K)):
        sum_count.append(C[z]+sum_AB[xy])


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

Submission status: Wrong Answer

Solution code:
from itertools import product
import sys
input = sys.stdin.readline

X, Y, Z, K = map(int, input().split())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]
A = sorted(A)[::-1]
B = sorted(B)[::-1]
C = sorted(C)[::-1]

List = [-1]*(X*Y)
Listcnt = 0
for i, j in product(A, B):
    List[Listcnt] = i+j
    Listcnt += 1

List = sorted(List)[-1:-K-1:-1]
ans = [-1]*(len(List)*Z)
anscnt = 0
for i, j in product(List, C):
    ans[anscnt] = i+j
    anscnt += 1
ans = sorted(ans)[-1:-K-1:-1]

print(ans)

Submission status: Wrong Answer

Solution code:
x, y, z, k = map(int, input().split())
m = []
for _ in range(3):
    m.append(sorted(list(map(int, input().split())), reverse=True))

def sorted_sum(list_a, list_b, limit):
    s = []
    for x in list_a:
        for y in list_b:
            s.append(x + y)
    return sorted(s[0:limit], reverse=True)


def consume_diff(s, a_val, list_b, b_index):
    diff = a_val - list_b[b_index]
    for i in range(b_index + 1, len(list_b)):
        if list_b[b_index] - list_b[i] > diff:
            break
        s.append(a_val + list_b[i])



ans = sorted_sum(sorted_sum(m[0], m[1], k), m[2], k)
for i in range(min([k, len(ans)])):
    print(ans[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 = sorted(a)
b = sorted(b)
c = sorted(c)

la = []

for i in range(x):
    for n in range(max(y-3000//(i+1),0),y):
        for m in range(max(z-3000//((i+1)*(n+1)),0),z):
            la.append(a[i]+b[n]+c[m])

la = sorted(la)

for i in range(k):
    print(la[-i-1])

Submission status: Wrong Answer

Solution code:
import operator

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)


di = {}

for i, (a, b, c) in enumerate(zip(a_, b_, c_)):
    di['a{}'.format(i)] = a
    di['b{}'.format(i)] = b
    di['c{}'.format(i)] = c

if len(di) > 3000:
    di = sorted(di.items(), reverse=True, key=operator.itemgetter(1))
    di = di[:3000]


a_li = []
b_li = []
c_li = []

for key, value in di.items():
    if 'a' in key:
        a_li.append(value)
    elif 'b' in key:
        b_li.append(value)
    elif 'c' in key:
        c_li.append(value)

ans = []
for a in a_li:
    for b in b_li:
        for c in c_li:
            ans.append(a+b+c)

ans.sort(reverse=True)

if len(ans) > 3000:
    for count, i in enumerate(ans):
        print(i)
        if count==2999:
            break
else:
    for count, i in enumerate(ans):
        print(i)

Submission status: Wrong Answer

Solution code:
x,y,z,k=map(int,input().split())
a=tuple(map(int,input().split()))
b=tuple(map(int,input().split()))
c=tuple(map(int,input().split()))
 
def f(p,q):
    return [i+j for j in q for i in p][:k]
 
if x+y<y+z:
    for i in sorted(f(c,f(a,b)))[::-1][:k]:
        print(i)
elif x+z<y+z:
    for i in sorted(f(b,f(a,c)))[::-1][:k]:
        print(i)
else:
    for i in sorted(f(a,f(b,c)))[::-1][:k]:
        print(i)

Submission status: Wrong Answer

Solution code:
X,Y,Z,K = (int(i) for i in input().split())
A = input().split()
listA = [int(a) for a in A]
B = input().split()
listB = [int(b) for b in B]
C = input().split()
listC = [int(c) for c in C]

listA = sorted(listA,reverse = True)
listB = sorted(listB,reverse = True)
listC = sorted(listC,reverse = True)
kouholist = [[listA[0] + listB[0] + listC[0] ,0,0,0]]
for i in range(K):
    kouholist.sort()
    kouholist.reverse()
    print(kouholist[0][0])
    if kouholist[0][1] < X - 1:
        kouholist.append([listA[kouholist[0][1] + 1] + listB[kouholist[0][2]] + listC[kouholist[0][3]],kouholist[0][1] + 1,kouholist[0][2],kouholist[0][3]])
    if kouholist[0][2] < Y - 1:
        kouholist.append([listA[kouholist[0][1]] + listB[kouholist[0][2] + 1] + listC[kouholist[0][3]],kouholist[0][1],kouholist[0][2] + 1,kouholist[0][3]])
       
    if kouholist[0][3] < Z - 1:
        
        kouholist.append([listA[kouholist[0][1]] + listB[kouholist[0][2]] + listC[kouholist[0][3] + 1],kouholist[0][1],kouholist[0][2],kouholist[0][3] + 1])
    kouholist.pop(0)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left as bi
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]
for i in sorted([j+i for j in c for i in sorted([i+j for i in a for j in b])[::-1][:k]])[::-1]:
    print(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()))

e = []
for a_i in a:
    for b_j in b:
        e.append(a_i + b_j)
e = sorted(e, reverse=True)

ans = []
for e_i in e[:k+1]:
    for c_j in c:
        ans.append(e_i + c_j)

ans.sort(reverse=True)
print(ans[:k])

Submission status: Wrong Answer

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_a.sort(reverse = True)  
l_b.sort(reverse = True)  
l_c.sort(reverse = True)
l_d = [a + b for a in l_a for b in l_b]
l_d.sort(reverse = True)
l_d[:3000]
l_e = [ab + c for ab in l_d for c in l_c]
l_e.sort(reverse = True)
l_e[:K]
for i in l_e:
    print(i)

Submission status: Wrong Answer

Solution code:
import copy
inf = float("INF")
x,y,z,k=map(int,input().split())
dp=[0]*3000
l =[]
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
for i in a:
  for j in b:
    l.append(i+j)
l.sort()
t =[]
for i in l[:k]:
  for j in c:
    t.append(i+j)
t.sort()
t = t[::-1]
for i ,n in enumerate(t):
  print(n)
  if i == k-1:break

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import functools
import operator
import itertools
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)

a = 0
b = 0
c = 0

cnt = 0
#print(A, B, C)
memo = defaultdict(lambda: False)
cand = []
while True:
#   print(cand)
#   print(a, b, c)
    summ = A[a] + B[b] + C[c]
    print(summ)
#   print("")
    cnt += 1
    if cnt == K:
        break
    else:
        if memo["{}{}{}".format(a+1, b, c)] is False and a+1 < len(A):
            cand.append([a+1, b, c])
            memo["{}{}{}".format(a+1, b, c)] = True
        if memo["{}{}{}".format(a, b+1, c)] is False and b+1 < len(B):
            cand.append([a, b+1, c])
            memo["{}{}{}".format(a, b+1, c)] = True
        if memo["{}{}{}".format(a, b, c+1)] is False and c+1 < len(C):
            cand.append([a, b, c+1])
            memo["{}{}{}".format(a, b, c+1)] = True

        min_x = None
        min_x_index = None
        max_summ = 0
        for i, x in enumerate(cand):
            cand_summ = A[x[0]] + B[x[1]] + C[x[2]]
#           print(i, cand_summ)
            if max_summ < cand_summ:
                min_x = x
                min_x_index = i
                max_summ = cand_summ
    a = min_x[0]
    b = min_x[1]
    c = min_x[2]
    cand.pop(min_x_index)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-

def solve():
    """ TLE """
    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(" ")))

    ans = []

    for x in range(X):
        for y in range(Y):
            ab = A[x] + B[y]
            for z in range(Z):
                if (x+1)*(y+1)*(z+1) > K:
                    break

                ans.append(ab + C[z])

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


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
import numpy as np
# N = int(stdin.readline().rstrip().split()[0])
# A = [int(x) for x in stdin.readline().rstrip().split()]
# N, X = [int(x) for x in stdin.readline().rstrip().split()]
# S = [int(x) for x in stdin.readline().rstrip().split()]
X, Y, Z, K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]
B = [int(x) for x in stdin.readline().rstrip().split()]
C = [int(x) for x in stdin.readline().rstrip().split()]
K = min([K, X*Y*Z])
A.sort()
B.sort()
C.sort()
A.reverse()
B.reverse()
C.reverse()
A.append(-10**9)
B.append(-10**9)
C.append(-10**9)
A.append(-10**10)
B.append(-10**10)
C.append(-10**10)

Max = A[0]+B[0]+C[0]
a, b, c = 0, 0, 0
memo = {}
memo[(a,b,c)] = Max
for i in range(K):
  key, Max = max(memo.items(), key=lambda x: x[1])
  print(Max)
  del memo[key]
  a,b,c=key
  memo[(a+1,b,c)] = A[a+1]+B[b]+C[c]
  memo[(a,b+1,c)] = A[a]+B[b+1]+C[c]
  memo[(a,b,c+1)] = A[a]+B[b]+C[c+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()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

kouho = set()
done = set()


def f(t):
    x, y, z = t
    return A[x] + B[y] + C[z]


def main():
    kouho.add((f((0, 0, 0)), (0, 0, 0)))

    for k in range(K):
        d = max(kouho)
        kouho.remove(d)

        x, y, z = d[1]
        toadd = [(x, y, z+1), (x, y+1, z), (x+1, y, z)]
        for ta in toadd:
            if ta[0] == X:
                continue
            if ta[1] == Y:
                continue
            if ta[2] == Z:
                continue
            kouho.add((f(ta), ta))

        print(d[0])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# D
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)
a_l = []
a_max = a[0]
for i in range(len(a)):
    a_l.append(a[i] - a_max)
b_l = []
b_max = b[0]
for i in range(len(b)):
    b_l.append(b[i] - b_max)
c_l = []
c_max = c[0]
for i in range(len(c)):
    c_l.append(c[i] - c_max)
a_count = 1
b_count = 1
c_count = 1
while a_count * b_count * c_count < k:
    l = []
    if a_count < len(a):
        l.append(a_l[a_count])
    if b_count < len(b):
        l.append(b_l[b_count])
    if c_count < len(c):
        l.append(c_l[c_count])
    l.sort()
    for m in l:
        if a_count < len(a) and m == a_l[a_count]:
            a_count += 1
            break
        elif b_count < len(b) and m == b_l[b_count]:
            b_count += 1
            break
        elif c_count < len(c) and m == c_l[c_count]:
            c_count += 1
            break

a = a[:a_count+1]
b = b[:b_count+1]
c = c[:c_count+1]

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

Submission status: Wrong Answer

Solution code:
from itertools import product
import sys
input = sys.stdin.readline

X, Y, Z, K = map(int, input().split())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]
A = sorted(A)[::-1]
B = sorted(B)[::-1]
C = sorted(C)[::-1]

List = []
for i, j in product(A, B):
    List.append(i+j)

List = sorted(List)[-1:-K-1:-1]
ans = []

for i, j in product(List, C):
    ans.append(i+j)
ans = sorted(ans)[::-1]

print(ans[:K])

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-

def solve():
    """ TLE """
    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(" ")))

    ans = []

    for x in range(X):
        for y in range(Y):
            ab = A[x] + B[y]
            for z in range(Z):
                if (x+1)*(y+1)*(z+1) > K:
                    break

                abc = ab + C[z]
                
                if len(ans) < K-1:
                    ans.append(abc)
                    continue
                elif len(ans) == K-1:
                    ans.append(abc)
                    ans.sort(reverse=True)
                    continue
                
                if abc > ans[-1]:
                    ans[-1] = abc
                    ans.sort(reverse=True)
                    continue

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


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import sys,bisect
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()))
SumABC = []
for i in A:
  for j in B:
    for k in C:
      s = i+j+k
      if len(SumABC) < K:
        bisect.insort(SumABC,s)
      if len(SumABC) == K and SumABC[K-1] < s:
        bisect.insort(SumABC,s)
        SumABC.pop(0)
SumABC.reverse()
for i in SumABC:
	print(i)