Problem:


Score: 400 points

Problem Statement

The Patisserie AtCoder sells cakes with number-shaped candles.
There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively.
Each cake has an integer value called deliciousness, as follows:

The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.

The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.

The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.

Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.

There are X \times Y \times Z such ways to choose three cakes.

We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.

Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Constraints

1 \leq X \leq 1 \ 000

1 \leq Y \leq 1 \ 000

1 \leq Z \leq 1 \ 000

1 \leq K \leq \min(3 \ 000, X \times Y \times Z)

1 \leq A_i \leq 10 \ 000 \ 000 \ 000

1 \leq B_i \leq 10 \ 000 \ 000 \ 000

1 \leq C_i \leq 10 \ 000 \ 000 \ 000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z

Output

Print K lines. The i-th line should contain the i-th value stated in the problem statement.

Sample Input 1

2 2 2 8
4 6
1 5
3 8

Sample Output 1

19
17
15
14
13
12
10
8

There are 2 \times 2 \times 2 = 8 ways to choose three cakes, as shown below in descending order of the sum of the deliciousness of the cakes:

(A_2, B_2, C_2): 6 + 5 + 8 = 19

(A_1, B_2, C_2): 4 + 5 + 8 = 17

(A_2, B_1, C_2): 6 + 1 + 8 = 15

(A_2, B_2, C_1): 6 + 5 + 3 = 14

(A_1, B_1, C_2): 4 + 1 + 8 = 13

(A_1, B_2, C_1): 4 + 5 + 3 = 12

(A_2, B_1, C_1): 6 + 1 + 3 = 10

(A_1, B_1, C_1): 4 + 1 + 3 = 8

Sample Input 2

3 3 3 5
1 10 100
2 20 200
1 10 100

Sample Output 2

400
310
310
301
301

There may be multiple combinations of cakes with the same sum of the deliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and the sum of A_3, B_3, C_1 are both 301.
However, they are different ways of choosing cakes, so 301 occurs twice in the output.

Sample Input 3

10 10 10 20
7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488
1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338
4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736

Sample Output 3

23379871545
22444657051
22302177772
22095691512
21667941469
21366963278
21287912315
21279176669
21160477018
21085311041
21059876163
21017997739
20703329561
20702387965
20590247696
20383761436
20343962175
20254073196
20210218542
20150096547

Note that the input or output may not fit into a 32-bit integer type.



Sample input:
2 2 2 8
4 6
1 5
3 8


Sample output:
19
17
15
14
13
12
10
8

Submission status: Wrong Answer

Solution code:
import itertools
X, Y, Z, K = map(int, input().rstrip().split())
A = list(map(int, input().rstrip().split()))
B = list(map(int, input().rstrip().split()))
C = list(map(int, input().rstrip().split()))
A.sort()
B.sort()
C.sort()
if X*Y*Z != K:
    if X > 20:
        A = A[:20]
    if Y > 20:
        B = B[:20]
    if Z > 20:
        C = C[:20]
combinations = list(itertools.product(A, B, C))
total = []
for combination in combinations:
    total.append(sum(combination))
