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:
import itertools
X, Y, Z, K = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse = True)[:200]
B = sorted([int(i) for i in input().split()], reverse = True)[:200]
C = sorted([int(i) for i in input().split()], reverse = True)[:200]

D = []
cnt = 0
for a, b, c in itertools.product(A, B, C):
    d = a + b + c
    D.append(d)
    cnt += 1
    if cnt == 3000000:
        break
    
D.sort(reverse = True)
for d in D[:K]:
    print(d)

Submission status: Wrong Answer

Solution code:
import itertools
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)

ABC = [A,B,C]

comb = 0
idx = [0,0,0]
while comb < K:
    tmp_list = []
    for j in range(3):
        if idx[j] + 1 >= len(ABC[j]):
            tmp_list.append(-1)
        else:
            tmp_list.append(ABC[j][idx[j]+1])

    m = max(tmp_list)

    i = tmp_list.index(m)

    idx[i] += 1
    tmp_comb = 1
    for j in idx:
        tmp_comb *= j+1
    comb = tmp_comb

seq = list(itertools.product(A[:idx[0]+1],B[:idx[1]+1],C[:idx[2]+1]))
ans = [sum(s) for s in seq]

ans = sorted(ans,reverse=True)
for a in ans[:K]:
    print(a)

Submission status: Wrong Answer

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

from heapq import heappush, heappop
def io_generator():
	return input()

#+++++++++++++++++++
	
class Foo(object):
	def __init__(self, value, state):
		self.state = state
		self.value = value

	def __lt__(self, other):
		return self.value > other.value

def get_c(aa,ab,ac, amm):
	if ac < amm[2]-1:
		ret=[[aa,ab,ac+1]]
	else:
		ret=[]
		
	if ab<amm[1]-1 and ab >= ac:
		ret.append([aa,ab+1,ac])
	
	if aa<amm[0]-1 and aa >= ab and aa >= ac:
		ret.append([aa+1,ab,ac])
	return ret
	
def gv(al,bl,cl,s):
	return al[s[0]]+bl[s[1]]+cl[s[2]]
	

def main(io):
	x,y,z,k=map(int, io().split())
	ml=[x,y,z]
	al =list(map(int, io().split()))
	al.sort(reverse=True)
	bl =list(map(int, io().split()))
	bl.sort(reverse=True)
	cl =list(map(int, io().split()))
	cl.sort(reverse=True)
	init=[0,0,0]
	ggv=lambda l : gv(al,bl,cl,l)
	
	qq = []
	heappush(qq,Foo(ggv(init), init))
	
	for _ in range(k):
		ff=heappop(qq)
		vv=ff.value
		cs=ff.state
		nc=get_c(cs[0],cs[1],cs[2],ml)
		print(vv)
		for ns in nc:
			heappush(qq, Foo(ggv(ns), ns))
	return 1

#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	#print (main(io))
	main(io)

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 xy in range(X*Y):
    if xy>2250:
        break
    for z in range(Z):
        sum_count.append(sum_AB[xy]+C[z])

sum_count.sort(reverse=True)
for i in range(K):
    print(sum_count[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()]
a=a[:min(k,len(a))]
b=b[:min(k,len(b))]
c=c[:min(k,len(c))]
d=[]
ans=[]
for i in a:
    for j in b:
        d.append(i+j)
d=d[:min(k,len(d))]
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:
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+=[a[i]+b[j]]
ab.sort(key=lambda x: -x)
c.sort(key=lambda x: -x)
ans=[]
ct=[0]
ansc=[ab[0]+c[0]]
while (len(ans)<k):
    if(ct[-1]!=0 and len(ct)<z):
        ansc+=[ab[0]+c[len(ct)]]
        ct+=[0]
    ans+=[max(ansc)]
    tmp=ansc.index(max(ansc))
    if(ct[tmp]==len(ab)-1):
        ansc[tmp]==0
    else:
        ct[tmp]+=1
        ansc[tmp]=ab[ct[tmp]]+c[tmp]
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
def int_raw():
    return int(input())


def ss_raw():
    return raw_input().split()


def ints_raw():
    return list(map(int, ss_raw()))


def diff_array(array):
    return [array[i + 1] - array[i] for i in xrange(len(array) - 1)]


X, Y, Z, K = ints_raw()
A = ints_raw()
sorted_A = sorted(A, reverse=True)
B = ints_raw()
sorted_B = sorted(B, reverse=True)
C = ints_raw()
sorted_C = sorted(C, reverse=True)

current_A = 0
current_B = 0
current_C = 0


def diff(array, index):
    if len(array) <= index:
        return 10000000000
    return array[0] - array[index]


while (current_A + 1) * (current_B + 1) * (current_C + 1) < K:
    a = diff(sorted_A, current_A + 1)
    b = diff(sorted_B, current_B + 1)
    c = diff(sorted_C, current_C + 1)
    if a <= b and a <= c and current_A < X - 1:
        current_A += 1
        continue
    if b <= c and b <= a and current_B < Y - 1:
        current_B += 1
        continue
    if c <= a and c <= b and current_C < Z - 1:
        current_C += 1
        continue

result = []
for i in xrange(current_A + 35):
    for j in xrange(current_B + 35):
        for k in xrange(current_C + 35):
            result.append(sorted_A[min(i, X - 1)] + sorted_B[min(j, Y - 1)] + sorted_C[min(k, Z - 1)])

sorted_result = sorted(result, reverse=True)
for i in xrange(K):
    print(sorted_result[i])

Submission status: Wrong Answer

Solution code:
X, Y, Z, K = list(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()))

