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: Runtime Error

Solution code:
x,y,z,k=map(int,input().split())
*a,=map(int,input().split())
*b,=map(int,input().split())
*c,=map(int,input().split())
 
def merge_sort(array):
    if len(array) <= 1:
        return array
    cnt=len(array)//2
    left=array[:cnt]
    right=array[cnt:]
    left = merge_sort(left)
    right = merge_sort(right)
    return merge(left, right)

def merge(left, right):
    array = [0]*3000
    l,r,ind=0,0,0
    while l < len(left) and r < len(right):
        if left[l] >= right[r]:
            array[ind]=left[l]
            l+=1
            ind+=1
        else:
            array[ind]=right[r]
            r+=1
            ind+=1
        if ind>=3000:
            return array
    if l < len(left):
        return array[:ind]+left[l:3000-ind+l]
    if r < len(right):
        return array[:ind]+right[r:3000-ind+r]

a=merge_sort(a)
b=merge_sort(b)
c=merge_sort(c)
l,r=[],[]
for i in a:
    for j in b:
    l.append(i+j)
l=merge_sort(l)
for i in l:
    for j in c:
    r.append(i+j)
r=merge_sort(r)
for i in range(k):
    print(r[i])

Submission status: Runtime Error

Solution code:
X,Y,Z,K=map(int,input().split())
A=map(int,input().split())
B=map(int,input().split())
C=map(int,input().split())
list(A).sort(reverse=True)
list(B).sort(reverse=True)
list(C).sort(reverse=True)
s=[]
ss=[]
count=0
mx=0
for i in A:
    for j in B:
        s+=[i+j]
s=s[:K]
s.sort(reverse=True)
for i in C:
    for j in s:
        ss+=i+j

ss.sort(reverse=True)


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

Submission status: Runtime Error

Solution code:
# coding: utf-8
import math 

N = int(input())
abcde = [int(input()) for _ in range(5)]

time = 0
n = N
last = 0 # 最後の1回で移動する人数
for i in range(5):
  time +=  math.ceil(n / abcde[i])
  last = n % abcde[i]
  if last == 0:
    last = abcde[i]
  if i < 4: 
    n = last + max((N-last) - (time-1) * abcde[i+1], 0)


print(time)

Submission status: Runtime Error

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a = IR(5)
    k = II()
    if max(a) - min(a) > k:
        print(":(")
    else:
        print("Yay!")
    return

#B
def B():
    a = IR(5)
    b = a[0]
    ans = 0
    for a_ in a:
        if a_ % 10 != 0:
            if b % 10> a_ % 10:
                b = a_
    flg = 0
    for a_ in a:
        if a_ != b or flg:
            ans += math.ceil(a_ / 10) * 10
        else:
            ans += b
            flg = 1
    print(ans)
            
    
    return

#C
def C():
    n = II()
    ai = IR(5)
    print(math.ceil(n / min(ai)) + 4)
        
        
    return

#D
def D():
    x, y, z, K = LI()
    a = LI()
    a.sort(reverse=True)
    b = LI()
    b.sort(reverse = True)
    c = LI()
    c.sort(reverse=True)
    ab = []
    for a_ in a:
        for b_ in b:
            ab.append(a_ + b_)
    ab.sort(reverse = True)
    ab = ab[:min(x+y,K)]
    ans = []
    for ab_ in ab:
        for c_ in c:
        ans.append(ab_ + c_)
    ans.sort(reverse = True)
    for k in range(K):
        print(ans[k])



        
                    

    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Runtime Error

Solution code:
x, y, z, k = map(int, input().split())
m = []
for _ in range(3):
    m.append(sorted(list(map(int, input().split())), reverse=True))

def sorted_sum(list_a, list_b, limit):
    s = []
    for x in list_a:
        for y in list_b:
            s.append(x + y)
    return sorted(s[0:limit], reverse=True)


def consume_diff(s, a_val, list_b, b_index):
    diff = a_val - list_b[b_index]
    for i in range(b_index + 1, len(list_b)):
        if list_b[b_index] - list_b[i] > diff:
            break
        s.append(a_val + list_b[i])



ans = sorted_sum(sorted_sum2(m[0], m[1], k), m[2], k)
for i in range(min([k, len(ans)])):
    print(ans[i])

Submission status: Runtime Error

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

