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 sys
input = lambda: sys.stdin.readline().rstrip()

from heapq import heappop, heappush

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_list = []
seen_list = set()
ans = []

heappush(sum_list, (-(A[0]+B[0]+C[0]), 0, 0, 0))

while sum_list:
    s, i, j, k = heappop(sum_list)
    
    ans.append(-s)

    if i+1 < len(A) and (i+1, j, k) not in seen_list:
        heappush(sum_list, (-(A[i+1]+B[j]+C[k]), i+1, j, k))
        seen_list.add((i+1, j, k))

    if j+1 < len(B) and (i, j+1, k) not in seen_list:
        heappush(sum_list, (-(A[i]+B[j+1]+C[k]), i, j+1, k))
        seen_list.add((i, j+1, k))

    if k+1 < len(C) and (i, j, k+1) not in seen_list:
        heappush(sum_list, (-(A[i]+B[j]+C[k+1]), i, j, k+1))
        seen_list.add((i, j, k+1))

for a in ans:
    print(a)

Submission status: Wrong Answer

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

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

ans=[]

for i in range(len(a)):
  for j in range(len(b)):
    if (i+1)*(j+1)>K:
      break
    for k in range(len(c)):
      if (i+1)*(j+1)*(k+1)>K:
        break
      ans.append(a[i]+b[j]+c[k])
    
ans.sort()
ans.reverse()

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

Submission status: Wrong Answer

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

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

ans=[]

for i in range(len(a)):
  for j in range(len(b)):
    for k in range(len(c)):
      if i*j*k>K:
        break
      ans.append(a[i]+b[j]+c[k])
    if i*j*k>K:
      break
  if i*j*k>K:
    break
        
    
ans.sort()
ans.reverse()

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 x in a:
	for y in b:
		ab.append(x+y)
ab.sort(reverse=True)
if len(ab)>k:
	ab=ab[:k+1]
c.sort()
l=0
r=max(ab)+max(c)+1
import bisect
while r-l>1:
	cnt=0
	mid=(l+r)//2
	for x in ab:
		cnt+=Z-bisect.bisect_left(c,mid-x)
	if cnt>=k:
		l=mid
	else:
		r=mid
ans=[]
for i in range(len(ab)):
	for j in range(bisect.bisect_left(c,l-ab[i]),Z):
		ans.append(ab[i]+c[j])
ans.sort(reverse=True)
for i in range(min(3000,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()))
ab=[]
for x in a:
	for y in b:
		ab.append(x+y)
ab.sort(reverse=True)
if len(ab)>k:
	ab=ab[:k]
c.sort()
l=0
r=max(ab)+max(c)+1
import bisect
while r-l>1:
	cnt=0
	mid=(l+r)//2
	for x in ab:
		cnt+=Z-bisect.bisect_left(c,mid-x)
	if cnt>=k-1:
		l=mid
	else:
		r=mid
ans=[]
for i in range(len(ab)):
	for j in range(bisect.bisect_left(c,l-ab[i]),Z):
		ans.append(ab[i]+c[j])
ans.sort(reverse=True)
for x in ans:
	print(x)

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 x in a:
	for y in b:
		ab.append(x+y)
ab.sort(reverse=True)
if len(ab)>k:
	ab=ab[:k+1]
c.sort()
l=0
r=max(ab)+max(c)+1
import bisect
while r-l>1:
	cnt=0
	mid=(l+r)//2
	for x in ab:
		cnt+=Z-bisect.bisect_left(c,mid-x)
	if cnt>=k:
		l=mid
	else:
		r=mid
ans=[]
for i in range(len(ab)):
	for j in range(bisect.bisect_left(c,l-ab[i]),Z):
		ans.append(ab[i]+c[j])
ans.sort(reverse=True)
for x in ans:
	print(x)

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 x in a:
	for y in b:
		ab.append(x+y)
ab.sort(reverse=True)
if len(ab)>k:
	ab=ab[:k+1]
c.sort()
l=0
r=max(ab)+max(c)+1
import bisect
while r-l>1:
	cnt=0
	mid=(l+r)//2
	for x in ab:
		cnt+=Z-bisect.bisect_left(c,mid-x)
	if cnt>=k:
		l=mid
	else:
		r=mid
ans=[]
for i in range(min(X*Y,k)):
	for j in range(bisect.bisect_left(c,l-ab[i]),Z):
		ans.append(ab[i]+c[j])
ans.sort(reverse=True)
for x in ans:
	print(x)

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 x in a:
	for y in b:
		ab.append(x+y)