total.sort(reverse=True)
for i in range(K):
    print(total[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()
a.reverse()
b.sort()
b.reverse()
c.sort()
c.reverse()
ans=[]
if x*y*z<=3000:
  for i in range(x):
    for j in range(y):
      for h in range(z):
        ans.append(a[i]+b[j]+c[h])
  ans.sort()
  ans.reverse()
  for i in range(k):
    print(ans[i])
  exit()
p=0
q=0
r=0
a1=0
b1=0
c1=0
while (p+1)*(q+1)*(r+1)<k:
  if p+1<len(a):
      a1=a[0]-a[p+1]
  else:
    a1=10**18
  if q+1<len(b):
      b1=b[0]-b[q+1]
  else:
    b1=10**18
  if r+1<len(c):
      c1=c[0]-c[r+1]
  else:
    c1=10**18
  if a1==min(a1,b1,c1) and p+1<len(a):
    p+=1
  elif b1==min(a1,b1,c1) and q+1<len(b):
    q+=1
  elif c1==min(a1,b1,c1) and r+1<len(c):
    r+=1
  else:
    if p+1<len(a):
      p+=1
    elif q+1<len(b):
      q+=1
    elif r+1<len(c):
      r+=1
for i in range(p+1):
  for j in range(q+1):
    for h in range(r+1):
      ans.append(a[i]+b[j]+c[h])
ans.sort()
ans.reverse()
for i in range(k):
  print(ans[i])

Submission status: Wrong Answer

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

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)


A = A[:100]
B = B[:100]
C = C[:100]

ans = []
for a in A:
    for b in B:
        for c in C:
            ans.append(a+b+c)
    
ans.sort(reverse=True)
for a in ans[:K]:
    print(a)

Submission status: Wrong Answer

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


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


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


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


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

current_A = 0
current_B = 0
current_C = 0


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


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

result = []
for i in xrange(current_A + 1):
    for j in xrange(current_B + 1):
        for k in xrange(current_C + 1):
            result.append(sorted_A[i] + sorted_B[j] + sorted_C[k])

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

Submission status: Wrong Answer

Solution code:
x, y, z, k = list(map(int, input().split()))
a_ = list(map(int, input().split()))
b_ = list(map(int, input().split()))
c_ = list(map(int, input().split()))

ans = []
for a in a_:
    for b in b_:
        for c in c_:
            ans.append(a+b+c)

ans.sort(reverse=True)

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(A, B, C, K):
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)

    def s(i, j, k):
        return A[i] + B[j] + C[k]
    used = set()
    
    cand = []
    heapq.heappush(cand, (-s(0, 0, 0), (0, 0, 0)))
    for _ in range(K-1):
        v, i = heapq.heappop(cand)
        print(-v)
        
        ti = (i[0]+1, i[1], i[2])
        if ti[0] < len(A) and ti not in used:
            heapq.heappush(cand, (-s(*ti), ti))
            used.add(ti)
        
        ti = (i[0], i[1]+1, i[2])
        if ti[1] < len(B) and ti not in used:
            heapq.heappush(cand, (-s(*ti), ti))
            used.add(ti)
        
        ti = (i[0], i[1], i[2]+1)
        if ti[2] < len(C) and ti not in used:
            heapq.heappush(cand, (-s(*ti), ti))
            used.add(ti)



def main():
    # for _ in range(1000):
    #     K = 3000
    #     A = [random.randint(1, 10000000000) for _ in range(random.randint(1, 1000))]
    #     B = [random.randint(1, 10000000000) for _ in range(random.randint(1, 1000))]
    #     C = [random.randint(1, 10000000000) for _ in range(random.randint(1, 1000))]
    #     K = min(K, len(A) + len(B) + len(C))
    #     slv(A,B,C,K)
    # N = read_int()
    X, Y, Z, K = read_int_n()
    A = read_int_n()
    B = read_int_n()
    C = read_int_n()
    (slv(A, B, C, 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()))
a.sort(key=lambda x:-x)
b.sort(key=lambda x:-x)
c.sort(key=lambda x:-x)
len=min(x*y*z,3000)
beauty=[0 for _ in range(5000)]
beauty[0]=a[0]+b[0]+c[0]
index=1
indexsum=1
size=[x,y,z]
while index<len:
    imax=min(indexsum+1,x)
    for i in range(imax):
        jmax=min(indexsum+1-i,y)
        for j in range(jmax):
            if indexsum-i-j < z:
                num=a[i]+b[j]+c[indexsum-i-j]
                beauty[index]=num
                index+=1
                # print(num)
    indexsum+=1
beauty.sort(key=lambda x:-x)
# print(beauty)
for i in range(k):
    print(beauty[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()))

if x>150:
  a.sort()
  a.reverse()
  a=a[0:150]

if y>150:
  b.sort()
  b.reverse()
  b=b[0:150]

if z>150:
  c.sort()
  c.reverse()
  c=c[0:150]

lena=len(a)
lenb=len(b)
lenc=len(c)
  
ansList=[]
for m in range(lena):
  for n in range(lenb):
    for o in range(lenc):
      ansList.append(a[m]+b[n]+c[o])

ansList.sort()
ansList.reverse()