A_list.sort(reverse=True)
B_list.sort(reverse=True)
C_list.sort(reverse=True)

class Value():
  def __init__(self, A_list, B_list, C_list, a_idx, b_idx, c_idx):
    self.A = A_list[a_idx]
    self.B = B_list[b_idx]
    self.C = C_list[c_idx]
    self.a_idx = a_idx
    self.b_idx = b_idx
    self.c_idx = c_idx
    self.value = self.A + self.B + self.C
  def __eq__(self, other):
    return self.a_idx == other.a_idx and self.b_idx == other.b_idx and self.c_idx == other.c_idx
  def __gt__(self, other):
    return self.value > other.value
  def __ge__(self, other):
    return self.value >= other.value
    
que = []
que.append(Value(A_list, B_list, C_list, 0, 0, 0))

for _ in range(K):
  if que:
    v = que.pop(0)
    print(v.value)
  new_v_list = []
  if v.a_idx < X - 1:
    new_v = Value(A_list, B_list, C_list, v.a_idx + 1, v.b_idx, v.c_idx)
    if not new_v in que: 
      que.append(new_v)
  if v.b_idx < Y - 1:
    new_v = Value(A_list, B_list, C_list, v.a_idx, v.b_idx + 1, v.c_idx)
    if not new_v in que:
      que.append(new_v)
  if v.c_idx < Z - 1:
    new_v = Value(A_list, B_list, C_list, v.a_idx, v.b_idx, v.c_idx + 1)
    if not new_v in que:
      que.append(new_v)
  que.sort(key=lambda x: x.value, reverse=True)
  que = que[:len(que)//2+1]

Submission status: Wrong Answer

Solution code:
x, y, z, k = map(int, input().split())
a = []
b = []
c = []
li = input().rstrip().split()
for i in li:
    a.append(int(i))
li = input().rstrip().split()
for i in li:
    b.append(int(i))
li = input().rstrip().split()
for i in li:
    c.append(int(i))
ans = []
for i in range(x):
  for j in range(y):
    for l in range(z):
      ans.append(a[i]+b[j]+c[l])
print(ans)      
ans.sort()
ans.reverse()     
for i in range(k):
  print(ans[i])

Submission status: Wrong Answer

Solution code:
from sys import stdin

def 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 = sorted(A, reverse=1)[:15]
    b = sorted(B, reverse=1)[:15]
    c = sorted(C, reverse=1)[:15]

    ans = []
    for a_ in a:
        for b_ in b:
            for c_ in c:
                ans.append(a_ + b_ + c_)
    ans.sort(reverse=1)
    print(*ans[:K], sep='\n')

input = lambda: stdin.readline()
main()

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)

if x * y * z <= 3000:
    ans = []
    for ai in a:
        for bi in b:
            for ci in c:
                ans.append(ai + bi + ci)
    ans.sort(reverse=True)
    for i in range(k):
        print(ans[i])