c.sort()
l=0
r=3002
import bisect
while r-l>1:
	cnt=0
	mid=(l+r)//2
	for x in ab:
		cnt+=Z-bisect.bisect_left(c,mid-x)
	if cnt>=k:
		l=mid
	else:
		r=mid
ans=[]
for i in range(X*Y):
	for j in range(bisect.bisect_left(c,l-ab[i]),Z):
		ans.append(ab[i]+c[j])
ans.sort(reverse=True)
for x in ans:
	print(x)

Submission status: Wrong Answer

Solution code:
# damedatta
def binsearch(l, r, fn):
    while r - l > 1:
        m = (l + r) // 2
        if fn(m):
            l = m
        else:
            r = m
    return l
def main():
    X, Y, Z, K = map(int, input().split())
    D = sorted(map(int, input().split()), reverse=True)
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    A = sorted((i + j for i in B for j in C), reverse=True)
    def calc(x):
        t = 0
        ii = len(D) - 1
        for i in A:
            while ii >= 0 and D[ii] + i < x:
                ii -= 1
            t += ii + 1
            if t >= K:
                return True
            if ii < 0:
                return False
        return t >= K
    l = binsearch(D[-1] + A[-1], D[0] + A[0], calc)
    ii = len(D) - 1
    rl = []
    for i in A:
        while ii >= 0 and D[ii] + i < l + 1:
            ii -= 1
        if ii < 0:
            break
        rl.extend(i + j for j in D[:ii+1])
    rl.sort(reverse=True)
    rl += [l] * (K - len(rl))
    print('\n'.join(str(i) for i in rl))
main()

Submission status: Wrong Answer

Solution code:
# damedatta
def binsearch(l, r, fn):
    while r - l > 1:
        m = (l + r) // 2
        if fn(m):
            l = m
        else:
            r = m
    return l
def main():
    X, Y, Z, K = map(int, input().split())
    D = sorted(map(int, input().split()), reverse=True)
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    A = sorted((i + j for i in B for j in C), reverse=True)
    def calc(x):
        t = 0
        ii = len(D) - 1
        for i in A:
            while ii >= 0 and D[ii] + i < x:
                ii -= 1
            t += ii + 1
            if t >= K:
                return True
            else:
                return False
    l = binsearch(D[-1] + A[-1], D[0] + A[0], calc)
    ii = len(D) - 1
    rl = []
    for i in A:
        while ii >= 0 and D[ii] + i < l + 1:
            ii -= 1
        if ii < 0:
            break
        rl.extend(i + j for j in D[:ii+1])
    rl.sort(reverse=True)
    print('\n'.join(str(i) for i in rl[:K]))
main()

Submission status: Wrong Answer

Solution code:
import bisect
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()))
    m = max(X,Y,Z)
    if Y == m:
        B, A = A, B
    if Z == m:
        C, A = A, C
    D = []
    for i in B:
        for j in C:
            D.append(i+j)
    D.sort()
    r = max(A) + max(D)
    l = 0
    while l != r:
        k = (l + r) // 2
        t = 0
        for i in A:
            ii = bisect.bisect_left(D, k-i)
            t += (len(D) - ii)
            if t > K:
                l = k
                break
        else:
            r = k - 1
    rl = []
    for i in A:
        ii = bisect.bisect_left(D, k-i)
        rl.extend([w+i for w in D[ii:]])
    rl.sort(reverse=True)
    print('\n'.join(str(i) for i in rl[:K]))
main()

Submission status: Wrong Answer

Solution code:
import bisect
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()))
    D = []
    for i in B:
        for j in C:
            D.append(i+j)
    D.sort()
    r = max(A) + max(D)
    l = 0
    while l != r:
        k = (l + r) // 2
        t = 0
        for i in A:
            ii = bisect.bisect_left(D, k-i)
            t += (len(D) - ii)
            if t > K:
                l = k
                break
        else:
            r = k - 1
    rl = []
    for i in A:
        ii = bisect.bisect_left(D, k-i)
        rl.extend([w+i for w in D[ii:]])
    rl.sort(reverse=True)
    for i in rl[:K]:
        print(i)
main()

Submission status: Wrong Answer

