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:
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 < K:
                break
            r.append(ab + c)
        if len(r) >= K:
            break
    r.sort(reverse=True)
    print('\n'.join(str(i) for i in r))

main()

Submission status: Wrong Answer

Solution code:
import sys,heapq
def input():
    return sys.stdin.readline()[:-1]
X,Y,Z,K=map(int,input().split())
A=list(map(lambda x:int(x)*-1,input().split()))
B=list(map(lambda x:int(x)*-1,input().split()))
C=list(map(lambda x:int(x)*-1,input().split()))
h=[]
heapq.heapify(h)
for i in A:
    for j in B:
        heapq.heappush(h,i+j)
m=min(K,len(h))
l=[None]*m
for i in range(m):
    l[i]=heapq.heappop(h)
print(l)
h=[]
heapq.heapify(h)
for i in l:
    for j in C:
        heapq.heappush(h,i+j)
for i in range(K):
    print(heapq.heappop(h)*-1)

Submission status: Wrong Answer

Solution code:
def solve(k,ax,bx,cx):
    ab = []
    for a in ax:
        for b in bx:
            ab.append(a+b)

    ab.sort(reverse=True)
    abk = ab[:k]

    ans = []
    for c in cx:
        for abi in abk:
            ans.append(c+abi)

    return sorted(ans[:k], reverse=True)

if __name__ == '__main__':
    _,_,_,k = map(int, input().split())
    ax = list(map(int,input().split()))
    bx = list(map(int,input().split()))
    cx = list(map(int,input().split()))
    ans = solve(k,ax,bx,cx)
    for a in ans:
        print(a)

Submission status: Wrong Answer

Solution code:
import itertools
L=[]
num=0
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
for a1,b1,c1 in itertools.product(a,b,c):
    num=a1+b1+c1
    L.append(num)
L=sorted(list(set(L)))[::-1]
for i in range(k):
    print(L[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()))

result = []

for x in range(X):
  for y in range(Y):
    if x * y > K:
      break
    for z in range(Z):
      if x * y * z > K:
        break
      result.append(A[x] + B[y] + C[z])

for k in list(sorted(result, reverse=True)):
  print(k)

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

result = []

for a in A:
  for b in B:
    for c in C:
      result.append(a+b+c)

for k in list(sorted(result, reverse=True)):
  print(k)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
def input(): return sys.stdin.readline().rstrip()

def main():
    X, Y, Z, K = map(int, input().split())
    A, B, C = [sorted(map(int, input().split()), reverse=True) for _ in range(3)]

    hp = []
    heapq.heappush(hp, (- A[0] - B[0] - C[0], 0, 0, 0))
    exists = set([(0, 0, 0)])
    for _ in range(K):
        v, x, y, z = heapq.heappop(hp)
        print(-v)
        if x + 1 < X and (x + 1, y, z) not in exists:
            heapq.heappush(hp, (v + A[x] - A[x+1], x + 1, x, z))
        if y + 1 < Y and (x, y + 1, z) not in exists:
            heapq.heappush(hp, (v + B[y] - B[y+1], x, y + 1, z))
        if z + 1 < Z and (x, y, z + 1) not in exists:
            heapq.heappush(hp, (v + C[z] - C[z+1], x, y, z + 1))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    X, Y, Z, K = map(int, input().split())
    A, B, C = [sorted(map(int, input().split())) for _ in range(3)]

    AB = []
    for i, a in enumerate(A):
        for j, b in enumerate(B):
            AB.append(a + b)
    AB = sorted(AB, reverse=True)[:K]

    ans = []
    for i, ab in enumerate(AB):
        for j, c in enumerate(C):
            ans.append(ab + c)
    ans = sorted(ans, reverse=True)[:K]
    print(ans)
    for i in ans:
        print(i)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    X, Y, Z, K = map(int, input().split())
    A, B, C = [sorted(map(int, input().split())) for _ in range(3)]

    AB = []
    for i, a in enumerate(A):
        for j, b in enumerate(B):
            AB.append(a + b)
    
    ans = []
    for i, ab in enumerate(AB[:K]):
        for j, c in enumerate(C):
            ans.append(ab + c)
    ans = sorted(ans, reverse=True)[:K]
    for i in ans:
        print(i)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# 想定解法3

import heapq

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

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)


Q =[]
heapq.heappush(Q, [-(A[0]+B[0]+C[0]), 0, 0, 0])
added_idx = set((0, 0, 0))