else:
    ia = 0
    ib = 0
    ic = 0
    len_a = len(a)
    len_b = len(b)
    len_c = len(c)

    while (ia+1) * (ib+1) * (ic+1) < 3000:
        if ia + 1 == len_a:
            diff_a = float('inf')
        else:
            diff_a = a[0] - a[ia+1]
        if ib + 1 == len_b:
            diff_b = float('inf')
        else:
            diff_b = b[0] - b[ib+1]
        if ic + 1 == len_c:
            diff_c = float('inf')
        else:
            diff_c = c[0] - c[ic+1]

        if diff_a <= diff_b and diff_a <= diff_c:
            ia += 1
        if diff_b <= diff_a and diff_b <= diff_c:
            ib += 1
        if diff_c <= diff_a and diff_c <= diff_b:
            ic += 1

    if ia+1 == x:
        a = a[:ia+1]
    else:
        a = a[:ia+2]
    if ib+1 == y:
        b = b[:ib+1]
    else:
        b = b[:ib+2]
    if ic == z:
        c = c[:ic+1]
    else:
        c = c[:ic+2]

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

l1 = len(a) * len(b)
s1 = [0] * l1
ans1 = [0] * k

i = 0
for A in a:
    for B in b:
        s1[i] = A + B
        i += 1
s1.sort(reverse=True)

j = 0
cnt = 0
f = False

while True:
    for i in range(l1):
        ans1[cnt] = s1[i] + c[j]
        cnt += 1
        if cnt >= k:
            f = True
            break
    if f:
        break
    j += 1


l2 = len(b) * len(c)
s2 = [0] * l2
ans2 = [0] * k

i = 0
for C in c:
    for B in b:
        s2[i] = C + B
        i += 1
s2.sort(reverse=True)

j = 0
cnt = 0
f = False

while True:
    for i in range(l2):
        ans2[cnt] = s2[i] + a[j]
        cnt += 1
        if cnt >= k:
            f = True
            break
    if f:
        break
    j += 1


l3 = len(c) * len(a)
s3 = [0] * l3
ans3 = [0] * k

i = 0
for C in c:
    for A in a:
        s3[i] = C + A
        i += 1
s3.sort(reverse=True)

j = 0
cnt = 0
f = False

while True:
    for i in range(l3):
        ans3[cnt] = s3[i] + b[j]
        cnt += 1
        if cnt >= k:
            f = True
            break
    if f:
        break
    j += 1


ans1.sort(reverse=True)
ans2.sort(reverse=True)
ans3.sort(reverse=True)

if ans1[-1] >= ans2[-1] and ans1[-1] >= ans3[-1]:
    ans = ans1
elif ans2[-1] >= ans1[-1] and ans2[-1] >= ans3[-1]:
    ans = ans2
else:
    ans = ans3

for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
import itertools
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 = sorted(a,reverse = True)
b_sort = sorted(b,reverse = True)
c_sort = sorted(c,reverse = True)

x = 0
y = 0
z = 0
x_next = 0
y_next = 0
z_next = 0
index_list = []
for i in range(K):
	index_list.append([x,y,z])
	print(a_sort[x]+b_sort[y]+c_sort[z])
	del_new = 0
	
	if x+1 != X:
		for ynew in range(y+1):
			for znew in range(z+1):
				if [x+1,ynew,znew] not in index_list:
					hoge = a_sort[x+1]+b_sort[ynew]+c_sort[znew]
					if hoge > del_new:
						del_new = hoge
						x_next = x+1
						y_next = ynew
						z_next = znew
	if y+1 != Y:
		for xnew in range(x+1):
			for znew in range(z+1):
				if [xnew,y+1,znew] not in index_list:
					hoge = a_sort[xnew]+b_sort[y+1]+c_sort[znew]
					if hoge > del_new:
						del_new = hoge
						x_next = xnew
						y_next = y+1
						z_next = znew
	if z+1 != Z:
		for ynew in range(y+1):
			for xnew in range(x+1):
				if [xnew,ynew,z+1] not in index_list:
					hoge = a_sort[xnew]+b_sort[ynew]+c_sort[z+1]
					if hoge > del_new:
						del_new = hoge
						x_next = xnew
						y_next = ynew
						z_next = z+1
	x = x_next
	y = y_next
	z = z_next

Submission status: Wrong Answer

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

D = []
cnt = 0
for a, b, c in itertools.product(A, B, C):
    d = a + b + c
    D.append(d)
    cnt += 1
    if cnt == 2000000:
        break
    