Solution code:
import bisect
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()))
    D = []
    for i in B:
        for j in C:
            D.append(i+j)
    D.sort()
    r = max(A) + max(D)
    l = 0
    while l != r:
        k = (l + r) // 2
        t = 0
        for i in A:
            ii = bisect.bisect_left(D, k-i)
            t += (len(D) - ii)
        if t > K:
            l = k
        else:
            r = k - 1
    rl = []
    for i in A:
        ii = bisect.bisect_left(D, k-i)
        rl.extend([w+i for w in D[ii:]])
    rl.sort(reverse=True)
    for i in rl[:K]:
        print(i)
main()

Submission status: Wrong Answer

Solution code:
import bisect
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()))
    D = []
    for i in B:
        for j in C:
            D.append(i+j)
    D.sort()
    r = max(A) + max(D)
    l = 0
    while l != r:
        k = (l + r) // 2
        t = 0
        for i in A:
            ii = bisect.bisect_left(D, k-i)
            t += (len(D) - ii)
        if t > K:
            l = k
        else:
            r = k - 1
    rl = []
    for i in A:
        ii = bisect.bisect_left(D, k-i)
        rl.extend([w+i for w in D[ii:]])
    rl.sort(reverse=True)
    for i in rl:
        print(i)
main()

Submission status: Wrong Answer

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

x, y, z, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
a.sort()
b.sort()
c.sort()

x_y_list = []

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

x_y_list.sort()

import bisect
left = 0
right = 10 ** 18

import numpy as np

x_y_list_np = np.array(x_y_list, np.int64)
c_np = np.array(c, np.int64)

while right - left > 1:
    mid = (left + right) // 2
    cnt = np.searchsorted(x_y_list_np, mid - c_np).sum()
    if cnt >= x*y*z - k + 1:
        right = mid
    else:
        left = mid

up_k = right # 上からk番目

ans = []
for i in c:
    idx = bisect.bisect_right(x_y_list, up_k - i)
    for j in range(idx, len(x_y_list)):
        ans.append(i + x_y_list[j])

for i in range(k - len(ans)):
    ans.append(up_k)

ans.sort()

for i in ans[::-1]:
    print(i)

Submission status: Wrong Answer

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

x, y, z, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
a.sort()
b.sort()
c.sort()

x_y_list = []

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

x_y_list.sort()

import bisect
left = 0
right = 10 ** 10

while right - left > 1:
    mid = (left + right) // 2
    cnt = 0
    for i in c:
        cnt += bisect.bisect_right(x_y_list, mid - i)
    if cnt >= x*y*z - k + 1:
        right = mid
    else:
        left = mid

up_k = right # 上からk番目

ans = []

for i in c:
    idx = bisect.bisect_right(x_y_list, up_k - i)
    for j in range(idx, len(x_y_list)):
        ans.append(i + x_y_list[j])

for i in range(k - len(ans)):
    ans.append(up_k)

ans.sort()

for i in ans[::-1]:
    print(i)

Submission status: Wrong Answer

Solution code:
from collections import deque
x,y,z,k = map(int,input().split())
a = deque(sorted(list(map(int,input().split()))))
b = deque(sorted(list(map(int,input().split()))))
c = deque(sorted(list(map(int,input().split()))))
la = []
lb = []
lc = []
count = x+y+z
while True:
    if a:
        a_ = a[-1]
    else:
        a_ = -1
    if b:
        b_ = b[-1]
    else:
        b_ = -1
    if c:
        c_ = c[-1]
    else:
        c_ = -1
    
    if max(a_,b_,c_) == a_:
        la.append(a_)
        a.pop()
    elif max(a_,b_,c_) == b_:
        lb.append(b_)
        b.pop()
    else:
        lc.append(c_)
        c.pop()
    count -= 1
    if count == 0 or len(la)*len(lc)*len(lb) >= k+5000000:
        break
ans = []
for i in la:
    for j in lb:
        for m in lc:
            ans.append(i+j+m)

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

Submission status: Wrong Answer

Solution code:
from collections import deque
x,y,z,k = map(int,input().split())
a = deque(sorted(list(map(int,input().split()))))
b = deque(sorted(list(map(int,input().split()))))
c = deque(sorted(list(map(int,input().split()))))
la = []
lb = []
lc = []
count = x+y+z
while True:
    if a:
        a_ = a[-1]
    else:
        a_ = -1
    if b:
        b_ = b[-1]
    else:
        b_ = -1
    if c:
        c_ = c[-1]
    else:
        c_ = -1
    
    if max(a_,b_,c_) == a_:
        la.append(a_)
        a.pop()
    elif max(a_,b_,c_) == b_:
        lb.append(b_)
        b.pop()
    else:
        lc.append(c_)
        c.pop()
    count -= 1
    if count == 0 or len(la)*len(lc)*len(lb) >= k+1000000:
        break