v = []
count = 0


for i in range(x):
    for j in range(y):
        v.append(a[i]+b[j])

v = sorted(v, reverse=True)
c = sorted(c, reverse=True)

vv = []
l = len(v)
if k > l: l=k
for i in range(l):
    for j in range(z):
        vv.append(v[i]+c[j])

vv = sorted(vv, reverse=True)

for i in vv[0:k]:
    print(i)

Submission status: Runtime Error

Solution code:
import numpy as np
from collections import deque
import bisect

X,Y,Z,K=map(int,input().split())
A=sorted([int(i) for i in input().split()],reverse=True)
B=sorted([int(i) for i in input().split()],reverse=True)
C=sorted([int(i) for i in input().split()],reverse=True)
Amax,Bmax,Cmax=(max(j) for j in [A,B,C])
Umami=Amax+Bmax+Cmax
Adif=[abs(i-Amax) for i in A]
Bdif=[abs(x-Bmax) for x in B]
Cdif=[abs(p-Cmax) for p in C]#AdifBdifCdifから1個ずつ選んだ和を小さい方から3000個
rank3000=100000000#暫定3000位のやつ
visited=np.zeros((1000,1000,1000),dtype="int")#Ai,Bj,Ckの行ったやつ
queue=deque()
queue.append([0,0,0])
ranking=[]
ranked=0#3000枠埋まったら1になる
Powerful=0
while queue and Powerful ==0:
    a,b,c = queue.popleft()
    for j, k ,l in ([1,0,0],[0,1,0],[0,0, 1]):
        new_a, new_b, new_c = a+j,b+k,c+l
        rankin=0
        if 0<=a<X and 0<=b<Y and 0<=c<Z and  visited[new_a][new_b][new_c]==0:
            visited[new_a][new_b][new_c]=1
            queue.append([new_a,new_b,new_c])
            if Adif[a]+Bdif[b]+Cdif[c]<rank3000:
                rankin+=1
                ranking.append(Adif[a]+Bdif[b]+Cdif[c])
                if ranked==0:
                    if len(ranking)==K:
                        ranked=1
                ranking.sort()
                if ranked==1:
                    ranking.pop(-1)
                    rank3000=ranking[-1]
            if rankin==0:
                Powerful=1
                break
print(ranking)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import operator

di = {}

for i, (a, b, c) in enumerate(zip(a_, b_, c_)):
    di['a{}'.format(i)] = a
    di['b{}'.format(i)] = b
    di['c{}'.format(i)] = c

if len(di) > 3000:
    di = sorted(di.items(), reverse=True, key=operator.itemgetter(1))
    di = di[:3000]


a_li = []
b_li = []
c_li = []

for key, value in di.items():
    if 'a' in key:
        a_li.append(value)
    elif 'b' in key:
        b_li.append(value)
    elif 'c' in key:
        c_li.append(value)

ans = []
for a in a_li:
    for b in b_li:
        for c in c_li:
            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: Runtime Error

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 = sorted(a)
b = sorted(b)
c = sorted(c)

la = []

for i in range(x):
    for n in range(max(y-3000//(i+1),0),y):
        for m in range(max(z-3000//((i+1)*(k+1)),0),z):
            la.append(a[i]+b[n]+c[m])

la = sorted(la)

for i in range(k):
    print(la[-i-1])

Submission status: Runtime Error

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)

kouho = set()
done = set()


def f(t):
    x, y, z = t
    return A[x] + B[y] + C[z]


def main():
    start = (f((0, 0, 0)), (0, 0, 0))
    kouho.add(start)
    done.add(start)

    for k in range(K):
        d = max(kouho)
        kouho.remove(d)

        x, y, z = d[1]
        toadd = [(x, y, z+1), (x, y+1, z), (x+1, y, z)]
        for ta in toadd:
            t = (f(ta), ta)
            if ta[0] == X:
                continue
            if ta[1] == Y:
                continue
            if ta[2] == Z:
                continue
            if t in done:
                continue
            kouho.add(t)

        print(d[0])


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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)
s = {(a[0] + b[0] + c[0], 0, 0, 0)}
while k >= 0:
  ne = []
  for e in s:
    print(e[0])
    ne.append(e)
    if e[1] < len(a) - 1:
    	ne.append((e[0] - a[e[1]] + a[e[1] + 1], e[1] + 1, e[2], e[3]))
    if e[2] < len(b) - 1:
    	ne.append((e[0] - b[e[2]] + b[e[2] + 1], e[1], e[2] + 1, e[3]))
    if e[3] < len(c) - 1:
    	ne.append((e[0] - c[e[3]] + c[e[3] + 1], e[1], e[2], e[3] + 1))
    break
  s.remove(ne[0])
  for tup in ne[1:]:
    s.add(tup)
  k -= 1

Submission status: Runtime Error

Solution code:
XYZK=list(map(int, input().split()))
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))
X=XYZK[0]
Y=XYZK[1]
Z=XYZK[2]
K=XYZK[3]