for i in range(K):
  nega_ans, x, y, z = heapq.heappop(Q)
  print(-nega_ans)
  if x+1 < X and (x+1, y, z) not in added_idx:
    heapq.heappush(Q, [-(A[x+1]+B[y]+C[z]), x+1, y, z])
  if y+1 < Y and (x, y+1, z) not in added_idx:
    heapq.heappush(Q, [-(A[x]+B[y+1]+C[z]), x, y+1, z])
  if z+1 < Z and (x, y, z+1) not in added_idx:
    heapq.heappush(Q, [-(A[x]+B[y]+C[z+1]), x, y, z+1])

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)

YZ = Y*Z
BC = []
for b in B:
  for c in C:
    BC.append(b+c)

BC.sort()

def check(S):
  count = 0
  left = X*Y*Z
  for a in A:
    count += YZ - bisect.bisect_left(BC, S-a)
    left -= YZ
    if count >= K or count+left < K:
      break
  
  return count >= K


Sl = 0
Sr = A[0]+B[0]+C[-1]+1

while Sr - Sl > 1:
  mid = (Sl + Sr) // 2
  if check(mid):
    Sl = mid
  else:
    Sr = mid

Ans = []
for a in A:
  for b in B:
    if a + b + C[0] < Sl:
      break
    for c in C:
      if a + b + c >= Sl:
        Ans.append(a+b+c)
      else:
        break

Ans.sort(reverse=True)
for ans in Ans:
  print(ans)

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)

YZ = Y*Z
BC = []
for b in B:
  for c in C:
    BC.append(b+c)

BC.sort()

def check(S):
  count = 0
  left = X*Y*Z
  for a in A:
    count += YZ - bisect.bisect_left(BC, S-a)
    left -= YZ
    if count >= K or count+left < K:
      break
  
  return count >= K


Sl = 0
Sr = A[0]+B[0]+C[-1]+1

while Sr - Sl > 1:
  mid = (Sl + Sr) // 2
  if check(mid):
    Sl = mid
  else:
    Sr = mid

C = C[::-1]
Ans = []
for a in A:
  for b in B:
    if a + b + C[0] < Sl:
      break
    for c in C:
      if a + b + c >= Sl:
        Ans.append(a+b+c)
      else:
        break

Ans.sort(reverse=True)
for ans in Ans:
  print(ans)

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

def check(S):
  count = 0
  left = X*Y*Z
  for a in A:
    for b in B:
      count += Z - bisect.bisect_left(C, S - a - b)
      left -= Z
      if count >= K:
        break
      
      if count + left < K:
        break
    
    else:
      continue 
    break 
  return count >= K


Sl = 0
Sr = A[0]+B[0]+C[-1]+1

while Sr - Sl > 1:
  mid = (Sl + Sr) // 2
  if check(mid):
    Sl = mid
  else:
    Sr = mid

C = C[::-1]
Ans = []
for a in A:
  for b in B:
    if a + b + C[0] < Sl:
      break
    for c in C:
      if a + b + c >= Sl:
        Ans.append(a+b+c)
      else:
        break

Ans.sort(reverse=True)
for ans in Ans:
  print(ans)

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

def check(S):
  count = 0
  for a in A:
    for b in B:
      count += Z - bisect.bisect_left(C, S - a - b)
      if count >= K:
        break
    
    else:
      continue 
    break 
  return count >= K


Sl = 0
Sr = A[0]+B[0]+C[-1]+1

while Sr - Sl > 1:
  mid = (Sl + Sr) // 2
  if check(mid):
    Sl = mid
  else:
    Sr = mid

C = C[::-1]
Ans = []
for a in A:
  for b in B:
    if a + b + C[0] < Sl:
      break
    for c in C:
      if a + b + c >= Sl:
        Ans.append(a+b+c)
      else:
        break

Ans.sort(reverse=True)
for ans in Ans:
  print(ans)

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 = [a + b for a in A for b in B]
AB.sort()
AB.reverse()
print(AB)
ABC = [ab + c for ab in AB for c in C]
ABC.sort()
ABC.reverse()
for k in range(K):
    print(ABC[k])

Submission status: Wrong Answer

Solution code:
import heapq
x, y, z, k = map(int, input().split())
n = [x, y, z]
if x*y*z < k:
    k = x*y*z