ans = []
for i in la:
    for j in lb:
        for m in lc:
            ans.append(i+j+m)

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

Submission status: Wrong Answer

Solution code:
from collections import deque
x,y,z,k = map(int,input().split())
a = deque(sorted(list(map(int,input().split()))))
b = deque(sorted(list(map(int,input().split()))))
c = deque(sorted(list(map(int,input().split()))))
la = []
lb = []
lc = []
count = x+y+z
while True:
    if a:
        a_ = a[-1]
    else:
        a_ = -1
    if b:
        b_ = b[-1]
    else:
        b_ = -1
    if c:
        c_ = c[-1]
    else:
        c_ = -1
    
    if max(a_,b_,c_) == a_:
        la.append(a_)
        a.pop()
    elif max(a_,b_,c_) == b_:
        lb.append(b_)
        b.pop()
    else:
        lc.append(c_)
        c.pop()
    count -= 1
    if count == 0 or len(la)*len(lc)*len(lb) >= k+100000:
        break
ans = []
for i in la:
    for j in lb:
        for m in lc:
            ans.append(i+j+m)

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

Submission status: Wrong Answer

Solution code:
from collections import deque
x,y,z,k = map(int,input().split())
a = deque(sorted(list(map(int,input().split()))))
b = deque(sorted(list(map(int,input().split()))))
c = deque(sorted(list(map(int,input().split()))))
la = []
lb = []
lc = []
count = x+y+z
while True:
    if a:
        a_ = a[-1]
    else:
        a_ = -1
    if b:
        b_ = b[-1]
    else:
        b_ = -1
    if c:
        c_ = c[-1]
    else:
        c_ = -1
    
    if max(a_,b_,c_) == a_:
        la.append(a_)
        a.pop()
    elif max(a_,b_,c_) == b_:
        lb.append(b_)
        b.pop()
    else:
        lc.append(c_)
        c.pop()
    count -= 1
    if count == 0 or len(la)*len(lc)*len(lb) >= k+10000:
        break
ans = []
for i in la:
    for j in lb:
        for m in lc:
            ans.append(i+j+m)

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

Submission status: Wrong Answer

Solution code:
from collections import deque
x,y,z,k = map(int,input().split())
a = deque(sorted(list(map(int,input().split()))))
b = deque(sorted(list(map(int,input().split()))))
c = deque(sorted(list(map(int,input().split()))))
la = []
lb = []
lc = []
count = x+y+z
while True:
    if a:
        a_ = a[-1]
    else:
        a_ = -1
    if b:
        b_ = b[-1]
    else:
        b_ = -1
    if c:
        c_ = c[-1]
    else:
        c_ = -1
    
    if max(a_,b_,c_) == a_:
        la.append(a_)
        a.pop()
    elif max(a_,b_,c_) == b_:
        lb.append(b_)
        b.pop()
    else:
        lc.append(c_)
        c.pop()
    count -= 1
    if count == 0 or len(la)*len(lc)*len(lb) >= k+5000:
        break
ans = []
for i in la:
    for j in lb:
        for m in lc:
            ans.append(i+j+m)

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

Submission status: Wrong Answer

Solution code:
from collections import deque
x,y,z,k = map(int,input().split())
a = deque(sorted(list(map(int,input().split()))))
b = deque(sorted(list(map(int,input().split()))))
c = deque(sorted(list(map(int,input().split()))))
la = []
lb = []
lc = []
count = x+y+z
while True:
    if a:
        a_ = a[-1]
    else:
        a_ = -1
    if b:
        b_ = b[-1]
    else:
        b_ = -1
    if c:
        c_ = c[-1]
    else:
        c_ = -1
    
    if max(a_,b_,c_) == a_:
        la.append(a_)
        a.pop()
    elif max(a_,b_,c_) == b_:
        lb.append(b_)
        b.pop()
    else:
        lc.append(c_)
        c.pop()
    count -= 1
    if count == 0 or len(la)*len(lc)*len(lb) >= k+1000:
        break
ans = []
for i in la:
    for j in lb:
        for m in lc:
            ans.append(i+j+m)

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)

x = y = z = 0
ans = []
for x in range(X):
    for y in range(Y):
        for z in range(Z):
            if (x + 1) * (y + 1) * (z + 1) <= K:
                ans.append(A[x] + B[y] + C[z])
            else:
                break

