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: Time Limit Exceeded

Solution code:
x, y, z, k = map(int, input().split())
c_s = list(map(int, input().split()))
b_s = list(map(int, input().split()))
a_s = list(map(int, input().split()))
a_s.sort(reverse=True)
b_s.sort(reverse=True)
c_s.sort(reverse=True)

d = {}
abcs = [0]
j = -1

for a in a_s:
    for b in b_s:
        for c in c_s:
            abc = a + b + c
            if j >= k and abcs[k-1] >= abc:
                break
            if abcs[0] == 0:
                abcs[0] = abc
            else:
                for i in reversed(range(len(abcs))):
                    if abcs[i] >= abc:
                        abcs.insert(i+1, abc)
                        break
            j += 1
for i in range(k):
    print(abcs[i])

Submission status: Time Limit Exceeded

Solution code:
x,y,z,q=map(int,input().split())
*a,=map(int,input().split())
*b,=map(int,input().split())
*c,=map(int,input().split())
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
 
class bisect:
  def bisect(self,l,r):
    cnt=(l+r)//2
    if cnt==l:
      return l-1+self.judge(l)
    if self.judge(cnt):
      return self.bisect(cnt+1,r)
    else:
      return self.bisect(l,cnt)
  def judge(self,thr):
    m=0
    for i in a:
      for j in b:
        for k in c:
          if i+j+k>thr:
            m+=1
            if m>=q:
              return True
    return False

def make(thr):
  m=0
  l=[]
  for i in a:
    for j in b:
      for k in c:
        n=i+j+k
        if n>thr:
          m+=1
          l+=[n]
          if m>=q:
            l.sort(reverse=True)
            return l

s=bisect()
thr=s.bisect(0,a[0]+b[0]+c[0]+1)
ans=make(thr)
for w in ans:
  print(w)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from bisect import bisect_left
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 = np.array(a)
b = np.array(b)
c = np.array(c)
bi,ci = np.meshgrid(b,c)
bc = (bi + ci).flatten()
a = np.sort(a)
bc = np.sort(bc)

lenbc = len(bc)
lo = 0
hi = bc[-1] + a[-1] + 1
while abs(lo-hi) > 1:
    mid = (lo+hi) // 2
    r = 0
    for v in a:
        r += lenbc - np.searchsorted(bc,mid-v)
    if r >= k:
        lo = mid
    else:
        hi = mid

r = []
for v in a:
    insid = np.searchsorted(bc,lo-v)
    for vb in range(insid, lenbc):
        r.append(v + bc[vb])
r = sorted(r, reverse=True)
for i in range(k): print(r[i])

Submission status: Time Limit Exceeded

Solution code:
input_out_data = input().split(" ")
cake_sum_point = []

for i in range(4):
    input_out_data[i] = int(input_out_data[i])


cake_A = input().split(" ")
cake_B = input().split(" ")
cake_C = input().split(" ")
for k in range(input_out_data[0]):
    cake_A[k] = int(cake_A[k])
cake_A.sort(reverse=True)
for k in range(input_out_data[1]):
    cake_B[k] = int(cake_B[k])
cake_B.sort(reverse=True)
for k in range(input_out_data[2]):
    cake_C[k] = int(cake_C[k])
cake_C.sort(reverse=True)

for i in range(input_out_data[0]):
    for k in range(input_out_data[1]):
        for j in range(input_out_data[2]):
            cake_sum_point.append(cake_A[i]+cake_B[k]+cake_C[j])
cake_sum_point.sort(reverse=True)
for i in range(input_out_data[3]):
    print(cake_sum_point[i])

Submission status: Time Limit Exceeded

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

data_AB = []
for i in range(X):
    for j in range(Y):
        data_AB.append(A[i]+B[j])
data_AB.sort()
data_AB.reverse()
data_AB_K = []
ab = min([K, X*Y])
for i in range(ab):
    data_AB_K.append(data_AB[i])