#2段階でソート
AB=[]
for i in range(X):
  for j in range(Y):
    AB.append(A[i]+B[j])
AB.sort(reverse=True)
AB=AB[0:K]

ABC=[]
for i in range(K):
  for j in range(Z):
    ABC.append(AB[i]+C[j])
ABC.sort(reverse=True)
for i in range(K):
  print(int(ABC[i]))

Submission status: Runtime Error

Solution code:

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.TreeSet;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws FileNotFoundException {
		// TODO Auto-generated method stub
		// setOut();

		int a = ni();
		int b = ni();
		int c = ni();
		int d = ni();
		long[] ar = nl(a);
		long[] br = nl(b);
		long[] cr = nl(c);

		List<Long> res = (solve(d, ar, br, cr));
		Collections.sort(res);
		Collections.reverse(res);
		for(int i=0;i<d;i++) {
			System.out.println(res.get(i));
		}

	}

	private static long[] nl(int c) {
		long[] res = new long[c];
		for (int i = 0; i < c; i++)
			res[i] = sc.nextLong();

		return res;
	}

	private static List<Long> solve(int d, long[] ar, long[] br, long[] cr) {
		// TODO Auto-generated method stub

		TreeSet<Long> s = new TreeSet<Long>(new Comparator<Long>() {

			@Override
			public int compare(Long o1, Long o2) {
				// TODO Auto-generated method stub
	               if(o1>o2)
	                	return 1;
	                else
	                	return -1;

			}
			
		});
		List<Long> res = new ArrayList<Long>();

		for (long a : ar) {
			for (long b : br) {
				for (long c : cr) {
					long max = a + b + c;
					if (s.size() < d) {
						s.add(max);
					} else {
						long k = s.first();

						if(max>k) {
							s.add(max);
			
						}
						
					}
				}
			}
		}
		res.addAll(s);
		return res;
	}

	private static void out(long[] cr) {
		// TODO Auto-generated method stub
		for(long l:cr)
			System.out.print(l+" ");
		System.out.println();
		
	}

	private static void out(int[][] dist2) {
		// TODO Auto-generated method stub
		for (int[] i : dist2) {
			for (int j : i) {
				System.out.print(j + " ");
			}
			out("");
		}

	}

	private static void setOut() throws FileNotFoundException {
		sc = new Scanner(new FileInputStream("in.txt"));
		System.setOut(new PrintStream(new FileOutputStream("out.txt")));

	}

	private static void out(char[][] b) {
		// TODO Auto-generated method stub
		for (char[] c : b) {
			out(c);
		}

	}

	private static void out(char[] c) {
		// TODO Auto-generated method stub
		for (char cc : c)
			System.out.print(cc + " ");
		System.out.println();
	}

	private static void out(int[] b) {
		// TODO Auto-generated method stub
		for (int i : b)
			System.out.print(i + " ");
		System.out.println();

	}

	public static void out(String str) {

		System.out.println(str);
	}

	public static void out(int str) {

		System.out.println(str);
	}

	public static int ni() {

		return sc.nextInt();

	}

	public static String ns() {

		return sc.next();
	}

	public static int[] ni(int k) {
		int[] res = new int[k];
		for (int i = 0; i < k; i++)
			res[i] = sc.nextInt();

		return res;
	}

	public static int[][] ni(int a, int b) {
		int[][] res = new int[a][b];
		for (int i = 0; i < a; i++)
			for (int j = 0; j < b; j++)
				res[i][j] = sc.nextInt();
		sc.next();
		return res;
	}
}

Submission status: Runtime Error