abc = []
for _ in range(3):
    *l, = sorted(map(int, input().split()), reverse=True)
    abc.append(l)

h = [[-(abc[0][0]+abc[1][0]+abc[2][0]), [0, 0, 0]]]
heapq.heapify(h)

index = [0, 0, 0]
se = h[:]

for _ in range(k):
    if len(h) <= 0: break

    ans, iterate = heapq.heappop(h)
    print(-ans)

    for i in range(3):
        if n[i] <= iterate[i] + 1: continue

        iterate[i] += 1

        s = -(abc[0][iterate[0]]+abc[1][iterate[1]]+abc[2][iterate[2]])
        t = [s, iterate[:]]

        if t not in se:
            heapq.heappush(h, t)
            se.append(t)

        iterate[i] -= 1

Submission status: Wrong Answer

Solution code:
import heapq
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=sorted([int(i) for i in input().split()],reverse=True)
ab=[]
for i in range(x):
    for j in range(y):
        ab.append(a[i]+b[j])
ab.sort(reverse=True)
ab=ab[:k]
l=len(ab)
abc=[]
for i in range(l):
    for j in range(z):
        heapq.heappush(abc,ab[i]+c[j])
for i in range(k):
    print(heapq.heappop(abc))

Submission status: Wrong Answer

Solution code:
def num():
    return int(input())
def nums():
    return list(map(int,input().split()))

X,Y,Z,K = nums()
A = nums()
B = nums()
C = nums()

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

AB = [bi + ai for bi in B for ai in A]
res = []
for ab_sum in AB[:K]:
    for ci in C[:K]:
        res.append(ab_sum + ci)
res.sort(reverse=True)
for ans in res[:K]:
    print(ans)

Submission status: Wrong Answer

Solution code:
MAX = 200

n1, n2, n3, kth = map(int, input().split())
a1 = sorted(map(int, input().split()), reverse=True)[:MAX]
a2 = sorted(map(int, input().split()), reverse=True)[:MAX]
a3 = sorted(map(int, input().split()), reverse=True)[:MAX]

ret = [a1[i] + a2[j] + a3[k] for i in range(len(a1)) for j in range(len(a2)) for k in range(len(a3))]
ret.sort(reverse=True)
print('\n'.join(map(str, ret[:kth])))

Submission status: Wrong Answer

Solution code:
MAX = 100

n1, n2, n3, kth = map(int, input().split())
a1 = sorted(map(int, input().split()), reverse=True)[:MAX]
a2 = sorted(map(int, input().split()), reverse=True)[:MAX]
a3 = sorted(map(int, input().split()), reverse=True)[:MAX]

ret = [a1[i] + a2[j] + a3[k] for i in range(len(a1)) for j in range(len(a2)) for k in range(len(a3))]
ret.sort(reverse=True)
print('\n'.join(map(str, ret[:kth])))

Submission status: Wrong Answer

Solution code:
MAX = 15

n1, n2, n3, kth = map(int, input().split())
a1 = sorted(map(int, input().split()), reverse=True)[:15]
a2 = sorted(map(int, input().split()), reverse=True)[:15]
a3 = sorted(map(int, input().split()), reverse=True)[:15]

ret = [a1[i] + a2[j] + a3[k] for i in range(min(MAX, n1)) for j in range(min(MAX, n2)) for k in range(min(MAX, n3))]
ret.sort(reverse=True)
print('\n'.join(map(str, ret[:kth])))

Submission status: Wrong Answer

Solution code:
from heapq import heappop, heappush
x, y, z, K = map(int, input().split())
cak = []
cak.append(sorted(list(map(int, input().split())), reverse=True))
cak.append(sorted(list(map(int, input().split())), reverse=True))
cak.append(sorted(list(map(int, input().split())), reverse=True))

def branch(p):
    cnt = 0
    for i in range(x):
        for j in range(y):
            for k in range(z):
                if cak[0][i]+cak[1][j]+cak[2][k] < p:
                    break
                cnt += 1
                if cnt >= K:
                    return True
    return False

lft = -1; rgt = cak[0][0]+cak[1][0]+cak[2][0]+1
while rgt-lft > 1:
    mid = (rgt+lft)//2
    if branch(mid):
        lft = mid
    else:
        rgt = mid

ans = []
cnt = 0
for i in range(x):
    for j in range(y):
        for k in range(z):
            dlc = cak[0][i]+cak[1][j]+cak[2][k]
            if dlc >= lft and cnt < K:
                cnt += 1
                ans.append(dlc)
            else:
                break