data_KC = []
C.sort()
C.reverse()
for i in range(ab):
    for j in range(Z):
        data_KC.append(data_AB_K[i] + C[j])
data_KC.sort()
data_KC.reverse()
for i in range(K):
    print(data_KC[i])

Submission status: Time Limit Exceeded

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

class bisect:
  def bisect(self,l,r,opt):
    cnt=(l+r)//2
    if cnt==l:
      return l-1+opt+(opt^self.judge(l))
    if opt^self.judge(cnt):
      return self.bisect(cnt+1,r,opt)
    else:
      return self.bisect(l,cnt,opt)
  def judge(self,thr):
    m=0
    for i in a:
      for j in b:
        for k in c:
          if i+j+k>thr:
            m+=1
            if m>=q:
              return True
    return False

def make(thr):
  m=0
  l=[]
  for i in a:
    for j in b:
      for k in c:
        n=i+j+k
        if n>thr:
          m+=1
          l+=[n]
          if m>=q:
            l.sort(reverse=True)
            return l

s=bisect()
thr=s.bisect(0,max(a)+max(b)+max(c)+1,0)
ans=make(thr)
for w in ans:
  print(w)

Submission status: Time Limit Exceeded

Solution code:
x, y, z, k = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

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

AB.sort(reverse=True)

ABC = []
for i in range(min(x * y, k)):
    for c in C:
        ABC.append(AB[i] + c)

ABC.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
import heapq

xyzk = list(map(int, input().split()))
x = xyzk[0]
y = xyzk[1]
z = xyzk[2]
k = xyzk[3]

a = list(map(int, input().split()))
a.sort(reverse=True)
b = list(map(int, input().split()))
b.sort(reverse=True)
c = list(map(int, input().split()))
c.sort(reverse=True)

queue = []

heapq.heappush(queue, [- (a[0] + b[0] + c[0]), 0, 0, 0])
for i in range(k):
    maximum = queue[0]
    print(- maximum[0])
    aa = maximum[1]
    bb = maximum[2]
    cc = maximum[3]
    heapq.heappop(queue)
    FlagA = False
    FlagB = False
    FlagC = False
    for j in range(len(queue)):
        if queue[j][1] == aa + 1 and queue[j][2] == bb and queue[j][3] == cc:
            FlagA = True
        elif queue[j][1] == aa and queue[j][2] == bb + 1 and queue[j][3] == cc:
            FlagB = True
        elif queue[j][1] == aa and queue[j][2] == bb and queue[j][3] == cc + 1:
            FlagC = True

    if not FlagA and len(a) > aa + 1:
        heapq.heappush(queue, [- (a[aa + 1] + b[bb] + c[cc]), aa + 1, bb, cc])
    if not FlagB and len(b) > bb + 1:
        heapq.heappush(queue, [- (a[aa] + b[bb + 1] + c[cc]), aa, bb + 1, cc])
    if not FlagC and len(c) > cc + 1:
        heapq.heappush(queue, [- (a[aa] + b[bb] + c[cc + 1]), aa, bb, cc + 1])

Submission status: Time Limit Exceeded

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

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

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

AB = sorted(AB, reverse=True)
if K < len(AB):
    AB = AB[:K]

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

ABC = sorted(ABC, reverse=True)
ABC = ABC[:K]

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

Submission status: Time Limit Exceeded

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

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)
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

AB = []

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

AB = sorted(AB, reverse=True)

if K < len(AB):
    AB = AB[:K]

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

ABC = sorted(ABC, reverse=True)

ABC = ABC[:K]
ABC = [str(abc) for abc in ABC]

print("\n".join(ABC))

Submission status: Time Limit Exceeded

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

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)

AB = []

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

AB = sorted(AB, reverse=True)

if K < len(AB):
    AB = AB[:K]

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

ABC = sorted(ABC, reverse=True)