Solution code:
import bisect

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

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
sum_AB = []
k = 0
for x in range(X):
    for y in range(Y):
        sum_AB.append(A[x]+B[y])
sum_AB.sort(reverse=True) #10**6
sum_count = []
for z in range(Z):
    for xy in range(K):
        sum_count.append(C[z]+sum_AB[xy])


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

Submission status: Runtime Error

Solution code:
from itertools import chain
def func1(A,B,C):
    s = A[0]+B[0]+C[0]
    X = func3(A,s)
    Y = func3(B,s)
    Z = func3(C,s)
    return sorted(chain(X,Y,Z,func2(X,Y,s), func2(Y,Z,s), func2(Z,X,s)))
import numpy as np
def diff(W):
    W = np.array(W)
    return W[:-1]-W[1:]
def func2(X,Y,b):
    for x in X:
        for y in Y:
            a = x+y
            if a>b:
                break
            yield x+y
def func3(W,s):
    w = 0
    for i in W:
        w += i
        if w >s:
            break
        yield w

*_,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)

def func(base, Ad,Bd,Cd):
    yield base
    while True:
        for d in func1(Ad, Bd, Cd):
            yield base - d
        a,*Ad = Ad
        b,*Bd = Bd
        c,*Cd = Cd
        base -= (a+b+c)
for i,t in enumerate(func(A[0]+B[0]+C[0], diff(A), diff(B), diff(C))):
    if i <k:
        print(t)
    else:
        break

Submission status: Runtime Error

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)

p, q, r = 0, 0, 0
now = a_nums[p] + b_nums[q] + c_nums[r]

while (p + 1) * (q + 1) * (r + 1) < k:
    pp = a_nums[p + 1] + b_nums[q] + c_nums[r]
    qq = a_nums[p] + b_nums[q + 1] + c_nums[r]
    rr = a_nums[p] + b_nums[q] + c_nums[r + 1]
    if pp >= max(qq, rr):
        p += 1
    elif qq >= rr:
        q += 1
    else:
        r += 1

a_nums = a_nums[:p + 1]
b_nums = b_nums[:q + 1]
c_nums = c_nums[:r + 1]
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: Runtime Error

Solution code:
import bisect

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

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
sum_AB = []
k = 0
for x in range(X):
    for y in range(Y):
        sum_AB.append(A[x]+B[y])
sum_AB.sort(reverse=True) #10**6
sum_count = []
for z in range(Z):
    for xy in range(3000):
        sum_count.append(C[z]+sum_AB[xy])


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

Submission status: Runtime Error

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

Submission status: Runtime Error

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)

kouho = set()
done = set()


def f(t):
    x, y, z = t
    return A[x] + B[y] + C[z]


def main():
    kouho.add([f(0, 0, 0), (0, 0, 0)])

    for k in range(K):
        d = max(kouho)
        kouho.remove(d)

        x, y, z = d[1]
        toadd = [(x, y, z+1), (x, y+1, z), (x+1, y, z)]
        for ta in toadd:
            if ta[0] == X:
                continue
            if ta[1] == Y:
                continue
            if ta[2] == Z:
                continue
            kouho.add([f(ta), ta])

        print(d[0])


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

def merge_sort(array):
    if len(array) <= 1:
        return array
    cnt=len(array)//2
    left=array[:cnt]
    right=array[cnt:]
    left = merge_sort(left)
    right = merge_sort(right)
    return merge(left, right)


def merge(left, right):
    array = [0]*3000
    l,r,ind=0,0,0
    if right[0]<left[-1]:
        return left
    while l < len(left) and r < len(right):
        if left[l] >= right[r]:
            array[ind]=left[l]
            l+=1
            ind+=1
        else:
            array[ind]=right[r]
            r+=1
            ind+=1
        if ind>=3000:
            return array
    if l < len(left):
        return array[:ind]+left[l:]
    if r < len(right):
        return array[:ind]+right[r:]

a=merge_sort(a)
b=merge_sort(b)
c=merge_sort(c)
l,r=[],[]
for i in a:
  for j in b:
    l.append(i+j)
l=merge_sort(l)
for i in l:
  for j in c:
    r.append(i+j)