ans.sort(reverse=True)
for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:
from heapq import heappop, heappush
x, y, z, K = map(int, input().split())
cak = []
cak.append(sorted(list(map(int, input().split())), reverse=True))
cak.append(sorted(list(map(int, input().split())), reverse=True))
cak.append(sorted(list(map(int, input().split())), reverse=True))

def branch(p):
    cnt = 0
    for i in range(x):
        for j in range(y):
            for k in range(z):
                if cak[0][i]+cak[1][j]+cak[2][k] < p:
                    break
                cnt += 1
                if cnt >= K:
                    return True
    return False

lft = -1; rgt = cak[0][0]+cak[1][0]+cak[2][0]+1
while rgt-lft > 1:
    mid = (rgt+lft)//2
    if branch(mid):
        lft = mid
    else:
        rgt = mid

ans = []
for i in range(x):
    for j in range(y):
        for k in range(z):
            dlc = cak[0][i]+cak[1][j]+cak[2][k]
            if dlc >= lft:
                ans.append(dlc)
            else:
                break
ans.sort(reverse=True)
for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:
from heapq import heappop, heappush
x, y, z, K = map(int, input().split())
cak = []
cak.append(sorted(list(map(int, input().split())), reverse=True))
cak.append(sorted(list(map(int, input().split())), reverse=True))
cak.append(sorted(list(map(int, input().split())), reverse=True))

def branch(p):
    cnt = 0
    for i in range(x):
        for j in range(y):
            for k in range(z):
                if cak[0][i]+cak[1][j]+cak[2][k] < p:
                    break
                cnt += 1
                if cnt >= K:
                    return True
    return False

lft = -1; rgt = 3*10**10+1
while rgt-lft > 1:
    mid = (rgt+lft)//2
    if branch(mid):
        lft = mid
    else:
        rgt = mid

ans = []
for i in range(x):
    for j in range(y):
        for k in range(z):
            dlc = cak[0][i]+cak[1][j]+cak[2][k]
            if dlc >= lft:
                ans.append(dlc)
            else:
                break
ans.sort(reverse=True)
for a in ans:
    print(a)

Submission status: Wrong Answer

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

x,y,z,k = map(int,input().split())
lisa = list(map(int,input().split()))
lisb = list(map(int,input().split()))
lisc = list(map(int,input().split()))


lisab = sorted([a+b for a in lisa for b in lisb], reverse=True)[:k-1]
lisabc = sorted([ab+c for ab in lisab[:k] for c in lisc], reverse=True)[:k-1]

print(*lisabc)

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 ai in a:
  for bi in b:
    ab.append(ai*bi)
ab.sort()

abc = []

for abi in ab[:k]:
  for ci in c:
    abc.append(abi * ci)
abc.sort()

for abci in abc[:k-1]:
  print(abci)

Submission status: Wrong Answer

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

D = [[0,0,0]]
ans = []
for k in range(K):
  # print(k,D)
  mxd = 0
  mxi = 0
  for i in range(len(D)):
    d = A[D[i][0]]+B[D[i][1]]+C[D[i][2]]
    if d >= mxd:
      mxd = d
      mxi = i
  ans.append(mxd)
  if D[mxi][0]+1 < X and [D[mxi][0]+1,D[mxi][1],D[mxi][2]] not in D:
    D.append([D[mxi][0]+1,D[mxi][1],D[mxi][2]])
  if D[mxi][1]+1 < Y and [D[mxi][0],D[mxi][1]+1,D[mxi][2]] not in D:
    D.append([D[mxi][0],D[mxi][1]+1,D[mxi][2]])
  if D[mxi][2]+1 < Z and [D[mxi][0],D[mxi][1],D[mxi][2]+1] not in D:
    D.append([D[mxi][0],D[mxi][1],D[mxi][2]+1])
  del D[mxi]
for a in ans:
  print(a)

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)

AB = [0] * (K * K)
for itra, a in enumerate(A):
  if itra >= K - 1:
    break
  for itrb, b in enumerate(B):
    AB[itra * K + itrb] = (a + b)
    if itrb >= K - 1:
      break
    
AB.sort(reverse=True)    
    
ABC = [0] * (K * K)
for itrab, ab in enumerate(AB):
  if itrab >= K - 1:
    break
  for itrc, c in enumerate(C):
    ABC[itrab * K + itrc] = (ab + c)
    if itrc >= K - 1:
      break
    