ABC = ABC[:K]
ABC = [str(abc) for abc in ABC]

print("\n".join(ABC))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ab = sorted(x+y for x in a for y in b)[:-k-1:-1]
abc = sorted(x+y for x in ab[:k] for y in c)[:-k-1:-1]
print(*abc, sep='\n')

Submission status: Time Limit Exceeded

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

ab = sorted([x+y for x in a for y in b])[:-k-1:-1]
abc = sorted([x+y for x in ab[:k] for y in c])[:-k-1:-1]
print(*abc, sep='\n')

Submission status: Time Limit Exceeded

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

ab = sorted([x+y for x in a for y in b])[:-k-1:-1]
abc = sorted([x+y for x in ab[:k] for y in c])[:-k-1:-1]

for i in abc:
  print(i)

Submission status: Time Limit Exceeded

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

li = []
ans = []

for i in a:
    for j in b:
        li.append(i + j)
        
li.sort(reverse = True)
li = li[:min(k,x*y)]

for i in li:
    for j in c:
        ans.append(i + j)
        
ans.sort(reverse = True)

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# なんかおかしい！！
import math
import sys
import itertools
import numpy as np

 
# なんこか入力
x,y,z,k = map(int, input().split())
 
# 空白区切りの数列をリストに代入
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
 
a.sort()
b.sort()
c.sort()
#cake = [[0 for i in range(3)] for j in range(3000)]
#cake[0][0]=x-1
#cake[0][1]=y-1
#cake[0][2]=z-1
#print(a[x-1]+b[y-1]+c[z-1])
#print(a[cake[0][0]],b[cake[0][1]],c[cake[0][2]])
t = [[-1,-1,-1,-1] for i in range(3*k)]
t[0] = [a[x-1]+b[y-1]+c[z-1],x-1,y-1,z-1]
t_a = 1
#print(s)
 
for i in range(0,k):
    ma = 0
    temp = [-1,-1,-1,-1]
    for j in t:
        if ma <= j[0] :
            temp = j
            ma = j[0]
#    print(temp)
    print(temp[0])
    t[t.index(temp)][0]=0
#    print("s=",s)
#    print("t=",t)
#    print(temp)
    f =1
    if temp[1] > 0:
        for j in t:
            if temp[1]-1 == j[1] and temp[2]==j[2] and temp[3]==j[3]:
                f = 0
                break
        if f == 1:
            t[t_a] = [a[temp[1]-1]+b[temp[2]]+c[temp[3]],temp[1]-1,temp[2],temp[3]]
            t_a += 1
    f =1
    if temp[2] > 0:
        for j in t:
            if temp[1] == j[1] and temp[2]-1==j[2] and temp[3]==j[3]:
                f = 0
                break
        if f == 1:
            t[t_a] = [a[temp[1]]+b[temp[2]-1]+c[temp[3]],temp[1],temp[2]-1,temp[3]]
            t_a += 1
    f =1
    if temp[3] > 0:
        for j in t:
            if temp[1] == j[1] and temp[2]==j[2] and temp[3]-1==j[3]:
                f = 0
                break
        if f == 1:
            t[t_a] = [a[temp[1]]+b[temp[2]]+c[temp[3]-1],temp[1],temp[2],temp[3]-1]
            t_a += 1

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k = map(int,input().split())
a = [int(v) for v in input().split()]
b = [int(v) for v in input().split()]
c = [int(v) for v in input().split()]

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

ab = []

for i in range(min(k,len(a))):
  for j in range(min(k,len(b))):
    ab.append(a[i]+b[j])
ab.sort(reverse=True)
ab = ab[:k]

ans = []

for v1 in ab:
  for v2 in c[:k]:
    ans.append(v1+v2)
ans.sort(reverse=True)

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

Submission status: Time Limit Exceeded

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

ab = [x+y for x in a for y in b]
ab.sort(reverse=True)