for i in range(k):
  print(ansList[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)

sum = []
for i in range(min(X,75)):
    for j in range(min(Y,75)):
        for k in range(min(Z,75)):
            sum.append(A[i] + B[j] + C[k])
sum.sort(reverse=True)
for i in range(K):
    print(sum[i])

Submission status: Wrong Answer

Solution code:
X,Y,Z,K=map(int,input().split())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
C=[int(i) for i in input().split()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
SUM=[]
for a in range(min(60,X)):
  for b in range(min(60,Y)):
    for c in range(min(60,Z)):
      SUM.append(A[a]+B[b]+C[c])
SUM.sort(reverse=True)
for i in range(K):
  print(SUM[i])

Submission status: Wrong Answer

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


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


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


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


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

current_A = 0
current_B = 0
current_C = 0


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


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

result = []
for i in xrange(current_A + 1):
    for j in xrange(current_B + 1):
        for k in xrange(current_C + 1):
            result.append(sorted_A[i] + sorted_B[j] + sorted_C[k])

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

Submission status: Wrong Answer

Solution code:
import itertools
x,y,z,k = map(int,input().split())
X = sorted(list(map(int,input().split())),reverse=True)
Y = sorted(list(map(int,input().split())),reverse=True)
Z = sorted(list(map(int,input().split())),reverse=True)
L = list(itertools.product(X[0:17],Y[0:17],Z[0:17]))
J = sorted([sum(i) for i in L],reverse=True)
for i in range(k):
    print(J[i])

Submission status: Wrong Answer

Solution code:
xyzk_, a_, b_, c_ = [input() for _ in range(4)]

x, y, z, k = [int(w) for w in xyzk_.split()]
a_nums = [int(n) for n in a_.split()]
b_nums = [int(n) for n in b_.split()]
c_nums = [int(n) for n in c_.split()]

a_nums.sort(reverse=True)
b_nums.sort(reverse=True)
c_nums.sort(reverse=True)

while (len(a_nums) - 1) * (len(b_nums) - 1) * (len(c_nums) - 1) >= k:
    m = min(min(a_nums), min(b_nums), min(c_nums))
    if m in a_nums:
        a_nums.pop()
    if m in b_nums:
        b_nums.pop()
    if m in c_nums:
        c_nums.pop()


sums = []
for a in a_nums:
    for b in b_nums:
        for c in c_nums:
            sums.append(a + b + c)

sums.sort(reverse=True)

for n in sums[:k]:
    print(n)

Submission status: Wrong Answer

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

sum = []
for i in range(min(X,50)):
    for j in range(min(Y,50)):
        for k in range(min(Z,50)):
            sum.append(A[i] + B[j] + C[k])
sum.sort(reverse=True)
for i in range(K):
    print(sum[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()))

if x>100:
  a.sort()
  a.reverse()
  a=a[0:100]

if y>100:
  b.sort()
  b.reverse()
  b=b[0:100]

if z>100:
  c.sort()
  c.reverse()
  c=c[0:100]

lena=len(a)
lenb=len(b)
lenc=len(c)
  
ansList=[]
for m in range(lena):
  for n in range(lenb):
    for o in range(lenc):
      ansList.append(a[m]+b[n]+c[o])

ansList.sort()
ansList.reverse()

for i in range(k):
  print(ansList[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()))
L = list()
for i in A:
  for j in B:
    for k in C:
      L.append(i+j+k)
L.sort()
L.reverse()
for i in L:
  print(i)

Submission status: Wrong Answer

Solution code:
x, y, z, n = map(int, input().split())
f = []
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
a.reverse()
b.reverse()
c.reverse()
a = a[0:-(-n//3)]
b = b[0:-(-n//3)]
c = c[0:-(-n//3)]
for i in range(len(a)) :
  for j in range(len(b)) :
    for k in range(len(c)) :
      f.append(a[i]+b[j]+c[k])
      f = sorted(f)
      f.reverse()
for i in range(n) :
  print(f[i])

Submission status: Wrong Answer

Solution code:
import itertools
import sys

input = sys.stdin.readline

maxn = 10000000000

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

A.append(-maxn)
B.append(-maxn)
C.append(-maxn)

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

apos, bpos, cpos = 0, 0, 0

while (apos + 1) * (bpos + 1) * (cpos + 1) < min(10 ** 6 + 10 ** 5, X * Y * Z):
    if (
        apos < len(A) - 2
        and abs(A[apos] - A[apos + 1]) < abs(B[bpos] - B[bpos + 1])
        and abs(A[apos] - A[apos + 1]) < abs(C[cpos] - C[cpos + 1])
    ):
        apos += 1
    elif bpos < len(B) - 2 and B[bpos] - B[bpos + 1] < C[cpos] - C[cpos + 1]:
        bpos += 1
    else:
        cpos += 1

res = []
for a in list(itertools.product(A[: apos + 1], B[: bpos + 1], C[: cpos + 1])):
    res.append(a[0] + a[1] + a[2])

res.sort(reverse=True)
for k in range(K):
    print(res[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()))

if x>100:
  a.sort()
  a.reverse()
  a=a[0:50]

if y>100:
  b.sort()
  b.reverse()
  b=b[0:100]

if z>100:
  c.sort()
  c.reverse()
  c=c[0:100]

lena=len(a)
lenb=len(b)
lenc=len(c)
  
ansList=[]
for m in range(lena):
  for n in range(lenb):
    for o in range(lenc):
      ansList.append(a[m]+b[n]+c[o])

ansList.sort()
ansList.reverse()

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

Submission status: Wrong Answer

Solution code:
from heapq import heappop, heappush, heappushpop


def main():
    x, y, z, k = map(int, input().split())
    aa = sorted(map(int, input().split()))
    bb = sorted(map(int, input().split()))
    cc = sorted(map(int, input().split()))

    q = [(-aa[-1] - bb[-1] - cc[-1], (len(aa) - 1, len(bb) - 1, len(cc) - 1))]
    heap = []
    ts = set()
    while len(q) > 0:
        v, (i_aa, i_bb, i_cc) = q[0]
        v = -v
        q = q[1:]

        if len(heap) < k:
            heappush(heap, v)
        else:
            if v > heap[0]:
                heappushpop(heap, v)
            else:
                break

        t = (i_aa - 1, i_bb, i_cc)
        if i_aa > 0 and not t in ts:
            heappush(q, (-aa[i_aa - 1] - bb[i_bb] - cc[i_cc], t))
            ts.add(t)

        t = (i_aa, i_bb - 1, i_cc)
        if i_bb > 0 and not t in ts:
            heappush(q, (-aa[i_aa] - bb[i_bb - 1] - cc[i_cc], t))
            ts.add(t)

        t = (i_aa, i_bb, i_cc - 1)
        if i_cc > 0 and not t in ts:
            heappush(q, (-aa[i_aa] - bb[i_bb] - cc[i_cc - 1], t))
            ts.add(t)

    for v in sorted(heap, reverse=True):
        print(v)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

ans = []

AA = sorted(A, key=lambda a: -a)
BB = sorted(B, key=lambda a: -a)
CC = sorted(C, key=lambda a: -a)
for a in AA:
    for b in BB:
        for c in CC:
            if len(ans) > 1000000:
                for an in sorted(ans, key=lambda p: -p)[:K]:
                    print(an)
                    exit()
            ans.append(a+b+c)

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

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 = list(reversed(sorted(A)))
B = list(reversed(sorted(B)))
C = list(reversed(sorted(C)))

Atmp = [A[0]]
Btmp = [B[0]]
Ctmp = [C[0]]

x, y, z = 1, 1, 1
while x*y*z < 3000 and x*y*z < X*Y*Z:
    l = [0, 0, 0]
    if (x < X):
        l[0] = A[x]
    if (y < Y):
        l[1] = B[y]
    if (z < Z):
        l[2] = C[z]
    maxi = 0
    maxl = 0
    for i in range(len(l)):
        if (l[i] > maxl):
            maxi = i
            maxl = l[i]
    if (maxi == 0):
        Atmp.append(maxl)
        x += 1
    elif (maxi == 1):
        Btmp.append(maxl)
        y += 1
    elif (maxi == 2):
        Ctmp.append(maxl)
        z += 1

ansl = []
for a in Atmp:
    for b in Btmp:
        for c in Ctmp:
            ansl.append(a+b+c)
ansl = list(reversed(sorted(ansl)))

#print(Atmp)
#print(Btmp)
#print(Ctmp)
#print(ansl)

for i in range(K):
    print(ansl[i])
    pass

Submission status: Wrong Answer

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

x,y,z,K=rl()
A=rl()
B=rl()
C=rl()
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
X=[]
for a,b,c in zip(A,B,C):
    X.append([a,0])
    X.append([b,1])
    X.append([c,2])
X.sort(reverse=True)

ca=0
cb=0
cc=0
xl = len(X)
if x*y*z>=1000000:
    for i in range(len(X)):
        _,a = X[i]
        if a == 0:
            ca += 1
        elif a == 1:
            cb += 1
        else:
            cc += 1 
        if ca*cb*cc>=1000000:
            xl=i
            break
else:
    ca=x
    cb=y
    cc=z

ans = []
import itertools
for a,b,c in itertools.product(A[:ca],B[:cb],C[:cc]):
    ans.append(a+b+c)
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
xyzk = input().split('\n')[0].split()
a = input().split('\n')[0].split()
b = input().split('\n')[0].split()
c = input().split('\n')[0].split()
for i in range(0,len(a)):
    a[i] = int(a[i])
for i in range(0,len(b)):
    b[i] = int(b[i])
for i in range(0,len(c)):
    c[i] = int(c[i])
for i in range(0,len(xyzk)):
    xyzk[i] = int(xyzk[i])
p=[]
for i in a:
    for j in b:
        for k in c:
            p.append(i+j+k)
p = sorted(p,reverse=True)
print(p[0:xyzk[3]])

Submission status: Wrong Answer

Solution code:
xyzk_, a_, b_, c_ = [input() for _ in range(4)]

x, y, z, k = [int(w) for w in xyzk_.split()]
a_nums = [int(n) for n in a_.split()]
b_nums = [int(n) for n in b_.split()]
c_nums = [int(n) for n in c_.split()]

while (len(a_nums) - 1) * (len(b_nums) - 1) * (len(c_nums) - 1) >= k:
    m = min(min(a_nums), min(b_nums), min(c_nums))
    if m in a_nums:
        a_nums.remove(m)
    if m in b_nums:
        b_nums.remove(m)
    if m in c_nums:
        c_nums.remove(m)


sums = []
for a in a_nums:
    for b in b_nums:
        for c in c_nums:
            sums.append(a + b + c)

sums.sort(reverse=True)

for n in sums[:k]:
    print(n)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy

limit = 56

x,y,z,k = map(int, input().split(" "))

acake= [int(e) for e in input().split(" ")]
bcake= [int(e) for e in input().split(" ")]
ccake= [int(e) for e in input().split(" ")]

acake.sort(reverse = True)
bcake.sort(reverse = True)
ccake.sort(reverse = True)

maxnum = max(acake[-1] , bcake[-1] ,acake[-1])

if acake[0] == maxnum:
    alimit = 1000
    blimit = limit
    climit = limit
elif bcake[0] == maxnum:
    blimit = 1000
    alimit = limit
    climit = limit
else:
    climit = 1000
    blimit = limit
    alimit = limit

if x*y*z < 3000:
    alimit = x+1
    blimit = y+1
    climit = z+1

pre_result = numpy.array(list(itertools.product(acake[0:alimit],bcake[0:blimit],ccake[0:climit])),dtype=numpy.int64)

result = numpy.sort(numpy.sum(pre_result,axis=1))[::-1]

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

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import itertools
x,y,z,k = map(int,input().split())

ls = []

for i in range(3):
    s = sorted(list(map(int,input().split())),reverse=True)
    ls.append(s)
#print (ls)
ptr = [1] * 3


cr = min(3000,k)
while(ptr[0]*ptr[1]*ptr[2]<cr):
    max_p = 0
    for j in range(3):
        p = 1
        for i in range(3):
            if j != i:
                p *= ls[i][0]
            else:
                if len(ls[i]) > ptr[i]:
                    p *= ls[i][ptr[i]]
                else:
                    p = 0
        #print (j,i,p)
        if max_p < p:
            max_p = p
            argmax_p = j
    ptr[argmax_p] += 1
    #print (ptr)
#print (ptr)
#print (ls)
for i in range(3):
    ls[i] = ls[i][:ptr[i]]
#print (ls)
product = list(itertools.product(*ls))
sm = sorted([sum(p) for p  in product],reverse=True)
for i in range(k):
    print (sm[i])

Submission status: Wrong Answer

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

x,y,z,K=rl()
A=rl()
B=rl()
C=rl()
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
X=[]
for a,b,c in zip(A,B,C):
    X.append([a,0])
    X.append([b,1])
    X.append([c,2])
X.sort(reverse=True)

ca=0
cb=0
cc=0
xl = len(X)
if x*y*z>=30000:
    for i in range(len(X)):
        _,a = X[i]
        if a == 0:
            ca += 1
        elif a == 1:
            cb += 1
        else:
            cc += 1 
        if ca*cb*cc>=30000:
            xl=i
            break
else:
    ca=x
    cb=y
    cc=z

ans = []
import itertools
for a,b,c in itertools.product(A[:ca],B[:cb],C[:cc]):
    ans.append(a+b+c)
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
from itertools import*
x,y,z,k=map(int,input().split())
a=set(map(int,input().split()))
b=set(map(int,input().split()))
c=set(map(int,input().split()))
#print(a,b,c)
for e in sorted(sum(i)for i in product(a,b,c))[::-1][:k]:
    print(e)

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()
a.reverse()
b.sort()
b.reverse()
c.sort()
c.reverse()
ans=[]
if x*y*z<=3000:
  for i in range(x):
    for j in range(y):
      for h in range(z):
        ans.append(a[i]+b[j]+c[h])
  ans.sort()
  ans.reverse()
  for i in range(k):
    print(ans[i])
  exit()
p=0
q=0
r=0
a1=0
b1=0
c1=0
while (p+1)*(q+1)*(r+1)<k+1000:
  if p+1<len(a):
      a1=a[0]-a[p+1]
  else:
    a1=10**18
  if q+1<len(b):
      b1=b[0]-b[q+1]
  else:
    b1=10**18
  if r+1<len(c):
      c1=c[0]-c[r+1]
  else:
    c1=10**18
  if a1==min(a1,b1,c1) and p+1<len(a):
    p+=1
  elif b1==min(a1,b1,c1) and q+1<len(b):
    q+=1
  elif c1==min(a1,b1,c1) and r+1<len(c):
    r+=1
  else:
    if p+1<len(a):
      p+=1
    if q+1<len(b):
      q+=1
    if r+1<len(c):
      r+=1
for i in range(p+1):
  for j in range(q+1):
    for h in range(r+1):
      ans.append(a[i]+b[j]+c[h])
ans.sort()
ans.reverse()
for i in range(k):
  print(ans[i])

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

X, Y, Z, K = LI()
A = sorted(LI(), reverse=True)
B = sorted(LI(), reverse=True)
C = sorted(LI(), reverse=True)
ABC = A+B+C
ABC = sorted(ABC, reverse=True)
#  print(ABC)
a,b,c = [],[],[]
abc = 0
while not(len(a) >= min(100, X) and len(b) >= min(100, Y) and len(c) >= min(100, Z)):
    if A:
        if ABC[abc]in A:
            a.append(ABC[abc])
            A.remove(ABC[abc])
    if B:
        if ABC[abc]in B:
            b.append(ABC[abc])
            B.remove(ABC[abc])
    if C:
        if ABC[abc]in C:
            c.append(ABC[abc])
            C.remove(ABC[abc])
    abc+=1
#  for abc in range(min(200, X+Y+Z)):

#      if ABC[abc]in A:
#          a.append(ABC[abc])
#          A.remove(ABC[abc])
#      if ABC[abc]in B:
#          b.append(ABC[abc])
#          B.remove(ABC[abc])
#      if ABC[abc]in C:
#          c.append(ABC[abc])
#          C.remove(ABC[abc])
#  print(a,b,c)

points = []
for i in a:
    for j in b:
        for k in c:
            points.append(i+j+k)


#  A = A[:min(250, X)]
#  B = B[:min(250, Y)]
#  C = C[:min(250, Z)]
#  # Aの中で最大の数字足すBの最大、Cの最大は全体の中で最大
#  # 3000個大きい順に求めれば良い

#  # iが決まれば、j,kのおおきさは分かる
#  BC = []
#  # 1000*1000 で10**6の計算量
#  #  for j in range(len(B)):
#  #      for k in range(len(C)):
#  #          BC.append(B[j] + C[k])

#  points = []
#  # 10**3 と 10** 6
#  #  for i in range(len(A)):
#  #      points += [bc + A[i] for bc in BC]
#  for i in range(len(A)):
#      #  for bc in BC:
#      #      points.append(A[i]+bc)
#      for j in range(len(B)):
#          for k in range(len(C)):
#              points.append(A[i] + B[j] + C[k])
for i in sorted(points, reverse=True)[:K]:
    print(i)

Submission status: Wrong Answer

Solution code:
import bisect

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

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
sum_count = []      
k = 0
for x in range(X):
    if k==1:
        break
    if x>500 and (A[x]<B[Y-1] or A[x]<C[Z-1]):
        break
    for y in range(Y):
        if k==1:
            break
        if x+y>1000 and (B[y]<A[X-1] or B[y]<C[Z-1]):
            k=1
            break
        for z in range(Z):
            if x+y+z>1500 and (C[z]<A[X-1] or C[z]<B[Y-1]):
                k=1
                break
            sum_count.append(A[x]+B[y]+C[z])

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