ans.sort()
print(*ans[:K], sep='\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()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

x = y = z = 0
ans = []
for x in range(X):
    for y in range(Y):
        for z in range(Z):
            if (x + 1) * (y + 1) * (z + 1) <= K:
                ans.append(A[x] + B[y] + C[z])
            else:
                break

ans.sort()
print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
X,Y,Z,K = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse=1)
B = sorted(list(map(int,input().split())),reverse=1)
C = sorted(list(map(int,input().split())),reverse=1)
def solve(P):
    count = 0
    for i in range(X):
        for j in range(Y):
            for k in range(Z):
                if (A[i]+B[j]+C[k]) < P:
                    break
                count += 1
                if count >= K:
                    return True
    return False

maxa = A[0]+B[0]+C[0]+1
mina = 0

while maxa -mina > 1:
    mid = (maxa+mina)//2
    if solve(mid):
        mina = mid
    else:
        maxa = mid
ans = []
flag = True
count = 0
for i in range(X):
    if not flag:
        break
    for j in range(Y):
        if not flag:
            break
        for k in range(Z):
            if (A[i]+B[j]+C[k]) < mina:
                break
            ans.append(A[i]+B[j]+C[k])
            count += 1
            if count >= K:
                flag = False
                break
ans.sort(reverse=1)
for i in range(K):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
X,Y,Z,K = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse=1)
B = sorted(list(map(int,input().split())),reverse=1)
C = sorted(list(map(int,input().split())),reverse=1)
def solve(P):
    count = 0
    for i in range(X):
        for j in range(Y):
            for k in range(Z):
                if (A[i]+B[j]+C[k]) < P:
                    break
                count += 1
                if count >= K:
                    return True
    return False

maxa = A[0]+B[0]+C[0]+1
mina = 0

while maxa -mina > 1:
    mid = (maxa+mina)//2
    if solve(mid):
        mina = mid
    else:
        maxa = mid
ans = []
flag = True
count = 0
for i in range(X):
    if not flag:
        break
    for j in range(Y):
        if not flag:
            break
        for k in range(Z):
            if (A[i]+B[j]+C[k]) < mina:
                break
            ans.append(A[i]+B[j]+C[k])
            count += 1
            if count >= K:
                flag = False
                break
ans.sort(reverse=1)
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
import heapq
X,Y,Z,K = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse=1)
B = sorted(list(map(int,input().split())),reverse=1)
C = sorted(list(map(int,input().split())),reverse=1)
Q = [(-A[0]-B[0]-C[0],0,0,0)]
heapq.heapify(Q)
for i in range(K):
    n,a,b,c = heapq.heappop(Q)
    if a < X-1:
        heapq.heappush(Q,(n+A[a]-A[a+1],a+1,b,c))
    if b < Y-1:
        heapq.heappush(Q,(n+B[b]-B[b+1],a,b+1,c))
    if c < Z-1:
        heapq.heappush(Q,(n+C[c]-C[c+1],a,b,c+1))
    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()))
a.sort(reverse=True);b.sort(reverse=True);c.sort(reverse=True)
ng = 10**12
ok = 0
def check(chk):
    cnt=0
    for i in range(x):
        for j in range(y):
            for k in range(z):
                if a[i]+b[j]+c[k]<chk:
                    break
                cnt+=1
                if cnt>K:
                    return True
    return False
while ng-ok>1:
    if check((ok+ng)//2):ok=(ok+ng)//2
    else:ng=(ok+ng)//2
cnt=0
l=[]
for i in range(x):
        for j in range(y):
            for k in range(z):
                if a[i]+b[j]+c[k]<=ok:
                    break
                l.append(a[i]+b[j]+c[k])
l.sort(reverse=True)
for i in l:print(i)

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_left,bisect_right,insort
input = sys.stdin.readline

def main():
    x,y,z,K=map(int,input().split())
    a=sorted(list(map(int,input().split())))
    b=sorted(list(map(int,input().split())))
    c=sorted(list(map(int,input().split())))
    l,r=a[0]+b[0]+c[0],a[-1]+b[-1]+c[-1]
    while l+1<r:
        ans=0
        m=(l+r)//2
        for i in range(x-1,-1,-1):
            if a[i]>=m:
                ans+=y*z
                continue
            for j in range(y-1,-1,-1):
                if a[i]+b[j]>=m:
                    ans+=z
                    continue
                for k in range(z-1,-1,-1):
                    if a[i]+b[j]+c[k]>=m:
                        ans+=1
                        continue
                    else:
                        break
        if ans>=K:
            l=m
        else:
            r=m
    s=[0]
    for i in range(x-1,-1,-1):
        for j in range(y-1,-1,-1):
            for k in range(z-1,-1,-1):
                if a[i]+b[j]+c[k]>=l:
                    s.append(a[i]+b[j]+c[k])
                    continue
                else:
                    break
    s.sort()
    for i in range(len(s)-1,0,-1):
        print(s[i])

if __name__ == '__main__':
    main()

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

ab = [i + j for i in a for j in b]
ab.sort(reverse=True)
ab = ab[:k]

abc = [i + j for i in ab for j in b]

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

Submission status: Wrong Answer

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

ax.sort(reverse=True)
by.sort(reverse=True)
cz.sort(reverse=True)

ans = []
for a in ax[:min(x, 100)]:
    for b in by[:(min(y, 100))]:
        for c in cz[:min(z, 100)]:
            ans.append(a + b + c)

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())
ax = list(map(int, input().split()))
by = list(map(int, input().split()))
cz = list(map(int, input().split()))