abc = [x+y for x in ab[:k] for y in c]

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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)
  if len(que) > K:
    que = que[:K-1]

Submission status: Time Limit Exceeded

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

ab = [x+y for x in a for y in b]
ab.sort()

abc = [x+y for x in ab[:-k-1:-1] for y in c]

abc.sort()
for i in abc[:-k-1:-1]:
  print(i)

Submission status: Time Limit Exceeded

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

li = []

for i in a:
    for j in b:
        li.append(i + j)
        
li.sort(reverse = True)
li = li[:min(k,x*y)]

box = []

for i in li:
    for j in c:
        box.append(i + j)

box.sort(reverse = True)

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

Submission status: Time Limit Exceeded

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

li = []

for i in range(x):
    for j in range(y):
        li.append(a[i] + b[j])
        
li.sort(reverse = True)
li = li[:min(k,x*y)]

box = []

for i in range(len(li)):
    for j in range(z):
        box.append(li[i] + c[j])

box.sort(reverse = True)

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys

X, Y, Z, K = map(int, input().split())
a = np.array(list(map(int, sys.stdin.readline().split())), dtype='int64')
b = np.array(list(map(int, sys.stdin.readline().split())), dtype='int64')
c = np.array(list(map(int, sys.stdin.readline().split())), dtype='int64')

amax = a.max()
bmax = b.max()
cmax = c.max()

a = amax - a
a.sort()
b = bmax - b
b.sort()
c = cmax - c
c.sort()


def func(o, p):
    min_ = 0
    max_ = o[-1] + p[-1]
    v = (min_ + max_) // 2
    while True:
        mat = np.searchsorted(o, v - p, side='right')
        sum_ = mat.sum()
        if sum_ > K:
            max_ = v - 1
            v = (v + min_) // 2
        elif sum_ == K:
            return v
        else:
            min_ = v + 1
            v = (v + max_ + 1) // 2


if X * Y > K:
    u = func(a, b)
    matr = np.searchsorted(a, u - b, side='right')
    d = np.array([],dtype='int64')
    for i in range(Y):
        d = np.append(d, a[:matr[i]] + b[i])
    d.sort()
else:
    d = (a + b.reshape([len(b), 1])).flatten()
    d.sort()

u = func(d, c)
matr = np.searchsorted(d, u - c, side='right')
e = np.array([],dtype='int64')
for i in range(Z):
    e = np.append(e, d[:matr[i]] + c[i])
e.sort()

t = amax + bmax + cmax
for ec in e:
    print(t - ec)

Submission status: Time Limit Exceeded

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

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

max_b = max(B)
max_c = max(C)


summs_ab = []
summs = []
"""
for a in A:
    for b in B:
        summs_ab.append(a+b)
summs_ab.sort(reverse=True)
summs_ab = summs_ab[:min(3001, X*Y*Z+1)]

for c in C:
    for sab in summs_ab:
        summs.append(sab+c)
summs.sort(reverse=True)
"""
for a in A[:K]:
    if len(summs) >= K and a + max_b + max_c < summs[K-1]:
        break

    for b in B[:K]:
        if len(summs) >= K and a + b + max_c < summs[K-1]:
            break

        for c in C[:K]:
            summ = a + b + c
            if len(summs) >= K:
                min_sum = summs[K-1]    
                if summ < min_sum:
                    break
            summs.append(summ)
        summs.sort()
        summs.reverse()

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

Submission status: Time Limit Exceeded

Solution code:
X,Y,Z,K = map(int,input().split())
As = list(map(int,input().split()))
Bs = list(map(int,input().split()))
Cs = list(map(int,input().split()))
AB = []
for A in As:
    for B in Bs:
        AB.append(A+B)
AB.sort(reverse=True)
ABC = []
for k in range(min(K,len(AB))):
    for c in Cs:
        ABC.append(AB[k]+c)
ABC.sort(reverse = True)
for abc in ABC[:K]:
    print(abc)