D.sort(reverse = True)
for d in D[:K]:
    print(d)

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(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
nA = A[0]
nB = B[0]
nC = C[0]
a, b, c = [], [], []
for i in A:
    a.append(nA-i)
for i in B:
    b.append(nB-i)
for i in C:
    c.append(nC-i)
ls = []
d, e, f = 0, 0, 0
while d*e*f < K:
    if d+1 == len(a):
        a.append(float('inf'))
        d += 1
    if e+1 == len(b):
        b.append(float('inf'))
        e += 1
    if f+1 == len(c):
        c.append(float('inf'))
        f += 1
    if min(a[d], b[e], c[f]) == a[d]:
        d += 1
    elif min(a[d], b[e], c[f]) == b[e]:
        e += 1
    elif min(a[d], b[e], c[f]) == c[f]:
        f += 1
for i in a[:d+2]:
    for j in b[:e+2]:
        for k in c[:f+2]:
            ls.append(i+j+k)
ls.sort()
for i in range(K):
    print(nA+nB+nC-ls[i])

Submission status: Wrong Answer

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

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

ia,ib,ic = 0,0,0
_min_ = 10000000000001
for ida,a in enumerate(A) :
    for idb,b in enumerate(B):
        idc = int(K/(ida+1)/(idb+1)) -1
        if  idc < len(C) and a+b+C[idc] < _min_:
            _min_ = a+b+C[idc]
            ia,ib,ic = ida,idb,idc

import itertools
#print(list(itertools.product(A[:s_a], B[:s_b],C[:s_c])))
for idx,value in enumerate(sorted([sum(i) for i in  list(itertools.product(A[:ia], B[:ib],C[:ic]))])[::-1]):
    if idx > K-1:
        break
    print(value)

Submission status: Wrong Answer

Solution code:
def int_raw():
    return int(input())


def ss_raw():
    return raw_input().split()


def ints_raw():
    return list(map(int, ss_raw()))


def diff_array(array):
    return [array[i + 1] - array[i] for i in xrange(len(array) - 1)]


X, Y, Z, K = ints_raw()
A = ints_raw()
sorted_A = sorted(A, reverse=True)
B = ints_raw()
sorted_B = sorted(B, reverse=True)
C = ints_raw()
sorted_C = sorted(C, reverse=True)

current_A = 0
current_B = 0
current_C = 0


def diff(array, index):
    if len(array) <= index:
        return 10000000000
    return array[0] - array[index]


while (current_A + 1) * (current_B + 1) * (current_C + 1) < K:
    a = diff(sorted_A, current_A + 1)
    b = diff(sorted_B, current_B + 1)
    c = diff(sorted_C, current_C + 1)
    if a <= b and a <= c and current_A < X - 1:
        current_A += 1
        continue
    if b <= c and b <= a and current_B < Y - 1:
        current_B += 1
        continue
    if c <= a and c <= b and current_C < Z - 1:
        current_C += 1
        continue

result = []
for i in xrange(current_A + 5):
    for j in xrange(current_B + 5):
        for k in xrange(current_C + 5):
            result.append(sorted_A[min(i, X - 1)] + sorted_B[min(j, Y - 1)] + sorted_C[min(k, Z - 1)])

sorted_result = sorted(result, reverse=True)
for i in xrange(K):
    print(sorted_result[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 xy in range(X*Y):
    if xy>2000:
        break
    for z in range(Z):
        sum_count.append(sum_AB[xy]+C[z])

sum_count.sort(reverse=True)
for i in range(K):
    print(sum_count[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(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

if x * y * z <= 3000:
    ans = []
    for ai in a:
        for bi in b:
            for ci in c:
                ans.append(ai + bi + ci)
    ans.sort(reverse=True)
    for i in range(k):
        print(ans[i])
else:
    ia = 0
    ib = 0
    ic = 0
    len_a = len(a)
    len_b = len(b)
    len_c = len(c)

    while (ia+1) * (ib+1) * (ic+1) < 3000:
        if ia + 1 == len_a:
            diff_a = float('inf')
        else:
            diff_a = a[ia] - a[ia+1]
        if ib + 1 == len_b:
            diff_b = float('inf')
        else:
            diff_b = b[ib] - b[ib+1]
        if ic + 1 == len_c:
            diff_c = float('inf')
        else:
            diff_c = c[ic] - c[ic+1]

        if diff_a <= diff_b and diff_a <= diff_c:
            ia += 1
        if diff_b <= diff_a and diff_b <= diff_c:
            ib += 1
        if diff_c <= diff_a and diff_c <= diff_b:
            ic += 1
    
    if ia+1 == x:
        a = a[:ia+1]
    else:
        a = a[:ia+2]
    if ib+1 == y:
        b = b[:ib+1]
    else:
        b = b[:ib+2]
    if ic == z:
        c = c[:ic+1]
    else:
        c = c[:ic+2]

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import os
import itertools
from math import *
import numpy as np

x,y,z,k = [int(i) for i in input().split(' ')]
#print(x,y,z,k)
    
xi = [int(i) for i in input().split()]
yi = [int(i) for i in input().split()]
zi = [int(i) for i in input().split()]

xi.sort(reverse=True)
yi.sort(reverse=True)
zi.sort(reverse=True)

xi = xi[:k]
yi = yi[:k]
zi = zi[:k]

nlist = []
for n in list(itertools.product(xi, yi, zi)):
    nlist.append(n[0] + n[1] + n[2])

nlist_np = np.array(nlist)
print(nlist_np)

a = np.argpartition(-nlist_np, k-1)

for i in range(k):
    print(nlist_np[a[i]])

Submission status: Wrong Answer

Solution code:
X, Y, X, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = []

AA = sorted(A, key=lambda a: -a)
BB = sorted(B, key=lambda a: -a)
CC = sorted(C, key=lambda a: -a)
if K > 100:
    for a in AA[::int(K**1/3+3)]:
        for b in BB[::int(K**1/3+3)]:
            for c in CC[::int(K**1/3+3)]:
                ans.append(a+b+c)
else:
    for a in AA:
        for b in BB:
            for c in CC:
                ans.append(a+b+c)

for an in sorted(ans, key=lambda p: -p)[:K]:
    print(an)

Submission status: Wrong Answer

Solution code:
import pprint
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()]

yum = []
check = 0
for i in range(x):
    if check == 1:
        break
    for j in range(y):
        if check == 1:
            break
        for k in range(x):
            yum.append(a[i] + b[j] + c[k])
            if i + j + k > K:
                check = 1
                break
            
yum = sorted(yum,reverse=True)

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

Submission status: Wrong Answer

Solution code:
import itertools

X, Y, Z, K = [int(x) for x in 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)

list_ = [a+b for (a,b) in itertools.product(A, B)]
list_.sort(reverse=True)

list__ = [ab+c for (ab,c) in itertools.product(list_[:10000], C)]
for N in list__[:K]:
  print(N)

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()))
ab=[]
for i in range(x):
    for j in range(y):
        ab+=[a[i]+b[j]]
ab.sort(key=lambda x: -x)
c.sort(key=lambda x: -x)
ans=[]
ct=[0]
ansc=[ab[0]+c[0]]
while (len(ans)<k):
    if(ct[-1]!=0 and len(ct)<z):
        ansc+=[ab[0]+c[len(ct)]]
        ct+=[0]
    ans+=[max(ansc)]
    tmp=ansc.index(max(ansc))
    if(ct[tmp]==len(ab)-1):
        ansc[tmp]==100000000000
    else:
        ct[tmp]+=1
        ansc[tmp]=ab[ct[tmp]]+c[tmp]
for i in ans:
    print(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()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
nA = A[0]
nB = B[0]
nC = C[0]
a, b, c = [], [], []
for i in A:
    a.append(nA-i)
for i in B:
    b.append(nB-i)
for i in C:
    c.append(nC-i)
ls = []
d, e, f = 0, 0, 0
while d*e*f < K:
    if d+1 == len(a):
        a.append(float('inf'))
        d += 1
    if e+1 == len(b):
        b.append(float('inf'))
        e += 1
    if f+1 == len(c):
        c.append(float('inf'))
        f += 1
    if min(a[d], b[e], c[f]) == a[d]:
        d += 1
    elif min(a[d], b[e], c[f]) == b[e]:
        e += 1
    elif min(a[d], b[e], c[f]) == c[f]:
        f += 1
for i in a[:d+1]:
    for j in b[:e+1]:
        for k in c[:f+1]:
            ls.append(i+j+k)
ls.sort()
for i in range(K):
    print(nA+nB+nC-ls[i])

Submission status: Wrong Answer

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

D = []
cnt = 0
for a, b, c in itertools.product(A, B, C):
    d = a + b + c
    D.append(d)
    cnt += 1
    if cnt == 1000000:
        break
    
D.sort(reverse = True)
for d in D[:K]:
    print(d)

Submission status: Wrong Answer

Solution code:
x,y,z,l = map(int,input().split())
A = [0]*10+list(map(int,input().split()))
B = [0]*10+list(map(int,input().split()))
C = [0]*10+list(map(int,input().split()))
A = sorted(A,reverse=True)
B = sorted(B,reverse=True)
C = sorted(C,reverse=True)
print(A[0]+B[0]+C[0])

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, 3000)]
    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:
from heapq import heappop, heappush

X, Y, Z, K = [int(s) for s in input().split()]
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
a, b, c = 1, 1, 1
while a * b  < K or a * c < K or b * c < K:
    da = A[a-1] - A[a] if X > a else float('Inf')
    db = B[b-1] - B[b] if Y > b else float('Inf')
    dc = C[c-1] - C[c] if Z > c else float('Inf')
    if da <= db and da <= dc:
        a += 1
    elif db <= da and db <= dc:
        b += 1
    else:
        c += 1
print(a, b, c)
h = []
for i in range(a):
    for j in range(b):
        for k in range(c):
            heappush(h, -(A[i] + B[j] + C[k]))
for _ in range(K):
    print(-heappop(h))

Submission status: Wrong Answer

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

from heapq import heappush, heappop
def io_generator():
	return input()

#+++++++++++++++++++
	
class Foo(object):
	def __init__(self, value, state):
		self.state = state
		self.value = value

	def __lt__(self, other):
		return self.value >= other.value

def get_c(aa,ab,ac, amm):
	if ac < amm[2]-1:
		ret=[[aa,ab,ac+1]]
	else:
		ret=[]
		
	if ab<amm[1]-1 and ab >= ac:
		ret.append([aa,ab+1,ac])
	
	if aa<amm[0]-1 and aa >= ab and aa >= ac:
		ret.append([aa+1,ab,ac])
	return ret
	
def gv(al,bl,cl,s):
	return al[s[0]]+bl[s[1]]+cl[s[2]]
	

def main(io):
	x,y,z,k=map(int, io().split())
	ml=[x,y,z]
	al =list(map(int, io().split()))
	al.sort(reverse=True)
	bl =list(map(int, io().split()))
	bl.sort(reverse=True)
	cl =list(map(int, io().split()))
	cl.sort(reverse=True)
	init=[0,0,0]
	ggv=lambda l : gv(al,bl,cl,l)
	
	qq = []
	heappush(qq,Foo(ggv(init), init))
	
	for _ in range(k):
		ff=heappop(qq)
		vv=ff.value
		cs=ff.state
		nc=get_c(cs[0],cs[1],cs[2],ml)
		print(vv)
		for ns in nc:
			heappush(qq, Foo(ggv(ns), ns))
	return 1

#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	#print (main(io))
	main(io)

Submission status: Wrong Answer

Solution code:
def ii2ss(n):
    ss = []
    for i in range(n):
        ss.append(input())
    return ss

def sp2nn(sp, sep=' '):
    return [int(s) for s in sp.split(sep)]

def ss2nn(ss):
    return [int(s) for s in list(ss)]

def tk(i, j, k):
    return '%d %d %d' % (i, j, k)

def tkr(key):
    return sp2nn(key)

def main(ss):
    X, Y, Z, K = sp2nn(ss[0])
    aa = sp2nn(ss[1])
    bb = sp2nn(ss[2])
    cc = sp2nn(ss[3])
    aa.sort()
    aa.reverse()
    bb.sort()
    bb.reverse()
    cc.sort()
    cc.reverse()
    
    d = {}
    d[tk(0, 0, 0)] = aa[0] + bb[0] + cc[0]
    for _ in range(K):
        vmax = -1
        vk = ''
        for k, v in d.items():
            if vmax < v:
                vmax = v
                vk = k
        print(vmax)
        d.pop(vk)
        i, j, k = tkr(vk)
        if i + 1 < len(aa):
            d[tk(i+1, j, k)] = aa[i+1] + bb[j] + cc[k]
        if j + 1 < len(bb):
            d[tk(i, j+1, k)] = aa[i] + bb[j+1] + cc[k]
        if k + 1 < len(cc):
            d[tk(i, j, k+1)] = aa[i] + bb[j] + cc[k+1]
        
main(ii2ss(4))