ABC.sort(reverse=True)
for itr, i in enumerate(ABC):
  print(i)
  if itr >= K - 1:
    break

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)

AB = [0] * (K * K)
for itra, a in enumerate(A):
  if itra >= K - 1:
    break
  for itrb, b in enumerate(B):
    AB[itra * K + itrb] = (a + b)
    if itrb >= K - 1:
      break
    
AB.sort(reverse=True)    
    
ABC = [0] * (K * K)
for itrab, ab in enumerate(AB):
  if itrab >= K - 1:
    break
  for itrc, c in enumerate(C):
    ABC[itrab * K + itrc] = (ab + c)
    if itrc >= K - 1:
      break
    
ABC.sort(reverse=True)
for itr, i in enumerate(ABC):
  print(i)
  if itr >= K - 1:
    break

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)

AB = []
for itra, a in enumerate(A):
  if itra > K:
    break
  for itrb, b in enumerate(B):
    if itrb > K:
      break
    AB.append(a + b)

AB.sort(reverse=True)    
    
ABC = []
for itrab, ab in enumerate(AB):
  if itrab > K:
    break
  for itrc, c in enumerate(C):
    if itrc > K:
      break
    ABC.append(ab + c)

ABC.sort(reverse=True)
for itr, i in enumerate(ABC):
  print(i)
  if itr > K:
    break

Submission status: Wrong Answer

Solution code:
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()))
    AB = []
    for a in A:
        for b in B:
            AB.append(a + b)

    AB.sort(reverse=True)
    C.sort(reverse=True)
    ans = []
    for i in range(min(K,X+Y)):
        for j in range(min(K,Z)):
            ans.append(AB[i] + C[j])

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



if __name__ == "__main__":
    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()))
ab=[]
abc=[]
for i in a:
  for j in b:
    ab.append(i+j)
ab.sort()
l=min(k,len(ab))
for i in range(l):
  for j in c:
    abc.append(ab[i]+j)
abc.sort()
abc.reverse()
for i in range(k):
  print(abc[i])

Submission status: Wrong Answer

Solution code:
from itertools import product
from heapq import heappop, heappush

x,y,z,k = map(int,input().split())
a = sorted(map(int, input().split()), reverse=True)
b = sorted(map(int, input().split()), reverse=True)
c = sorted(map(int, input().split()), reverse=True)


idx = [0,0,0]
heap = []
xxx = [x,y,z]

aaa = idx[0] if idx[0]+1 >= x else idx[0] + 1
bbb = idx[1] if idx[1]+1 >= y else idx[1] + 1
ccc = idx[2] if idx[2]+1 >= z else idx[2] + 1
heappush(heap, [-(a[aaa] + b[idx[1]] + c[idx[2]]), [1, 0, 0], 0])
heappush(heap, [-(a[idx[0]] + b[bbb] + c[idx[2]]), [0, 1, 0], 1])
heappush(heap, [-(a[idx[0]] + b[idx[1]] + c[ccc]), [0, 0, 1], 2])
print(a[idx[0]] + b[idx[1]] + c[idx[2]])
doc = {}
for _ in range(min(k-1, x*y*z)):
    score, ix, pos = heappop(heap)
    print(-score)
    for i in range(3):
        tmp = ix.copy()
        tmp[i] = ix[i] if ix[i] + 1 >= xxx[i] else ix[i] + 1
        if ','.join(map(str, tmp)) not in doc:
            doc[','.join(map(str, tmp))] = 1
            score = a[tmp[0]] + b[tmp[1]] + c[tmp[2]]
            # print(idx, ix, score, heap)
            heappush(heap, [-score, tmp, i])

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

Submission status: Wrong Answer

Solution code:
from itertools import product
from heapq import heappop, heappush

x,y,z,k = map(int,input().split())
a = sorted(map(int, input().split()), reverse=True)
b = sorted(map(int, input().split()), reverse=True)
c = sorted(map(int, input().split()), reverse=True)

i,j,l = 0,0,0
if x * y * z <= 3000:
    lst = sorted([sum(i) for i in product(a,b,c)], reverse=True)
    [print(i) for i in lst[:k]]
    exit()

lst = []
cnt = 0
for tup in product(a,b,c):
    lst.append(sum(tup))
    if cnt > 100000:
        break
    cnt += 1

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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