Submission status: Time Limit Exceeded

Solution code:
_, _, _, k = list(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 a:
  for j in b:
    ab.append(i+j)
ab.sort()
abc = []
for i in ab[:-k-1:-1]:
  for j in c:
    abc.append(i+j)
abc.sort()
for i in abc[:-k-1:-1]:
  print(i)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3

import itertools

def main():
    X, Y, Z, K = map(int, input().split())
    data = [list(map(int, input().split())) for _ in range(3)]

    a_add_b = [[i + j for i in data[0]] for j in data[1]]
    a_add_b = list(itertools.chain(*a_add_b))
    a_add_b.sort()
    e_add_c = [[i + j for i in a_add_b[-K:]] for j in data[2]]
    e_add_c = list(itertools.chain(*e_add_c))
    e_add_c.sort()

    e_add_c = e_add_c[::-1]

    for abc in e_add_c[:K]:
        print(abc)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k=map(int,input().split())
al=[int(i) for i in input().split()]
bl=[int(i) for i in input().split()]
cl=[int(i) for i in input().split()]
lst=[]
for i in al:
  for j in bl:
    lst.append(i+j)
lst.sort(reverse=True)
num=min(x*y,k)
lst=lst[:num]
L=[]
for i in cl:
  for j in lst:
    L.append(i+j)
L.sort(reverse=True)
for i in range(k):
  print(L[i])

Submission status: Time Limit Exceeded

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

li = []

for i in range(x):
    for j in range(y):
        li.append(a[i] + b[j])
        
li.sort(reverse = True)
li = li[:min(k,x*y)]

box = []

for i in range(len(li)):
    for j in range(z):
        box.append(li[i] + c[j])

box.sort(reverse = True)
box = box[:k]

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

Submission status: Time Limit Exceeded

Solution code:
x,y,z,k=map(int,input().split())
al=[int(i) for i in input().split()]
bl=[int(i) for i in input().split()]
cl=[int(i) for i in input().split()]
lst=[]
for i in al:
  for j in bl:
    lst.append(i+j)
lst.sort(reverse=True)
num=min(x*y,k)
lst=lst[:k]
L=[]
for i in cl:
  for j in lst:
    L.append(i+j)
L.sort(reverse=True)
for i in range(k):
  print(L[i])

Submission status: Time Limit Exceeded

Solution code:
import itertools
x,y,z,t = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)
ans = []
for i in range(x):
    for k in range(y):
        ans.append(a[i]+b[k])
ans.sort(reverse = True)
if x*y > t:
    ans = ans[0:t]
    l = t
else:
    l = x*y
out = []

for i in range(l):
    for k in range(z):
        out.append(ans[i]+c[k])
out.sort(reverse = True)
for i in range(t):
    print(out[i])

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from string import ascii_uppercase
import sys, bisect
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

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

yz = []
res = []
def solve():
    for i in range(Y):
        for j in range(Z):
            yz.append(B[i] + C[j])
    yz.sort(reverse=True)
    for i in range(X):
        for j in range(min(K,len(yz))):
            res.append(A[i] + yz[j])
    res.sort(reverse=True)
    for i in range(K):
        print(res[i])


if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from string import ascii_uppercase
import sys, bisect
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

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

yz = []
res = []
def solve():
    for i in range(Y):
        for j in range(Z):
            yz.append(B[i] + C[j])
    yz.sort(reverse=True)
    for i in range(X):
        for j in range(min(K,len(yz))):
            bisect.insort_left(res, A[i] + yz[j])
    for i in range(K):
        print(res[len(res) - i - 1])


if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
import itertools
x,y,z,t = 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()
ans = []
for i in range(x):
    for k in range(y):
        ans.append(a[i]+b[k])
ans.sort(reverse = True)
if x*y > t:
    ans = ans[0:t]
    l = t
else:
    l = x*y