ax.sort(reverse=True)
by.sort(reverse=True)
cz.sort(reverse=True)

ans = []
for a in ax[:min(x, 31)]:
    for b in by[:(min(y, 31))]:
        for c in cz[:min(z, 31)]:
            ans.append(a + b + c)

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

Submission status: Wrong Answer

Solution code:
def binsearch(l, r, fn):
    while r - l > 1:
        m = (l + r) // 2
        if fn(m):
            l = m
        else:
            r = m
    return l

def main():
    X, Y, Z, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = sorted(map(int, input().split()), reverse=True)
    AB = sorted((a + b for a in A for b in B), reverse=True)
    def helper(x):
        r = 0
        t = len(C) - 1
        for ab in AB:
            while t >= 0 and C[t] + ab < x:
                t -= 1
            r += t + 1
            if r >= K:
                return True
            if t < 0:
                return False
        return r >= K
    l = binsearch(AB[-1] + C[-1], AB[0] + C[0] + 1, helper)
    r = []
    t = len(C) - 1
    for ab in AB:
        while t >= 0 and C[t] + ab < l:
            t -= 1
        if t < 0:
            break
        r.extend(ab + c for c in C[:t + 1])
        if len(r) >= K:
            break
    r.sort(reverse=True)
    r = r[:K]
    print('\n'.join(str(i) for i in r))

main()

Submission status: Wrong Answer

Solution code:
def binsearch(l, r, fn):
    while r - l > 1:
        m = (l + r) // 2
        if fn(m):
            l = m
        else:
            r = m
    return l

def main():
    X, Y, Z, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = sorted(map(int, input().split()), reverse=True)
    AB = sorted((a + b for a in A for b in B), reverse=True)
    def helper(x):
        r = 0
        t = len(C) - 1
        for ab in AB:
            while t >= 0 and C[t] + ab < x:
                t -= 1
            r += t + 1
        return r >= K
    l = binsearch(AB[-1] + C[-1], AB[0] + C[0] + 1, helper)
    r = []
    for ab in AB:
        for c in C:
            if ab + c < l:
                break
            r.append(ab + c)
            if len(r) == K:
                break
        if len(r) >= K:
            break
    r = r[:K]
    r.sort(reverse=True)
    print('\n'.join(str(i) for i in r))

main()

Submission status: Wrong Answer

Solution code:
def binsearch(l, r, fn):
    while r - l > 1:
        m = (l + r) // 2
        if fn(m):
            l = m
        else:
            r = m
    return l

def main():
    X, Y, Z, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = sorted(map(int, input().split()), reverse=True)
    AB = sorted((a + b for a in A for b in B), reverse=True)
    def helper(x):
        r = 0
        t = len(C) - 1
        for ab in AB:
            while t >= 0 and C[t] + ab < x:
                t -= 1
            r += t + 1
            if r >= K:
                return True
            if t < 0:
                return False
        return r >= K
    l = binsearch(AB[-1] + C[-1], AB[0] + C[0] + 1, helper)
    r = []
    t = len(C) - 1
    for ab in AB:
        while t >= 0 and C[t] + ab < l:
            t -= 1
        if t < 0:
            break
        r.extend(ab + c for c in C[:t + 1])
        if len(r) >= K:
            break
    r = r[:K]
    r.sort(reverse=True)
    print('\n'.join(str(i) for i in r))

main()