# sum of deliciousness が border以上の組み合わせが K個以上あればTrue
def is_ok(a, b, c, X, Y, Z, K, border):
    cnt = 0
    for i in range(X):
        for j in range(Y):
            for k in range(Z):
                if a[i] + b[j] + c[k] < border:
                    break
                cnt += 1
                if cnt == K:
                    return True
    return False

def main():
    x, y, z, K = map(int, sys.stdin.readline().split())
    abc = np.array(sys.stdin.read().split(), dtype=np.int64)
    a = abc[:x]
    b = abc[x:x + y]
    c = abc[x + y:x + y+ z]
    a = np.sort(a)[::-1]
    b = np.sort(b)[::-1]
    c = np.sort(c)[::-1]

    l, r = 3, 3 * 10 ** 10
    while l <= r:
        border = (l + r) // 2
        if is_ok(a, b, c, x, y, z, K, border):
            l = border + 1
        else:
            r = border - 1
        print(l, r)

    res = []
    cnt = 0
    for i in range(x):
        for j in range(y):
            for k in range(z):
                sum_deli = a[i] + b[j] + c[k]
                if sum_deli < r:
                    break
                res.append(sum_deli)
                cnt += 1
                if cnt == K:
                    res = sorted(res, reverse=True)
                    print('\n'.join(map(str, res)))
                    sys.exit()
                

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

x,y,z,k = inpl()
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
ab = []
for i in a:
    for j in b:
        ab.append(i+j)
ab.sort(reverse=True)
c.sort(reverse=True)
cp = [0] * z
# print(ab,c)
for i in range(k):
    res = 0
    ind = -1
    for j in range(z):
        if cp[j] >= 0 and c[j] + ab[cp[j]] >= res:
            res = c[j] + ab[cp[j]]
            ind = j
    print(res)
    cp[ind] += 1
    if cp[ind] == x + y:
        cp[ind] = -1

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

x,y,z,k = inpl()
a = inpl()
b = inpl()
c = inpl()
ab = []
for i in a:
    for j in b:
        ab.append(i+j)
ab.sort(reverse=True)
A = min(x+y,k)
res = []
# print(ab,c)
for i in range(A):
    for j in range(z):
        res.append(ab[i]+c[j])
res.sort(reverse=True)
for i in range(k):
    print(res[i])

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

x,y,z,k = inpl()
a = inpl()
b = inpl()
c = inpl()
ab = []
for i in a:
    for j in b:
        ab.append(i+j)
ab.sort(reverse=True)
c.sort(reverse=True)
A = min(x+y,k)
C = min(z,k)
res = []
# print(ab,c)
for i in range(A):
    for j in range(C):
        res.append(ab[i]+c[j])
res.sort(reverse=True)
for i in range(k):
    print(res[i])

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

x,y,z,k = inpl()
a = inpl()
b = inpl()
c = inpl()
ab = []
for i in a:
    for j in b:
        ab.append(i+j)
ab.sort(reverse=True)
c.sort(reverse=True)
cp = [0] * z
# print(ab,c)
for i in range(k):
    res = 0
    ind = -1
    for j in range(z):
        if cp[j] >= 0 and c[j] + ab[cp[j]] >= res:
            res = c[j] + ab[cp[j]]
            ind = j
    print(res)
    cp[ind] += 1
    if cp[ind] == x + y:
        cp[ind] = -1

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

x,y,z,k = inpl()
a = inpl()
b = inpl()
c = inpl()
ab = []
for i in a:
    for j in b:
        ab.append(i+j)
ab.sort(reverse=True)
c.sort(reverse=True)
cp = [0] * z
# print(ab,c)
for i in range(k):
    res = 0
    ind = -1
    for j in range(z):
        if cp[j] >= 0 and c[j] + ab[cp[j]] > res:
            res = c[j] + ab[cp[j]]
            ind = j
    print(res)
    cp[ind] += 1
    if cp[ind] >= x + y:
        cp[ind] = -1

Submission status: Wrong Answer

Solution code:
x,y,z,k = map(int,input().split())
list1 = [list(map(int,input().split())) for i in range(3) ]

list_ab = []
list_ab_c = []

for i in list1[0]:
	for j in list1[1]:
		list_ab.append(i+j)

for i in list_ab[:3000]:
	for j in list1[2]:
		list_ab_c.append(i+j)

list_ab_c.sort(reverse=True)

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