out = []

for i in range(l):
    for k in range(z):
        out.append(ans[i]+c[k])
out.sort(reverse = True)
for i in range(t):
    print(out[i])

Submission status: Time Limit Exceeded

Solution code:
_, _, _, k = list(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 a:
  for j in b:
    ab.append(i+j)
ab.sort()
ab.reverse()
abc = []
for i in ab[:k]:
  for j in c:
    abc.append(i+j)
abc.sort()
abc.reverse()
for i in abc[:k]:
  print(i)

Submission status: Time Limit Exceeded

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_ = [b+c for (b,c) in itertools.product(B, C)]
list_.sort(reverse=True)
 
list__ = [ab+c for (ab,c) in itertools.product(list_[:K], A)]
list__.sort(reverse=True)
for N in list__[:K]:
  print(N)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
import heapq
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [X, Y, Z, K] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2]), int(input_raw[3])]

    input_raw = read_func().strip().split()
    A = [long(input_raw[i]) for i in range(X)]
    input_raw = read_func().strip().split()
    B = [long(input_raw[i]) for i in range(Y)]
    input_raw = read_func().strip().split()
    C = [long(input_raw[i]) for i in range(Z)]

    BC = [B[i] + C[j] for i in range(Y) for j in range(Z)]
    BC.sort(reverse = True)

    T=[A[i] + BC[j] for i in range(X) for j in range(min(K, len(BC)))]
    T.sort(reverse = True)
    for i in range(K):
        print T[i]

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

X, Y, Z, K = map(int, input().split())
a = np.array(list(map(int, input().split())), dtype='int64')
b = np.array(list(map(int, input().split())), dtype='int64')
c = np.array(list(map(int, input().split())), dtype='int64')

amax = a.max()
bmax = b.max()
cmax = c.max()

a = amax - a
a.sort()
b = bmax - b
b.sort()
c = cmax - c
c.sort()


def func(o, p):
    min_ = 0
    max_ = o[-1] + p[-1]
    v = (min_ + max_) // 2
    while True:
        mat = np.searchsorted(o, v - p, side='right')
        sum_ = mat.sum()
        if sum_ > K:
            max_ = v - 1
            v = (v + min_) // 2
        elif sum_ == K:
            return v
        else:
            min_ = v + 1
            v = (v + max_ + 1) // 2


if X * Y > K:
    u = func(a, b)
    matr = np.searchsorted(a, u - b, side='right')
    d = np.array([],dtype='int64')
    for i in range(Y):
        d = np.append(d, a[:matr[i]] + b[i])
    d.sort()
else:
    d = (a + b.reshape([len(b), 1])).flatten()
    d.sort()

u = func(d, c)
matr = np.searchsorted(d, u - c, side='right')
e = np.array([],dtype='int64')
for i in range(Z):
    e = np.append(e, d[:matr[i]] + c[i])
e.sort()

t = amax + bmax + cmax
for ec in e:
    print(t - ec)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from string import ascii_uppercase
import sys, bisect
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

X, Y, Z, K = read_int()
A = read_int()
A.sort(reverse=True)
B = sorted(read_int())
C = sorted(read_int())

yz = []
res = []
def solve():
    for i in range(Y):
        for j in range(Z):
            yz.append(B[i] + C[j])
    yz.sort(reverse=True)
    for i in range(X):
        for j in range(min(K,len(yz))):
            res.append(A[i] + yz[j])
    res.sort(reverse=True)
    for i in range(K):
        print(res[i])


if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
import itertools
x,y,z,t = 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()
ans = []
for i in range(x):
    for k in range(y):
        ans.append(a[i]+b[k])
ans.sort()
ans.reverse()
if x*y > t:
    ans = ans[0:t]
out = []
for i in range(len(ans)):
    for k in range(z):
        out.append(ans[i]+c[k])
out.sort()
out.reverse()
for i in range(t):
    print(out[i])