Buggy python submission (verdict: Runtime Error):
/*
g++ main.cpp --std=c++14; ./a.out < input.txt
*/
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<tuple>

using namespace std;

const auto mod = 1000000007L;

typedef long long ll;

template<typename T>
using V = vector<T>;

template<typename K, typename V>
using M = map<K,V>;

ll sum(tuple<ll,ll,ll> const & t, V<ll> const & A, V<ll> const & B, V<ll> const & C) {
        auto a = get<0>(t);
        auto b = get<1>(t);
        auto c = get<2>(t);
        return A[a]+B[b]+C[c];
}

int main() {
    int X,Y,Z,K;
    cin>>X>>Y>>Z>>K;
    auto A=V<ll>(X);
    for(size_t i = 0; i < X; i++)cin>>A[i];
    sort(A.begin(), A.end(), [](auto a, auto b){return a>b;});
    auto B=V<ll>(Y);
    for(size_t i = 0; i < Y; i++)cin>>B[i];
    sort(B.begin(), B.end(), [](auto a, auto b){return a>b;});
    auto C=V<ll>(Z);
    for(size_t i = 0; i < Z; i++)cin>>C[i];
    sort(C.begin(), C.end(), [](auto a, auto b){return a>b;});
    auto Q=multimap<ll, tuple<ll, ll, ll>, greater<ll>>();
    Q.insert(decltype(Q)::value_type(sum(make_tuple(0,0,0), A, B, C), make_tuple(0,0,0)));
    for(size_t k = 0; k < K; k++)
    {
        auto t = Q.begin();
        cout << t->first << "\n";
        auto a = get<0>(t->second);
        auto b = get<1>(t->second);
        auto c = get<2>(t->second);
        Q.erase(t) ;
        auto d=make_tuple(a, b, c+1);
        if (c+1<X) Q.insert(decltype(Q)::value_type(sum(d, A, B, C), d));
        auto e=make_tuple(a, b+1, c);
        if (c+1<Y) Q.insert(decltype(Q)::value_type(sum(e, A, B, C), e));
        auto f=make_tuple(a+1, b, c);
        if (c+1<Z) Q.insert(decltype(Q)::value_type(sum(f, A, B, C), f));
    }
}

Fixed submission:
"""
python3 main.py < input.txt
"""
import math
import itertools as it
import heapq

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

def evaluate(x,y,z): return (-A[x]-B[y]-C[z], x,y,z)

Q=[]
heapq.heappush(Q, evaluate(0,0,0))
for i in range(1,K+1):
    (e,x,y,z) = heapq.heappop(Q)
    print(-e)
    if x+1 < X and evaluate(x+1, y, z) not in Q:
        heapq.heappush(Q, evaluate(x+1, y, z))
    if y+1 < Y and evaluate(x, y+1, z) not in Q:
        heapq.heappush(Q, evaluate(x, y+1, z))
    if z+1 < Z and evaluate(x, y, z+1) not in Q:
        heapq.heappush(Q, evaluate(x, y, z+1))

Buggy python submission (verdict: Time Limit Exceeded):
"""
python3 main.py < input.txt
"""
import math
import itertools as it

X,Y,Z,K=map(int, input().split())
A=list(map(int, input().split()))+[0]
A.sort(reverse=True)
B=list(map(int, input().split()))+[0]
B.sort(reverse=True)
C=list(map(int, input().split()))+[0]
C.sort(reverse=True)

def abc(x): return A[x[0]]+B[x[1]]+C[x[2]]
def cand(c): 
    x,y,z=c[0],c[1],c[2]
    return [(x+1,y,z),(x,y+1,z),(x,y,z+1)]
dp={1:(0,0,0)}
dpV={(0,0,0)}
def f(k):
    if k in dp:
        return abc(dp[k])
    candidates=list(it.chain.from_iterable([cand(dp[i]) for i in range(1,k)]))
    #print(candidates)
    candidates=list(filter(lambda x: (x not in dpV) and x[0]<X and x[1]<Y and x[2]<Z, candidates))
    #print(candidates)
    dp[k]=max(candidates,key=abc)
    dpV.add(dp[k])
    return abc(dp[k])
    
for i in range(1,K+1):
    print(f(i))

Fixed submission:
"""
python3 main.py < input.txt
"""
import math
import itertools as it
import heapq

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

def evaluate(x,y,z): return (-A[x]-B[y]-C[z], x,y,z)

Q=[]
heapq.heappush(Q, evaluate(0,0,0))
for i in range(1,K+1):
    (e,x,y,z) = heapq.heappop(Q)
    print(-e)
    if x+1 < X and evaluate(x+1, y, z) not in Q:
        heapq.heappush(Q, evaluate(x+1, y, z))
    if y+1 < Y and evaluate(x, y+1, z) not in Q:
        heapq.heappush(Q, evaluate(x, y+1, z))
    if z+1 < Z and evaluate(x, y, z+1) not in Q:
        heapq.heappush(Q, evaluate(x, y, z+1))