r=merge_sort(r)
for i in range(k):
    print(r[i])

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
x, y, z, k = map(int, input().split())
A = list(map(int, input().split())).sort(reverse=True)
B = list(map(int, input().split())).sort(reverse=True)
C = list(map(int, input().split())).sort(reverse=True)
D = []
E = []
for b in B:
    for c in C:
        D.append(b+c)
D.sort(reverse=True)
for a in A:
    for d in D[:k]:
       E.append(a+d)
E.sort(reverse=True)
for e in E[:k]:
    print(e)

Submission status: Runtime Error

Solution code:
X,Y,Z,K = (int(i) for i in input().split())
A = input().split()
listA = [int(a) for a in A]
B = input().split()
listB = [int(b) for b in B]
C = input().split()
listC = [int(c) for c in C]

listA = sorted(listA,reverse = True)
listB = sorted(listB,reverse = True)
listC = sorted(listC,reverse = True)
kouholist = [[listA[0] + listB[0] + listC[0] ,0,0,0]]
for i in range(K):
    kouholist.sort().reverse()
    print(kouholist[0][0])
    if kouholist[0][1] < X - 1:
        kouholist.append([listA[kouholist[0][1] + 1] + listB[kouholist[0][2]] + listC[kouholist[0][3]],kouholist[0][1] + 1,kouholist[0][2],kouholist[0][3]])
        
    if kouholist[0][2] < Y - 1:
        kouholist.append([listA[kouholist[0][1]] + listB[kouholist[0][2] + 1] + listC[kouholist[0][3]],kouholist[0][1],kouholist[0][2] + 1,kouholist[0][3]])
       
    if kouholist[0][3] < Z - 1:
        
        kouholist.append([listA[kouholist[0][1]] + listB[kouholist[0][2]] + listC[kouholist[0][3] + 1],kouholist[0][1],kouholist[0][2],kouholist[0][3] + 1])
    kouholist.pop()

Submission status: Runtime Error

Solution code:
import unittest
import abc123d as tester

def ioByFile(fn='inputFile.txt'):
	with open(fn) as f:
		for line in f:
			yield line

def getCorrect(fn='correct.txt'):
	with open(fn) as f:
		return f.read()

class InputTests(unittest.TestCase):
	def _calFUT(self, io):
		return str(tester.main(io))+'\n'
		
	def test_it(self):
		testInput=ioByFile()
		io=lambda : next(testInput)
		actual = self._calFUT(io)
		
		self.assertEqual(actual,getCorrect())

if __name__ == "__main__":
	unittest.main()

Submission status: Runtime Error

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

X,Y,Z,K = (int(i) for i in input().split())
ax = [int(i) for i in input().split()]
by = [int(i) for i in input().split()]
cz = [int(i) for i in input().split()]
ans = [0] * min(3000,X*Y*Z)
cnt = 0
for i in ax:
  for j in by:
    for k in cz:
      ans[cnt] = i + j + k
      cnt += 1
ans.sort(reverse=True)
for i in range(K):
  print(ans[i])

Submission status: Runtime Error

Solution code:
from heapq import heappush, heappop


def solve(X, Y, Z, K, As, Bs, Cs):
    As.sort()
    Bs.sort()
    Cs.sort()
    ADs = [a2 - a1 for a1, a2 in zip(As, As[1:])][::-1]
    BDs = [a2 - a1 for a1, a2 in zip(Bs, Bs[1:])][::-1]
    CDs = [a2 - a1 for a1, a2 in zip(Cs, Cs[1:])][::-1]

    m = As[-1] + Bs[-1] + Cs[-1]
    h = []
    ans = [m]
    heappush(h, (ADs[0], (0, -1, -1)))
    heappush(h, (BDs[0], (-1, 0, -1)))
    heappush(h, (CDs[0], (-1, -1, 0)))
    taken = set()
    
    for i in range(K - 1):
        p, stacks = heappop(h)
        while (p, stacks) in taken:
            p, stacks = heappop(h)
        taken.add((p, stacks))
        ans.append(m - p)

        if stacks[0] + 1 < len(ADs):
            heappush(h, ((p + ADs[stacks[0] + 1]), (stacks[0] + 1, stacks[1], stacks[2])))
        if stacks[1] + 1 < len(BDs):
            heappush(h, ((p + BDs[stacks[1] + 1]), (stacks[0], stacks[1] + 1, stacks[2])))
        if stacks[2] + 1 < len(CDs):
            heappush(h, ((p + CDs[stacks[2] + 1]), (stacks[0], stacks[1], stacks[2] + 1)))

    return "\n".join([str(a) for a in ans])


if __name__ == "__main__":
    X, Y, Z, K = tuple(map(int, input().split(" ")))
    As = list(map(int, input().split(" ")))
    Bs = list(map(int, input().split(" ")))
    Cs = list(map(int, input().split(" ")))
    print(solve(X, Y, Z, K, As, Bs, Cs))

Submission status: Runtime Error

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)

li=[]
dp=[[0 for i in range(3)] for j in range(5)]


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

w=0
for l in range(k):
    maxtemp=0
    for i in range(len(li)):

        
        for j2 in range(z):
            if dp[i][j2]==0:
                con=li[i]+c[j2]
                
                if con>maxtemp:
                    x1=i
                    y1=j2
                    maxtemp=con
                break
    

    dp[x1][y1]=l+1
    
    print(maxtemp)

Submission status: Runtime Error

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

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

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

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

def get_c(aa,ab,ac, amm):
	if ac < amm[2]-1:
		ret=[[aa,ab,ac+1]]
	else:
		ret=[]
		
	if ab<amm[1]-1:# and ab >= ac:
		ret.append([aa,ab+1,ac])
	
	if aa<amm[0]-1:# and aa >= ab and aa >= ac:
		ret.append([aa+1,ab,ac])
	return ret
	
def gv(al,bl,cl,s):
	return al[s[0]]+bl[s[1]]+cl[s[2]]
	
def main(io):
	x,y,z,k=map(int, io().split())
	ml=[x,y,z]
	al =list(map(int, io().split()))
	al.sort(reverse=True)
	bl =list(map(int, io().split()))
	bl.sort(reverse=True)
	cl =list(map(int, io().split()))
	cl.sort(reverse=True)
	init=[0,0,0]
	ggv=lambda l : gv(al,bl,cl,l)
	
	qq = []
	heappush(qq,Foo(ggv(init), init))
	
	ol=set()
	ol.add(init)
	
	for _ in range(k):
		ff=heappop(qq)
		vv=ff.value
		cs=ff.state
		nc=get_c(cs[0],cs[1],cs[2],ml)
		print(vv)
		for ns in nc:
			if ns in ol:
				continue
			else:
				heappush(qq, Foo(ggv(ns), ns))
				ol.add(ns)
	return 1

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

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

Submission status: Runtime Error

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

#input
import numpy as np
import sys
sys.setrecursionlimit(10**10) 
[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()))

D = []
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

#make list
memo = np.zeros((X,Y,Z))
for i in range(min(K,X)):
    for j in range(min((K//(i+1))+1,Y)):
        for k in range(min(((K//(i+1))+1)//(j+1),Z)):
            if memo[i][j][k] != 0:
                continue
            else:
                memo[i][j][k] = A[i]+B[j]+C[k]
                D.append(memo[i][j][k])
D.sort(reverse=True)
for i in range(K):
    print(int(D[i]))

Submission status: Runtime Error

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

AB = []
for i in range(X):
    for j in range(Y):
        AB.append(A[i] + B[j])
AB.sort()
C.sort()

def n_above(val):
    cnt = 0
    for c in C:
        cnt += len(AB) - bisect_left(AB, val - c)
    return cnt

l = AB[0] + C[0]
r = AB[-1] + C[-1]
while r - l > 1:
    m = (l + r) // 2
    if n_above(m) >= K:
        l = m
    else:
        r = m

ans = []
for c in C:
    ans += [ab + c for ab in AB[bisect_left(AB, m - 1 - c):]]
ans.sort(reverse = True)
for i in range(K):
    print(ans[i])

Submission status: Runtime Error

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

#input
import numpy as np
import sys
sys.setrecursionlimit(10**6) 
[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()))

D = []
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

#make list
memo = np.zeros((X,Y,Z))
for i in range(min(K,X)):
    for j in range(min((K//(i+1))+1,Y)):
        for k in range(min(((K//(i+1))+1)//(j+1),Z)):
            if memo[i][j][k] != 0:
                continue
            else:
                memo[i][j][k] = A[i]+B[j]+C[k]
                D.append(memo[i][j][k])
D.sort(reverse=True)
for i in range(K):
    print(int(D[i]))